Can't we get total number of matches in _search api?

can't we get total number of matches in _search api?

i'm using following search api to get total matched document and to find number of match for the given query.
in this we don't receive the actual total match for the given query rather then results saying total value 10000 and relation : gte.

i'm not sure how to get the total number of match that i used to receive older versions of elasticsearch ex:5.6.3 v.

https://host:9202/index/_search

Response from 7.11.2
"hits": {
"total": {
"value": 10000,
"relation": "gte"
}

Response from 5.6.3

"hits": {
    "total": 1366000,
    "max_score": 1.0,
    .....
  }

Take a look at Search your data | Elasticsearch Guide [7.12] | Elastic

Why do you need the total number of hits?

@warkolm , Thanks for sharing the document.

total # of hits is required to show for the user saying this many records matched for ur search, and out of this we are showing n docs.

There are some optimisations so the response will be faster if you don't track the total number of hits after 10000 hits.

One good practice IMO is to say to the user:

  • When you have hits below 10000:

Your query is matching 5678 documents. Here are the 10 first documents.

  • When you have more than 10000 hits:

Your query is matching more than 10.000 documents. Here are the 10 first documents.

My 2 cents.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.