From bdd7078ac7800b5e2c15cc1bc86bcfee7b76ae00 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Mon, 28 Jan 2019 09:57:11 +0100 Subject: [PATCH 1/3] Handle total hits equal to track_total_hits This change ensures that a total hits equal to the value set for track_total_hits is not considered as a lower bound. Closes #37897 --- .../test/search/220_total_hits_object.yml | 14 +++++++++++++- .../action/search/SearchPhaseController.java | 2 +- 2 files changed, 14 insertions(+), 2 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 a9c37c00b929a..520bb3e0498cd 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 @@ -113,7 +113,7 @@ setup: - do: search: - size: 3 + size: 0 track_total_hits: 4 body: query: @@ -123,6 +123,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 67f33398bba68..9fce755c93ba3 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java @@ -758,7 +758,7 @@ TotalHits getTotalHits() { assert totalHitsRelation == Relation.EQUAL_TO; return new TotalHits(totalHits, totalHitsRelation); } else { - if (totalHits < trackTotalHitsUpTo) { + if (totalHits <= trackTotalHitsUpTo) { return new TotalHits(totalHits, totalHitsRelation); } else { /* From 5a77a7d35e32cc83fa65f35cbd56a0a9ba698f9c Mon Sep 17 00:00:00 2001 From: jimczi Date: Mon, 4 Mar 2019 15:07:16 +0100 Subject: [PATCH 2/3] adapt skip version for rest test before backport --- .../rest-api-spec/test/search/220_total_hits_object.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 07a7dbfe152ae..0aad77c02cb1f 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: From 349fdfd77b5c9be5fcccf9f9d1dbbf6aeadcfb04 Mon Sep 17 00:00:00 2001 From: jimczi Date: Mon, 4 Mar 2019 16:10:56 +0100 Subject: [PATCH 3/3] adapt skip version for rest test before backport --- .../rest-api-spec/test/search/220_total_hits_object.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0aad77c02cb1f..965d18844e3cc 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: " - 7.0.99" + version: " - 7.99.99" reason: hits.total is rendered as an object in 7.0.0 - do: