From 160dc29f0e99f7ae458d0df8e9c2542da22bf3d4 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Tue, 5 Mar 2019 12:03:39 +0100 Subject: [PATCH] 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. --- .../test/search/220_total_hits_object.yml | 16 ++++++++++++++-- .../action/search/SearchPhaseController.java | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/220_total_hits_object.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/220_total_hits_object.yml index 8823fc8922b..0aad77c02cb 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/220_total_hits_object.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/220_total_hits_object.yml @@ -56,7 +56,7 @@ setup: --- "hits.total as an object": - skip: - version: " - 6.99.99" + version: " - 7.0.99" reason: hits.total is rendered as an object in 7.0.0 - do: @@ -106,7 +106,7 @@ setup: - do: search: - size: 3 + size: 0 track_total_hits: 4 body: query: @@ -116,6 +116,18 @@ setup: - match: {hits.total.value: 4} - match: {hits.total.relation: gte} + - do: + search: + size: 0 + track_total_hits: 5 + body: + query: + match: + foo: bar + + - match: {hits.total.value: 5} + - match: {hits.total.relation: eq} + - do: catch: /\[rest_total_hits_as_int\] cannot be used if the tracking of total hits is not accurate, got 100/ search: diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java b/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java index d370f60d98c..084cdaca2cc 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java @@ -754,7 +754,7 @@ public final class SearchPhaseController { assert totalHitsRelation == Relation.EQUAL_TO; return new TotalHits(totalHits, totalHitsRelation); } else { - if (totalHits < trackTotalHitsUpTo) { + if (totalHits <= trackTotalHitsUpTo) { return new TotalHits(totalHits, totalHitsRelation); } else { /*