Metric Aggregation
산술 aggregation
{
"size" : 0,
"aggs" : {
"stats_score" : {
"stats" : {
"field" : "points"
}
}
}
}
curl -XGET -H'Content-Type: application/json' localhost:9200/_search?pretty --data-binary @avg_points_aggs.json
- AVG(평균)
- MAX (최대값)
- status : count/ min / max / avg / sum => aggregation이 다 나올 수 있는 코드
Bucket aggregation
SQL Group by와 같음
{
"size" : 0,
"aggs" : {
"team_stats" : {
"terms" : {
"field" : "team"
},
"aggs" : {
"stats_score" : {
"stats" : {
"field" : "points"
}
}
}
}
}
}
- 일단 index 생성 후 mapping
curl -XPUT 'http://localhost:9200/basket/record/_mapping?include_type_name=true' -H "Content-Type: application/json" -d @basketball_mapping.json
- document @file로 post하기
curl -XPOST 'localhost:9200/\_bulk' -H 'Content-Type: application/json' --data-binary @twoteam\_basketball.json
- bucket aggregation search
curl -XGET -H "Content-Type: application/json" localhost:9200/basket/\_search?pretty --data-binary
@terms\_aggs.json
team별로 document를 묶은 다음 결과값에서 또 aggregation을 진행함
index 조회
curl -XGET 'localhost:9200/\_cat/indices?v'
index 삭제
curl --location --request DELETE 'localhost:9200/basketbal'
반응형