-
-
Save doytsujin/70e8d94e3e2c3938c81a1efe74a8c4c9 to your computer and use it in GitHub Desktop.
Elasticsearch aggregations demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XDELETE 'localhost:9200/test' | |
curl -XPUT 'localhost:9200/test' -d ' | |
{ | |
"mappings" : { | |
"_default_": { | |
"properties" : { | |
"name" : { "type" : "string" }, | |
"age" : { "type" : "integer" }, | |
"country" : { "type" : "string" }, | |
"gender" : { "type" : "string" } | |
} | |
} | |
} | |
} | |
' | |
curl -XPUT 'localhost:9200/test/data/1' -d ' | |
{ | |
"name" : "abc", | |
"age" : 22, | |
"country" : "usa", | |
"gender" : "male" | |
} | |
' | |
curl -XPUT 'localhost:9200/test/data/2' -d ' | |
{ | |
"name" : "xyz", | |
"age" : 27, | |
"country" : "usa", | |
"gender" : "male" | |
} | |
' | |
curl -XPUT 'localhost:9200/test/data/3' -d ' | |
{ | |
"name" : "xyz", | |
"age" : 22, | |
"country" : "india", | |
"gender" : "female" | |
} | |
' | |
curl -XPUT 'localhost:9200/test/data/4' -d ' | |
{ | |
"name" : "abc", | |
"age" : 22, | |
"country" : "usa", | |
"gender" : "female" | |
} | |
' | |
curl -XGET 'localhost:9200/test/_refresh' | |
curl -XGET 'localhost:9200/test/data/_search?pretty' -d ' | |
{ | |
"aggs" : { | |
"age": { | |
"terms": { | |
"field": "age" | |
}, | |
"aggs" : { | |
"country" : { | |
"terms" : { | |
"field" : "country" | |
} | |
} | |
} | |
} | |
} | |
}' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"ok":true,"acknowledged":true}{"ok":true,"acknowledged":true}{"ok":true,"_index":"test","_type":"data","_id":"1","_version":1}{"ok":true,"_index":"test","_type":"data","_id":"2","_version":1}{"ok":true,"_index":"test","_type":"data","_id":"3","_version":1}{"ok":true,"_index":"test","_type":"data","_id":"4","_version":1}{"ok":true,"_shards":{"total":10,"successful":5,"failed":0}}{ | |
"took" : 5, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 4, | |
"max_score" : 1.0, | |
"hits" : [ { | |
"_index" : "test", | |
"_type" : "data", | |
"_id" : "3", | |
"_score" : 1.0, "_source" : | |
{ | |
"name" : "xyz", | |
"age" : 22, | |
"country" : "india", | |
"gender" : "female" | |
} | |
}, { | |
"_index" : "test", | |
"_type" : "data", | |
"_id" : "2", | |
"_score" : 1.0, "_source" : | |
{ | |
"name" : "xyz", | |
"age" : 27, | |
"country" : "usa", | |
"gender" : "male" | |
} | |
}, { | |
"_index" : "test", | |
"_type" : "data", | |
"_id" : "1", | |
"_score" : 1.0, "_source" : | |
{ | |
"name" : "abc", | |
"age" : 22, | |
"country" : "usa", | |
"gender" : "male" | |
} | |
}, { | |
"_index" : "test", | |
"_type" : "data", | |
"_id" : "4", | |
"_score" : 1.0, "_source" : | |
{ | |
"name" : "abc", | |
"age" : 22, | |
"country" : "usa", | |
"gender" : "female" | |
} | |
} ] | |
}, | |
"aggregations" : { | |
"age" : { | |
"buckets" : [ { | |
"key" : 22, | |
"doc_count" : 3, | |
"country" : { | |
"buckets" : [ { | |
"key" : "usa", | |
"doc_count" : 2 | |
}, { | |
"key" : "india", | |
"doc_count" : 1 | |
} ] | |
} | |
}, { | |
"key" : 27, | |
"doc_count" : 1, | |
"country" : { | |
"buckets" : [ { | |
"key" : "usa", | |
"doc_count" : 1 | |
} ] | |
} | |
} ] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment