If one wants to count the number of documents in an index (of Elasticsearch) then there are (at least?) two possibilities:
Direct
count
POST my_index/_count
should return the number of documents in
my_index
.Using
search
Here one can use the
count
as thesearch_type
or some other type. In either of the cases the total count can be extracted from the field['hits']['total']
My questions are:
what is the difference between the different approaches? Which one should I prefer?
I raise this question because I'm experiencing different results depending on the chosen method. I'm now in the process of debugging the issue, and this question popped up.
{"count":27053653,"_shards":{"total":3,"successful":3,"skipped":0,"failed":0}}
– Balance