Executing facets
ElasticSearch provides several functionalities other than search; it allows executing statistics and real-time analytics on searches via the facets.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script available in the online code.
How to do it...
For executing a facet, we will perform the steps given as follows:
From command line:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true&size=0' -d '{ "query": { "match_all": {} }, "facets": { "tag": { "terms": { "field": "tag", "size": 10 } } } }'
In this case we have used a
match_all
query plus a term facets used to count terms.The result returned by ElasticSearch, if everything is all right, should be:
{ "took" : 2, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 3, "max_score" : 1.0, "hits" : [ ] }, "facets" : { "tag" :...