Elastic Search - Bucket Aggregation
Aggregation은 Elastic Search에서
갖고있는 Document들 중에서 어떠한 값을 조합해서 나타내는 것
Bucket Aggregation
은 Group by와 같다고 보면된다.
xxxxxxxxxx
curl -XGET localhost:9200/record/_mapping?pretty --data-binary @basketball_mapping.json -H "Content-Type:application/json"
basketball_mapping.json
xxxxxxxxxx
{
"record" : {
"properties" : {
"team" : {
"type" : "string",
"fielddata" : true
},
"name" : {
"type" : "string",
"fielddata" : true
},
"points" : {
"type" : "long"
},
"rebounds" : {
"type" : "long"
},
"assists" : {
"type" : "long"
},
"blocks" : {
"type" : "long"
},
"submit_date" : {
"type" : "date",
"format" : "yyyy-MM-dd"
}
}
}
}
xcurl -XPOST localhost:9200/_bulk?pretty -H "Content-Type:application/json" --data-binary @twoteam_basketball.json
twoteam_basketball.json
xxxxxxxxxx
{ "index" : { "_index" : "basketball", "_type" : "record", "_id" : "1" } }
{"team" : "Chicago","name" : "Michael Jordan", "points" : 30,"rebounds" : 3,"assists" : 4, "blocks" : 3, "submit_date" : "1996-10-11"}
{ "index" : { "_index" : "basketball", "_type" : "record", "_id" : "2" } }
{"team" : "Chicago","name" : "Michael Jordan","points" : 20,"rebounds" : 5,"assists" : 8, "blocks" : 4, "submit_date" : "1996-10-13"}
{ "index" : { "_index" : "basketball", "_type" : "record", "_id" : "3" } }
{"team" : "LA","name" : "Kobe Bryant","points" : 30,"rebounds" : 2,"assists" : 8, "blocks" : 5, "submit_date" : "2014-10-13"}
{ "index" : { "_index" : "basketball", "_type" : "record", "_id" : "4" } }
{"team" : "LA","name" : "Kobe Bryant","points" : 40,"rebounds" : 4,"assists" : 8, "blocks" : 6, "submit_date" : "2014-11-13"}
xxxxxxxxxx
curl -XGET localhost:9200/_search?pretty --data-binary @terms_aggs.json -H "Content-Type:application/json"
terms_aggs.json
xxxxxxxxxx
{
"size" : 0,
"aggs" : {
"players" : {
"terms" : {
"field" : "team"
}
}
}
}
Mapping할때 team값의 fielddata
를 true로 해야 오류가 생기지 않는다.
엘라스틱서치는 여기서 마무리.
다음은 시각화 도구인 Kibana 에 대해 포스팅한다
'Back-end' 카테고리의 다른 글
logstash - Windows환경에서 (0) | 2018.09.07 |
---|---|
Kibana - Visualization (0) | 2018.09.05 |
Elastic Search -Metric Aggregation (0) | 2018.08.31 |
ElasticSearch Search 데이터 조회하기 (0) | 2018.08.30 |
ElasticSearch Mapping (0) | 2018.08.30 |
댓글