Skip to content

Commit 160dc29

Browse files
committed
Handle total hits equal to track_total_hits (#37907)
This change ensures that a total hits equal to the value set for track_total_hits is not considered as a lower bound.
1 parent e94d32d commit 160dc29

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

rest-api-spec/src/main/resources/rest-api-spec/test/search/220_total_hits_object.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ setup:
5656
---
5757
"hits.total as an object":
5858
- skip:
59-
version: " - 6.99.99"
59+
version: " - 7.0.99"
6060
reason: hits.total is rendered as an object in 7.0.0
6161

6262
- do:
@@ -106,7 +106,7 @@ setup:
106106

107107
- do:
108108
search:
109-
size: 3
109+
size: 0
110110
track_total_hits: 4
111111
body:
112112
query:
@@ -116,6 +116,18 @@ setup:
116116
- match: {hits.total.value: 4}
117117
- match: {hits.total.relation: gte}
118118

119+
- do:
120+
search:
121+
size: 0
122+
track_total_hits: 5
123+
body:
124+
query:
125+
match:
126+
foo: bar
127+
128+
- match: {hits.total.value: 5}
129+
- match: {hits.total.relation: eq}
130+
119131
- do:
120132
catch: /\[rest_total_hits_as_int\] cannot be used if the tracking of total hits is not accurate, got 100/
121133
search:

server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ TotalHits getTotalHits() {
754754
assert totalHitsRelation == Relation.EQUAL_TO;
755755
return new TotalHits(totalHits, totalHitsRelation);
756756
} else {
757-
if (totalHits < trackTotalHitsUpTo) {
757+
if (totalHits <= trackTotalHitsUpTo) {
758758
return new TotalHits(totalHits, totalHitsRelation);
759759
} else {
760760
/*

0 commit comments

Comments
 (0)