Skip to content

Instantly share code, notes, and snippets.

@radu-gheorghe
Created November 15, 2012 07:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save radu-gheorghe/4077281 to your computer and use it in GitHub Desktop.
Elasticsearch terms facet
curl -XDELETE localhost:9200/test
#{"ok":true,"acknowledged":true}
curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"red", "counter": 3}'
#{"ok":true,"_index":"test","_type":"test","_id":"MLv-xERyTFaIdkQeaxoiaw","_version":1}
curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"red", "counter": 7}'
#{"ok":true,"_index":"test","_type":"test","_id":"JaMQIZpbQaKrgdTOtaEEcg","_version":1}
curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"blue", "counter": 5}'
#{"ok":true,"_index":"test","_type":"test","_id":"8TSz-nH3RQ2N3GqJh5xlXA","_version":1}
curl -XPOST localhost:9200/test/_refresh
curl -XPOST localhost:9200/test/test/_search?pretty=true -d '{
"query": {
"match_all": {}
},
"facets" : {
"test_facet" : {
"terms_stats" : {
"key_field" : "tag",
"value_field" : "counter"
}
}
}
}'
#{
# "took" : 109,
# "timed_out" : false,
# "_shards" : {
# "total" : 1,
# "successful" : 1,
# "failed" : 0
# },
# "hits" : {
# "total" : 3,
# "max_score" : 1.0,
# "hits" : [ {
# "_index" : "test",
# "_type" : "test",
# "_id" : "MLv-xERyTFaIdkQeaxoiaw",
# "_score" : 1.0, "_source" : {"timestamp": "random_date", "tag":"red", "counter": 3}
# }, {
# "_index" : "test",
# "_type" : "test",
# "_id" : "JaMQIZpbQaKrgdTOtaEEcg",
# "_score" : 1.0, "_source" : {"timestamp": "random_date", "tag":"red", "counter": 7}
# }, {
# "_index" : "test",
# "_type" : "test",
# "_id" : "8TSz-nH3RQ2N3GqJh5xlXA",
# "_score" : 1.0, "_source" : {"timestamp": "random_date", "tag":"blue", "counter": 5}
# } ]
# },
# "facets" : {
# "test_facet" : {
# "_type" : "terms_stats",
# "missing" : 0,
# "terms" : [ {
# "term" : "red",
# "count" : 2,
# "total_count" : 2,
# "min" : 3.0,
# "max" : 7.0,
# "total" : 10.0,
# "mean" : 5.0
# }, {
# "term" : "blue",
# "count" : 1,
# "total_count" : 1,
# "min" : 5.0,
# "max" : 5.0,
# "total" : 5.0,
# "mean" : 5.0
# } ]
# }
# }
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment