
ElasticSearch Cookbook
By :

It is often required to return only the count of the matched results and not the results themselves.
There are a lot of scenarios involving counting, some of them are as follows:
To return a number (for example, how many posts for a blog, how many comments for a post)
Validating if some items are available: are there posts? are there comments?
You need a working ElasticSearch cluster and an index populated with the script available in online code.
For executing a counting query, we need to perform the following steps:
From command line, we will execute the following count
query:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_count' -d '{"match_all":{}}'
The result returned by ElasticSearch, if everything is all right, should be as follows:
{ "count" : 3, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 } }
The result is composed by the count result (a long type) and the shards status at the time of the query.
Change the font size
Change margin width
Change background colour