Counting number of documents using Elasticsearch

后端 未结 5 1658
一生所求
一生所求 2021-01-31 07:13

If one wants to count the number of documents in an index (of Elasticsearch) then there are (at least?) two possibilities:

  • Direct count

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 08:00

    Old question, chipping in because on ElasticSearch version > 7.0 :

    1. _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":[...]}}

    2. _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.

提交回复
热议问题