티스토리 뷰
인덱스 템플릿
- 인덱스 템플릿 생성: PUT _index_template/{템플릿명}
- 적용될 인덱스 패턴 지정: index_patterns: "{인덱스명}-*"
_reindex API 에서 스크립트 사용
- painless 스크립트를 사용해서 인덱스명 지정
- ctx._index = ctx._substring(...)
_reindex API에서 ingest pipeline 사용
- remove 프로세서를 이용하여 불필요한 필드를 삭제하는 ingest pipeline 생성
- 재색인 시 생성한 ingest pipeline 적용하여 필드 삭제
https://www.elastic.co/guide/en/elasticsearch/reference/7.10/index.html
Elasticsearch Guide [7.10] | Elastic
www.elastic.co
아래를 따라하기위해서는 이전 글을 참고하셔야합니다.
2022.11.08 - [ELK 스택] - Elasticsearch - 인덱스 재색인 : 필드 매핑 개선
Elasticsearch - 인덱스 재색인 : 필드 매핑 개선
2022.11.08 - [ELK 스택] - Filebeat - Logstash - Elasticsearch 예제 Filebeat - Logstash - Elasticsearch 예제 Filebeat 설치 및 실행 filebeat.yml 에서 파일 입력 설정 파일을 다시 읽어들이기 위한 data 플래그 삭제 Filebeat =>
jhyunnn.tistory.com
# 인덱스 템플릿 생성
PUT _index_template/mylogs
{
"index_patterns": [
"mylogs*"
],
"priority": 10,
"template": {
#mappings 를 이런식으로 넣습니다.
"mappings": {
"properties": {
"@timestamp": {
},
...
}
},
"verb": {
"type": "keyword"
}
}
}
# 인덱스 템플릿 조회
GET _index_template/mylogs
# 인덱스 템플릿 삭제
DELETE _index_template/mylogs
여기서 다시 reindex 해보면 다이나믹 매핑으로 생성이되지만,
템플릿을 지정한 방식대로 생성이 되는걸 확인 할 수 있습니다.
POST _reindex
{
"source": {
"index": "apachelog-2020.08.08"
},
"dest": {
"index": "mylogs"
}
}
GET mylogs/_mapping
위 방식으로하면 하나하나 다 따로따로 해줘야하지만 이거를 여러개 가져오기 위해서는
source에서는 apachelog-*가 가능하지만 dest 에서는 * 하면 불가능합니다. 그래서 스크립트를 작성해줘야합니다.
# dest 에서 * 하면 에러가 발생합니다.
# 아래는 잘못된 예제!!
POST _reindex
{
"source": {
"index": "apachelog-*"
},
"dest": {
"index": "mylogs-*"
}
}
# 스크립트를 이용해서 하는 방법
# painless 스크립트 사용
POST _reindex
{
"source": {
"index": "apachelog-*"
},
"dest": {
"index": "mylogs-*"
},
"script": {
"lang": "painless",
"source": "ctx._index = 'mylogs-' + (ctx._index.substring('apachelog-'.length(), ctx._index.length()))"
}
}
# 인덱스에 접근할때는 ctx. 로 접근해야하고
# 이름 부분을 수정해줍니다.
# 예제
# 2020.08.08 만 가져와서 한번 넣어보겠습니다.
POST _reindex
{
"source": {
"index": "apachelog-2020.08.08"
},
"dest": {
"index": "mylogs-*"
},
"script": {
"lang": "painless",
"source": "ctx._index = 'mylogs-' + (ctx._index.substring('apachelog-'.length(), ctx._index.length()))"
}
}
GET _cat/indices//mylogs*
## clientip, ecs, input, tags 를 지우는거 해보겠습니다 필드 지우기
PUT _ingest/pipeline/mylogs_delete_fileds
{
"processors": [
{
"remove": {
"field": ["clientip", "ecs", "input", "tags"]
}
}
]
}
GET _ingest/pipeline/mylogs_delete_fileds
DELETE _ingest/pipeline/mylogs_delete_fileds
## pipeline 적용해서 생성
POST _reindex
{
"source": {
"index": "apachelog-*"
},
"dest": {
"index": "mylogs",
"pipeline": "mylogs_delete_fileds"
},
"script": {
"lang": "painless",
"source": "ctx._index = 'mylogs-' + (ctx._index.substring('apachelog-'.length(), ctx._index.length()))"
}
}
#필드들이 삭제된걸 확인이 가능합니다.
GET mylogs-*/_search
#갯수 확인 가능
GET mylogs-*/_count
#mylogs로 시작하는 인덱스 검색
GET _cat/indices/mylogs*
# mapping 확인
GET mylogs_2020.08.09/_mapping
참고
'ELK 스택' 카테고리의 다른 글
Elasticsearch - 인덱스 재색인 : 필드 매핑 개선 (0) | 2022.11.08 |
---|---|
Filebeat - Logstash - Elasticsearch 예제 (0) | 2022.11.08 |
Elasticsearch - 인덱스 매핑과 데이터 타입 날짜, 객체, 위치정보 (3) (0) | 2022.11.07 |
Elasticsearch - 인덱스 매핑과 데이터 타입 날짜, 객체, 위치정보 (2) (0) | 2022.11.07 |
Elasticsearch - 인덱스 매핑과 데이터 타입 날짜, 객체, 위치정보 (1) (0) | 2022.11.07 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- InteiilJ
- 절대 경로 설정하기
- react
- Mapping
- string
- 명령어
- NextJS 14
- literal sql
- 인덱스
- ElasticSearach 백업
- Mappings
- list
- GIT
- Elasticsearch
- config
- Linux
- index 처리를 잘하자
- React18
- Java
- 재색인
- EL
- bool
- ArrayList
- kibana
- pm2-logrotate
- Query
- 문자
- 키바나
- logstash
- mysql은 nl이 기본 세팅
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함