Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- pwnable
- 프론트엔드개발자
- 시스템해킹
- wargame
- rce
- elasticsearch
- elk stack
- exploit
- forensic
- 정보보안
- error 583066
- Index
- software
- ATT&CK
- Mitre
- #C언어 #연산자
- filesystem
- AD
- node.js
- 랜섬웨어
- Threat Intelligence
- PetitPotam
- Credential Access
- #whitespace #
- sql인젝션
- SQLMap
- 침해사고
- 백엔드개발자
- 가이드라인
- windows
Archives
- Today
- Total
Plit00's Story
[Node.js] - Elasticsearch 페이지 출력 본문
Pagination - index&tag
서칭을 통해 찾아본 결과 npm elasticsearch-Pagination이 있어 관련 모듈을 쓰면 된다했지만 없는걸 확인하고
하나씩 구현함
elasticsearch match_all로 검색을 한다면 10개 밖에 안보여주기 때문에 페이지네이션을 통해 출력
단, 출력하려는 index_name의 ids와 tag_index의 ids가 동일하게 매칭되어야 정상적으로 출력됨
client.search에서 index: ['index_name' , 'tag_index']로 검색되도 정상적으로 출력됨을 확인했지만
원하는 바로 출력하려 했을때의 방법은 찾지 못해 하나씩 불러오는 과정으로 만듬
또한, 10개밖에 안보여주는것을 size를 임의로 지정하여 전체적으로 설정할 수 있지만
원하는 데이터들이 일정 값을 넘으면 속도가 현저히 느려지기 때문에 객체변환 방식으로 페이지네이션을 구현함
index.js
router.get('/', (req, res) =>{
const page = parseInt(req, params.page) || 1;
const from = (page - 1) * perPage;
client.search({
index:'index_name',
body:{
from: from,
size: perPage,
query:{
match_all: {}
}
}
}).then(indexResults => {
const name = indexResults.hits.hits.map(hit => hit._source);
client.search({
index: 'tag_index',
body: {
from: from,
size: perPage,
query: {
match_all: {}
}
}
}).then(tagResults => {
const tag_index = tagResults.hits.hits.map(hit => hit._source);
const total = indexResults.hits.total;
const pages = Math.ceil(total / perPage);
var indexData = tag_index.map(tag, i) => {
tag.tag1 = tag_index[i].tag1;
tag.tag2 = tag_index[i].tag2;
tag.tag3 = tag_index[i].tag3;
return tag;
});
res.render('index', {indexData: idexData, page: page, pages: pages});
})
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
원하는 레퍼런스를 통해서 임의로 query를 보낼 수 있음
'Security > Elasticsearch' 카테고리의 다른 글
ELK Stack install Ubuntu 18.04(설치) (0) | 2023.04.11 |
---|---|
[Node.js] - error Unexpected token in JSON at position 583066 (0) | 2023.01.25 |
[Node.js] - Elasticsearch query (0) | 2022.12.18 |
ELK Stack - DC Server Packetbeat 연동 (0) | 2022.04.15 |
ELK Stack - Winlogbeat, Sysmon연동 (0) | 2022.04.15 |
Comments