Counting number of documents using Elasticsearch

后端 未结 5 1665
一生所求
一生所求 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

    Probably _count is a bit faster since it doesn't have to execute a full query with ranking and result fetching and can simply return the size.

    It would be interesting to know a bit more about how you manage to get different results though. For that I need more information like what exact queries you are sending and if any indexing is going on on the index.

    But suppose that you do the following

    1. index some documents
    2. refresh the index

    _search and _count (with a match all query) should return the same total. If not, that'd be very weird.

提交回复
热议问题