Created
March 28, 2014 21:26
-
-
Save bly2k/9843335 to your computer and use it in GitHub Desktop.
Elasticsearch value_count and cardinality
This file contains 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/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