Count different values โ€‹โ€‹using elasticsearch

I am studying elastic search and would like to count different values. While I can count values, but not different.

Here is an example of data:

curl http://localhost:9200/store/item/ -XPOST -d '{ "RestaurantId": 2, "RestaurantName": "Restaurant Brian", "DateTime": "2013-08-16T15:13:47.4833748+01:00" }' curl http://localhost:9200/store/item/ -XPOST -d '{ "RestaurantId": 1, "RestaurantName": "Restaurant Cecil", "DateTime": "2013-08-16T15:13:47.4833748+01:00" }' curl http://localhost:9200/store/item/ -XPOST -d '{ "RestaurantId": 1, "RestaurantName": "Restaurant Cecil", "DateTime": "2013-08-16T15:13:47.4833748+01:00" }' 

And what I have tried so far:

 curl -XPOST "http://localhost:9200/store/item/_search" -d '{ "size": 0, "aggs": { "item": { "terms": { "field": "RestaurantName" } } } }' 

Output:

 { "took": 0, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 3, "max_score": 0.0, "hits": [] }, "aggregations": { "item": { "buckets": [ { "key": "restaurant", "doc_count": 3 }, { "key": "cecil", "doc_count": 2 }, { "key": "brian", "doc_count": 1 } ] } } } 

How can I get the cecil counter as 1 instead of 2

+11
aggregation elasticsearch facet
source share
3 answers

You should use the cardinality parameter mentioned by @coder, which you can find in the document.

 $ curl -XGET "http://localhost:9200/store/item/_search" -d' { "aggs" : { "restaurant_count" : { "cardinality" : { "field" : "RestaurantName", "precision_threshold": 100, "rehash": false } } } }' 

It worked for me ...

+5
source share

There is no support for a separate count in ElasticSearch, although there is no deterministic count. As a result, use aggregation of terms and counters. See a graph other than an elastic search question.

0
source share

All Articles