[es8] aggregation - Pipeline Aggregations
Elasticsearch aggregation 을 테스트 해보려고 한다. 그중에서도 Pipeline Aggregations
우선 내 신상 ES 로 이동
/Users/doo/docker/es8.8.1
실행해보자
(base) ➜ es8.8.1 docker compose up -d --build
우선 키바나를 접속해보자
http://localhost:5601/app/home#/
오케이
인덱스는 언제더라.. 어젠가 그젠가 만들어 놓은 인덱스
820만건의 location 정보
mapping 구조
{
"location-index": {
"mappings": {
"dynamic": "true",
"properties": {
"addr1": {
"type": "keyword"
},
"city": {
"type": "keyword"
},
"country": {
"type": "keyword"
},
"country_code": {
"type": "keyword"
},
"location": {
"type": "geo_point"
},
"no": {
"type": "keyword"
},
"private_ip": {
"type": "ip"
},
"public_ip": {
"type": "ip"
},
"timestamp": {
"type": "date"
}
}
}
}
}
얼레 timestamp 가 비어있네
ingest pipeline 을 만들어서 timestamp 를 찍어보잣
https://ldh-6019.tistory.com/403
[es8] Elasticsearch Timestamp Pipeline
IP 와 location 정보를 색인하는데 .. 의미는 없지만 timestamp 를 찍어 보고 싶었다. _timestamp Elasticsearch 초기 _timestamp에는 인덱스에 매핑 필드를 사용할 수 있었습니다. 이 기능은 버전 2.0부터 더 이상
ldh-6019.tistory.com
PUT /_ingest/pipeline/timestamp
{
"description": "Creates a timestamp when a document is initially indexed",
"processors": [
{
"set": {
"field": "_source.timestamp",
"value": "{{_ingest.timestamp}}"
}
}
]
}
bulk class 에 timestamp pipeline 추가
색인 실행
조았으.. timestamp
다시 aggregation 해보자 sum 을 해줄 number type 의 필드가 없어 다시 색인 ㅠㅠ
num 필드에 10000까지의 랜덤 스코어 색인
날짜별로 더 했더니
GET location-index/_search
{
"size": 0,
"aggs": {
"doo_date_histo": {
"date_histogram": {
"field": "timestamp",
"calendar_interval": "day"
},
"aggs": {
"doo_sum": {
"sum": { "field": "num" }
},
"the_deriv": {
"derivative": { "buckets_path": "doo_sum" }
}
}
}
}
}
결과