If one wants to count the number of documents in an index (of Elasticsearch) then there are (at least?) two possibilities:
Direct count
Old question, chipping in because on ElasticSearch version > 7.0 :
_search
: returns the documents with the hit count for the search query, less than or equal to the result window size, which is typically 10,000. e.g.:
{"took":3,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":10000,"relation":"gte"},"max_score": 0.34027478,"hits":[...]}}
_count
: returns the total number of hits for the search query irrespective of the result window size. no documents returned, e.g.:
{"count":5703899,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0}}
So, _search
might return the total hits as 10,000 if that is your configured result window size, while _count
would return the actual count for the same query.