테스트 데이터 날짜 변경 ingest pipeline
ELK2022. 8. 4. 01:07
728x90
간혹 날짜별 데이터 테스트시 당일 데이터가 없을 경우 귀찮을 때가 있다.
그럴때 쓰면 좋은 Pipline 다무시하고 하단 스크립트 부분 참조 하면된다.
레퍼넌스
https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html
PUT _ingest/pipeline/calculate_iu
{
"description": "Add an ingest timestamp and calculate ingest lag",
"processors": [
{
"set": {
"field": "_source.ingest_time",
"value": "{{_ingest.timestamp}}"
}
},
{
"set": {
"field": "_source.ingest_t2ime2",
"value": "{{_ingest.timestamp}}"
}
},
{
"script": {
"lang": "painless",
"source": """SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date currentTime = new Date();String mTime = mSimpleDateFormat.format(currentTime);if(ctx.containsKey("ingest_time") ) {DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern('yyyy-MM-dd HH:mm:ss');LocalDateTime ldt = LocalDateTime.parse(mTime, dateFormat);
ctx['날짜를 바꿀 필드'] = ldt.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
"""
}
}
]
}
아래와 같이 위에 만든 파이프라인을 추가 하여 기존 데이터를 가라 인덱스에 리인덱스 후 다시 원본에 인덱싱 하면 날짜가 업데이트 된다.
POST _reindex
{
"source": {
"index": "*"
},
"dest": {
"index": "*",
"pipeline": "calculate_iu"
}
}
POST _reindex
{
"source": {
"index": "*"
},
"dest": {
"index": "*"
}
}
테스트의 경우 아래와 같이 해볼수 있다.
POST _ingest/pipeline/calculate_iu/_simulate
{
"docs": [
{
"_source": {
"타깃필드": "2022-05-10 04:13:12"
}
}
]
}
기존 데이터 업데이트가 아닌 신규 데이터에 날짜를 바꿀때는 해당과 같이 하면 된다.
POST index/_doc?pipeline=calculate_iu
{
"필드": "2099-05-07 11:04:05.11"
}
'ELK' 카테고리의 다른 글
ELK docker 기반 개발 환경 구축 (0) | 2022.09.15 |
---|---|
Elasticsearch node 영구 제거시 명령어 (0) | 2022.08.21 |
logstash 이용 ELK 데이터 json으로 받는 방법 (0) | 2022.08.01 |
사용중인 노드 제거 방법 (0) | 2022.07.28 |
노드롤 설정 (0) | 2022.07.20 |
댓글()