I have an index that looks like this:
{ "id":1, "countries":["china","japan","united states"] }, { "id":2, "countries":["china","united states"] }
I want an output like this:
{ china: 2 }{ united states: 2} { japan: 1}
Is there a query or aggregation that does this?
I found it. I need the terms aggregator.
curl -XPOST 'localhost:9200/someindex/_search?size=0&pretty' -H 'Content-Type: application/json' -d' { "aggs" : { "countries" : { "terms" : { "field" : "countries" } } } } '
© 2020. All Rights Reserved - Elasticsearch
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant logo are trademarks of the Apache Software Foundation in the United States and/or other countries.