-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reported hits count are inconsistent between _search and _search/template #52801
Comments
Pinging @elastic/es-search (:Search/Search) |
From the source code I found that when elasticsearch/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java Line 303 in 1e0ba70
|
It's lost because the templated search parses the |
Thanks @gaobinlong and @jimczi for looking into this. |
Yes sorry, the expectation when setting |
Thank @jimczi so when specifying |
@jimczi OK, I'm glad to do that. @consulthys, only D is incorrect, when |
When 'rest_track_total_hits_as_int' is set to true, the total hits count in the response should be accurate. So we should set trackTotalHits to true if need when parsing the inline script of a search template request. Closes #52801
Elasticsearch version (
bin/elasticsearch --version
): 7.5.0Plugins installed: []
JVM version (
java -version
): Elastic CloudOS version (
uname -a
if on a Unix-like system): Elastic CloudDescription of the problem including expected versus actual behavior:
Since ES 7, one must use
rest_total_hits_as_int=true
in order to revert to the old behavior of getting an exact number of total hits in the search response. I feel there is a discrepancy in how thesearch
and_search/template
endpoints behave regarding the reported number of hits.In my tests below, I'm querying an index with more than 10000 documents with the exact same JSON query (as a normal query and as a template query depending on which endpoint I'm targeting).
A. When using the
_search
endpoint, I get this:B. When using the
_search?rest_total_hits_as_int=true
endpoint, I get this:C. When using the
_search/template
endpoint, I get this:So far, so good, everything is consistent.
D. But when I hit the
_search/template?rest_total_hits_as_int=true
endpoint, I get this:The only way I found to get the exact total with the
_search/template
endpoint is by adding the"track_total_hits": true
parameter to the template query.E. When doing so, I get this when hitting the
_search/template
endpointF. and this when when hitting the
_search/template?rest_total_hits_as_int=true
endpointThere are two take-aways here:
"track_total_hits": true
in the query in order to spit out the exact number of hits (like in cases E and F)Steps to reproduce:
It's easy to reproduce this on any index that has more than 10K documents and creating a simple
match_all
template query.The text was updated successfully, but these errors were encountered: