Skip to content

Instantly share code, notes, and snippets.

@bly2k
Created March 28, 2014 21:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bly2k/9843335 to your computer and use it in GitHub Desktop.
Save bly2k/9843335 to your computer and use it in GitHub Desktop.
Elasticsearch value_count and cardinality
curl -XDELETE localhost:9200/test
curl -XPUT localhost:9200/test/doc/1 -d '{ "a": "1" }'
curl -XPUT localhost:9200/test/doc/2 -d '{ "a": "1" }'
curl -XPUT localhost:9200/test/doc/3 -d '{ "a": "1" }'
curl -XPOST "localhost:9200/test/_search?search_type=count&pretty" -d '{
"aggs": {
"value_count": {
"value_count": {
"field": "a"
}
},
"cardinality": {
"cardinality": {
"field": "a"
}
}
}
}'
Returns:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"value_count" : {
"value" : 3
},
"cardinality" : {
"value" : 1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment