Commit 663d82c
authored
Shortcut total hit count when terminate_after is used (elastic#94889)
We have for long considered terminate_after a "filtered collector",
same as min_score and post_filter, for which we disable the
hit count optimization as we want to make sure that the total hit count
reflects the documents that are in fact going to be collected.
When we moved to leveraging Weight#count from Lucene (elastic#88396), we automatically
moved to shortcutting the total hit count when using terminate_after and
size is set to 0, meaning that in this scenario the total hits may be
higher than the terminate after value that is set to the request, in case the
total hit count is retrieved from the index statistics through Weight#count.
This is acceptable, given that terminate_after is intended to stop
additional work after collecting a certain number of docs, but no
additional work is performed to collect a higher and accurante total hit
count in this case, given it could be retrieved from the index
statistics. This also raises that `EarlyTerminatingCollector` isn't
necessarily to be considered as a collector that filters documents out.
The current situation is inconsistent as we will shortcut the total hit
count when size is 0 and terminate after is set, but we won't if size is
greater than 0.
This commit treats terminate_after the same way regardless of how size
is set: the total hit count may be higher than the terminate after if it
did not require actual counting to be computed.1 parent f50725e commit 663d82c
File tree
3 files changed
+11
-7
lines changed- docs/changelog
- server/src
- main/java/org/elasticsearch/search/query
- test/java/org/elasticsearch/search/query
3 files changed
+11
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | 135 | | |
138 | 136 | | |
139 | 137 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| 413 | + | |
413 | 414 | | |
414 | 415 | | |
415 | 416 | | |
416 | 417 | | |
417 | | - | |
| 418 | + | |
418 | 419 | | |
419 | 420 | | |
420 | 421 | | |
421 | 422 | | |
422 | 423 | | |
423 | 424 | | |
424 | | - | |
| 425 | + | |
425 | 426 | | |
426 | 427 | | |
427 | 428 | | |
| |||
430 | 431 | | |
431 | 432 | | |
432 | 433 | | |
433 | | - | |
| 434 | + | |
434 | 435 | | |
435 | 436 | | |
436 | 437 | | |
| |||
440 | 441 | | |
441 | 442 | | |
442 | 443 | | |
443 | | - | |
| 444 | + | |
444 | 445 | | |
445 | 446 | | |
446 | 447 | | |
| |||
501 | 502 | | |
502 | 503 | | |
503 | 504 | | |
504 | | - | |
| 505 | + | |
505 | 506 | | |
506 | 507 | | |
507 | 508 | | |
| |||
0 commit comments