Counting number of documents using Elasticsearch

后端 未结 5 1666
一生所求
一生所求 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 07:48

    The two queries provide the same result but: - count consumes less resources/bandwidth because doesn't require to fetch documents, scoring and other internal optimizations. Set the search size to 0, could be very similar.

    If you want count all the record in an index, you can also execute an aggregation terms on "_type" field.

    The results should be the same. Before comparing the results, be sure to execute an index refresh.

提交回复
热议问题