Reputation: 3605
My API request looks like this...
GET /my_index/_search?scroll=1m
Along with getting the search results, I'm also looking to get the count of the total results at one go. However, while targeting hits>total>value
, the number of records never show a count more than 10000. Due to this, I have to fire count API separately. Is there any way where I can get more than 10000 records in my same _search
query?
Upvotes: 13
Views: 13527
Reputation: 1996
Simply add "track_total_hits": true
to your request.
(see Elasticsearch Reference: Track total hits)
Upvotes: 28
Reputation: 470
Try to set track_total_hits
search option to true
.
Generally the total hit count can’t be computed accurately without visiting all matches, which is costly for queries that match lots of documents. The
track_total_hits parameter
allows you to control how the total number of hits should be tracked. Given that it is often enough to have a lower bound of the number of hits, such as "there are at least 10000 hits", the default is set to 10,000. This means that requests will count the total hit accurately up to 10,000 hits. It’s is a good trade off to speed up searches if you don’t need the accurate number of hits after a certain threshold.When set to true the search response will always track the number of hits that match the query accurately
There is a great article from the official documentation describing what it is.
Or, if you only need total count, just use Count API:
Upvotes: 6