diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/TransportNoopSearchAction.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/TransportNoopSearchAction.java index d22d0b5fca7..745f247ad1b 100644 --- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/TransportNoopSearchAction.java +++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/TransportNoopSearchAction.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.plugin.noop.action.search; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; @@ -47,10 +48,10 @@ public class TransportNoopSearchAction extends HandledTransportAction listener) { listener.onResponse(new SearchResponse(new InternalSearchResponse( new SearchHits( - new SearchHit[0], 0L, 0.0f), + new SearchHit[0], new TotalHits(0L, TotalHits.Relation.EQUAL_TO), 0.0f), new InternalAggregations(Collections.emptyList()), new Suggest(Collections.emptyList()), - new SearchProfileShardResults(Collections.emptyMap()), false, false, 1), "", 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, - SearchResponse.Clusters.EMPTY)); + new SearchProfileShardResults(Collections.emptyMap()), false, false, 1), + "", 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY)); } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/CCRIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/CCRIT.java index b6fa146701d..3126538468b 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/CCRIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/CCRIT.java @@ -104,7 +104,7 @@ public class CCRIT extends ESRestHighLevelClientTestCase { SearchRequest leaderSearchRequest = new SearchRequest("leader"); SearchResponse leaderSearchResponse = highLevelClient().search(leaderSearchRequest, RequestOptions.DEFAULT); - assertThat(leaderSearchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(leaderSearchResponse.getHits().getTotalHits().value, equalTo(1L)); assertBusy(() -> { CcrStatsRequest ccrStatsRequest = new CcrStatsRequest(); @@ -118,7 +118,7 @@ public class CCRIT extends ESRestHighLevelClientTestCase { SearchRequest followerSearchRequest = new SearchRequest("follower"); SearchResponse followerSearchResponse = highLevelClient().search(followerSearchRequest, RequestOptions.DEFAULT); - assertThat(followerSearchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(followerSearchResponse.getHits().getTotalHits().value, equalTo(1L)); }); PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower"); @@ -143,7 +143,7 @@ public class CCRIT extends ESRestHighLevelClientTestCase { SearchRequest followerSearchRequest = new SearchRequest("follower"); SearchResponse followerSearchResponse = highLevelClient().search(followerSearchRequest, RequestOptions.DEFAULT); - assertThat(followerSearchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(followerSearchResponse.getHits().getTotalHits().value, equalTo(2L)); }); // Need to pause prior to unfollowing it: diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java index 26eff197aea..e04a6a8867a 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java @@ -882,7 +882,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { assertEquals(0, bulkResponse.getSearchFailures().size()); assertEquals( 2, - highLevelClient().search(new SearchRequest(sourceIndex), RequestOptions.DEFAULT).getHits().totalHits + highLevelClient().search(new SearchRequest(sourceIndex), RequestOptions.DEFAULT).getHits().getTotalHits().value ); } { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index 119a50695ec..51fc4f332bf 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -174,7 +174,7 @@ public class RestHighLevelClientTests extends ESTestCase { SearchResponse searchResponse = restHighLevelClient.scroll( new SearchScrollRequest(randomAlphaOfLengthBetween(5, 10)), RequestOptions.DEFAULT); assertEquals(mockSearchResponse.getScrollId(), searchResponse.getScrollId()); - assertEquals(0, searchResponse.getHits().totalHits); + assertEquals(0, searchResponse.getHits().getTotalHits().value); assertEquals(5, searchResponse.getTotalShards()); assertEquals(5, searchResponse.getSuccessfulShards()); assertEquals(100, searchResponse.getTook().getMillis()); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RollupIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RollupIT.java index f34a73a0991..616e8f59de4 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RollupIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RollupIT.java @@ -189,7 +189,7 @@ public class RollupIT extends ESRestHighLevelClientTestCase { assertBusy(() -> { SearchResponse searchResponse = highLevelClient().search(new SearchRequest(rollupIndex), RequestOptions.DEFAULT); assertEquals(0, searchResponse.getFailedShards()); - assertEquals(1L, searchResponse.getHits().getTotalHits()); + assertEquals(1L, searchResponse.getHits().getTotalHits().value); SearchHit searchHit = searchResponse.getHits().getAt(0); Map source = searchHit.getSourceAsMap(); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java index e6a2f5d6178..0ae426f8e03 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java @@ -208,7 +208,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertNull(searchResponse.getAggregations()); assertNull(searchResponse.getSuggest()); assertEquals(Collections.emptyMap(), searchResponse.getProfileResults()); - assertEquals(5, searchResponse.getHits().totalHits); + assertEquals(5, searchResponse.getHits().getTotalHits().value); assertEquals(5, searchResponse.getHits().getHits().length); for (SearchHit searchHit : searchResponse.getHits().getHits()) { assertEquals("index", searchHit.getIndex()); @@ -232,7 +232,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertNull(searchResponse.getAggregations()); assertNull(searchResponse.getSuggest()); assertEquals(Collections.emptyMap(), searchResponse.getProfileResults()); - assertEquals(1, searchResponse.getHits().totalHits); + assertEquals(1, searchResponse.getHits().getTotalHits().value); assertEquals(1, searchResponse.getHits().getHits().length); assertThat(searchResponse.getHits().getMaxScore(), greaterThan(0f)); SearchHit searchHit = searchResponse.getHits().getHits()[0]; @@ -293,7 +293,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertSearchHeader(searchResponse); assertNull(searchResponse.getSuggest()); assertEquals(Collections.emptyMap(), searchResponse.getProfileResults()); - assertEquals(5, searchResponse.getHits().totalHits); + assertEquals(5, searchResponse.getHits().getTotalHits().value); assertEquals(0, searchResponse.getHits().getHits().length); assertEquals(Float.NaN, searchResponse.getHits().getMaxScore(), 0f); Range rangeAgg = searchResponse.getAggregations().get("agg1"); @@ -375,7 +375,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertSearchHeader(searchResponse); assertNull(searchResponse.getSuggest()); assertEquals(Collections.emptyMap(), searchResponse.getProfileResults()); - assertEquals(5, searchResponse.getHits().totalHits); + assertEquals(5, searchResponse.getHits().getTotalHits().value); assertEquals(0, searchResponse.getHits().getHits().length); assertEquals(Float.NaN, searchResponse.getHits().getMaxScore(), 0f); assertEquals(1, searchResponse.getAggregations().asList().size()); @@ -474,7 +474,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertSearchHeader(searchResponse); assertNull(searchResponse.getSuggest()); assertEquals(Collections.emptyMap(), searchResponse.getProfileResults()); - assertEquals(3, searchResponse.getHits().totalHits); + assertEquals(3, searchResponse.getHits().getTotalHits().value); assertEquals(0, searchResponse.getHits().getHits().length); assertEquals(Float.NaN, searchResponse.getHits().getMaxScore(), 0f); assertEquals(1, searchResponse.getAggregations().asList().size()); @@ -514,7 +514,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertSearchHeader(searchResponse); assertNull(searchResponse.getAggregations()); assertEquals(Collections.emptyMap(), searchResponse.getProfileResults()); - assertEquals(0, searchResponse.getHits().totalHits); + assertEquals(0, searchResponse.getHits().getTotalHits().value); assertEquals(Float.NaN, searchResponse.getHits().getMaxScore(), 0f); assertEquals(0, searchResponse.getHits().getHits().length); assertEquals(1, searchResponse.getSuggest().size()); @@ -592,7 +592,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { try { long counter = 0; assertSearchHeader(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++)); @@ -601,7 +601,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { searchResponse = execute(new SearchScrollRequest(searchResponse.getScrollId()).scroll(TimeValue.timeValueMinutes(2)), highLevelClient()::scroll, highLevelClient()::scrollAsync); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse.getHits()) { assertEquals(counter++, ((Number) hit.getSortValues()[0]).longValue()); @@ -610,7 +610,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { searchResponse = execute(new SearchScrollRequest(searchResponse.getScrollId()).scroll(TimeValue.timeValueMinutes(2)), highLevelClient()::scroll, highLevelClient()::scrollAsync); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(30)); for (SearchHit hit : searchResponse.getHits()) { assertEquals(counter++, ((Number) hit.getSortValues()[0]).longValue()); @@ -653,21 +653,21 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertThat(multiSearchResponse.getResponses()[0].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[0].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[0].getResponse()); - assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits(), Matchers.equalTo(2L)); + assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits().value, Matchers.equalTo(2L)); assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getAt(0).getId(), Matchers.equalTo("1")); assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getAt(1).getId(), Matchers.equalTo("2")); assertThat(multiSearchResponse.getResponses()[1].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[1].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[1].getResponse()); - assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getTotalHits(), Matchers.equalTo(2L)); + assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getTotalHits().value, Matchers.equalTo(2L)); assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getAt(0).getId(), Matchers.equalTo("3")); assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getAt(1).getId(), Matchers.equalTo("4")); assertThat(multiSearchResponse.getResponses()[2].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[2].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[2].getResponse()); - assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getTotalHits(), Matchers.equalTo(2L)); + assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getTotalHits().value, Matchers.equalTo(2L)); assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getAt(0).getId(), Matchers.equalTo("5")); assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getAt(1).getId(), Matchers.equalTo("6")); } @@ -695,7 +695,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertThat(multiSearchResponse.getResponses()[0].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[0].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[0].getResponse()); - assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits(), Matchers.equalTo(2L)); + assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits().value, Matchers.equalTo(2L)); assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getHits().length, Matchers.equalTo(0)); Terms terms = multiSearchResponse.getResponses()[0].getResponse().getAggregations().get("name"); assertThat(terms.getBuckets().size(), Matchers.equalTo(2)); @@ -705,7 +705,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertThat(multiSearchResponse.getResponses()[1].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[1].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[0].getResponse()); - assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getTotalHits(), Matchers.equalTo(2L)); + assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getTotalHits().value, Matchers.equalTo(2L)); assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getHits().length, Matchers.equalTo(0)); terms = multiSearchResponse.getResponses()[1].getResponse().getAggregations().get("name"); assertThat(terms.getBuckets().size(), Matchers.equalTo(2)); @@ -715,7 +715,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertThat(multiSearchResponse.getResponses()[2].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[2].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[0].getResponse()); - assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getTotalHits(), Matchers.equalTo(2L)); + assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getTotalHits().value, Matchers.equalTo(2L)); assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getHits().length, Matchers.equalTo(0)); terms = multiSearchResponse.getResponses()[2].getResponse().getAggregations().get("name"); assertThat(terms.getBuckets().size(), Matchers.equalTo(2)); @@ -743,19 +743,19 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertThat(multiSearchResponse.getResponses()[0].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[0].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[0].getResponse()); - assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits(), Matchers.equalTo(1L)); + assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits().value, Matchers.equalTo(1L)); assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getAt(0).getId(), Matchers.equalTo("2")); assertThat(multiSearchResponse.getResponses()[1].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[1].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[1].getResponse()); - assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getTotalHits(), Matchers.equalTo(1L)); + assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getTotalHits().value, Matchers.equalTo(1L)); assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getAt(0).getId(), Matchers.equalTo("4")); assertThat(multiSearchResponse.getResponses()[2].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[2].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[2].getResponse()); - assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getTotalHits(), Matchers.equalTo(1L)); + assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getTotalHits().value, Matchers.equalTo(1L)); assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getAt(0).getId(), Matchers.equalTo("6")); searchRequest1.source().highlighter(new HighlightBuilder().field("field")); @@ -768,14 +768,14 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertThat(multiSearchResponse.getResponses()[0].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[0].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[0].getResponse()); - assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits(), Matchers.equalTo(1L)); + assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits().value, Matchers.equalTo(1L)); assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getAt(0).getHighlightFields() .get("field").fragments()[0].string(), Matchers.equalTo("value2")); assertThat(multiSearchResponse.getResponses()[1].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[1].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[1].getResponse()); - assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getTotalHits(), Matchers.equalTo(1L)); + assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getTotalHits().value, Matchers.equalTo(1L)); assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getAt(0).getId(), Matchers.equalTo("4")); assertThat(multiSearchResponse.getResponses()[1].getResponse().getHits().getAt(0).getHighlightFields() .get("field").fragments()[0].string(), Matchers.equalTo("value2")); @@ -783,7 +783,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { assertThat(multiSearchResponse.getResponses()[2].getFailure(), Matchers.nullValue()); assertThat(multiSearchResponse.getResponses()[2].isFailure(), Matchers.is(false)); SearchIT.assertSearchHeader(multiSearchResponse.getResponses()[2].getResponse()); - assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getTotalHits(), Matchers.equalTo(1L)); + assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getTotalHits().value, Matchers.equalTo(1L)); assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getAt(0).getId(), Matchers.equalTo("6")); assertThat(multiSearchResponse.getResponses()[2].getResponse().getHits().getAt(0).getHighlightFields() .get("field").fragments()[0].string(), Matchers.equalTo("value2")); @@ -842,7 +842,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { SearchResponse searchResponse = searchTemplateResponse.getResponse(); assertNotNull(searchResponse); - assertEquals(1, searchResponse.getHits().totalHits); + assertEquals(1, searchResponse.getHits().getTotalHits().value); assertEquals(1, searchResponse.getHits().getHits().length); assertThat(searchResponse.getHits().getMaxScore(), greaterThan(0f)); @@ -955,7 +955,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { SearchResponse goodResponse =responses[0].getResponse().getResponse(); assertNotNull(goodResponse); assertThat(responses[0].isFailure(), Matchers.is(false)); - assertEquals(1, goodResponse.getHits().totalHits); + assertEquals(1, goodResponse.getHits().getTotalHits().value); assertEquals(1, goodResponse.getHits().getHits().length); assertThat(goodResponse.getHits().getMaxScore(), greaterThan(0f)); SearchHit hit = goodResponse.getHits().getHits()[0]; diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java index 766385c99aa..8e272baa9fc 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java @@ -20,6 +20,7 @@ package org.elasticsearch.client.documentation; import org.apache.lucene.search.Explanation; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.LatchedActionListener; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; @@ -235,7 +236,11 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { SearchHits hits = searchResponse.getHits(); // end::search-hits-get // tag::search-hits-info - long totalHits = hits.getTotalHits(); + TotalHits totalHits = hits.getTotalHits(); + // the total number of hits, must be interpreted in the context of totalHits.relation + long numHits = totalHits.value; + // whether the number of hits is accurate (EQUAL_TO) or a lower bound of the total (GREATER_THAN_OR_EQUAL_TO) + TotalHits.Relation relation = totalHits.relation; float maxScore = hits.getMaxScore(); // end::search-hits-info // tag::search-hits-singleHit @@ -259,7 +264,8 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { (Map) sourceAsMap.get("innerObject"); // end::search-hits-singleHit-source } - assertEquals(3, totalHits); + assertEquals(3, numHits); + assertEquals(TotalHits.Relation.EQUAL_TO, relation); assertNotNull(hits.getHits()[0].getSourceAsString()); assertNotNull(hits.getHits()[0].getSourceAsMap().get("title")); assertNotNull(hits.getHits()[0].getSourceAsMap().get("innerObject")); @@ -577,7 +583,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { String scrollId = searchResponse.getScrollId(); // <3> SearchHits hits = searchResponse.getHits(); // <4> // end::search-scroll-init - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(1, hits.getHits().length); assertNotNull(scrollId); @@ -587,7 +593,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { SearchResponse searchScrollResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT); scrollId = searchScrollResponse.getScrollId(); // <2> hits = searchScrollResponse.getHits(); // <3> - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(1, hits.getHits().length); assertNotNull(scrollId); // end::search-scroll2 @@ -617,7 +623,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { // end::search-scroll-execute-sync assertEquals(0, searchResponse.getFailedShards()); - assertEquals(3L, searchResponse.getHits().getTotalHits()); + assertEquals(3L, searchResponse.getHits().getTotalHits().value); // tag::search-scroll-execute-listener ActionListener scrollListener = @@ -754,7 +760,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { // end::search-template-response assertNotNull(searchResponse); - assertTrue(searchResponse.getHits().totalHits > 0); + assertTrue(searchResponse.getHits().getTotalHits().value > 0); // tag::render-search-template-request request.setSimulate(true); // <1> @@ -805,7 +811,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { SearchResponse searchResponse = response.getResponse(); assertNotNull(searchResponse); - assertTrue(searchResponse.getHits().totalHits > 0); + assertTrue(searchResponse.getHits().getTotalHits().value > 0); // tag::search-template-execute-listener ActionListener listener = new ActionListener() { @@ -883,7 +889,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { assertEquals(searchTerms.length, multiResponse.getResponses().length); assertNotNull(multiResponse.getResponses()[0]); SearchResponse searchResponse = multiResponse.getResponses()[0].getResponse().getResponse(); - assertTrue(searchResponse.getHits().totalHits > 0); + assertTrue(searchResponse.getHits().getTotalHits().value > 0); } @@ -926,7 +932,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { assertEquals(searchTerms.length, multiResponse.getResponses().length); assertNotNull(multiResponse.getResponses()[0]); SearchResponse searchResponse = multiResponse.getResponses()[0].getResponse().getResponse(); - assertTrue(searchResponse.getHits().totalHits > 0); + assertTrue(searchResponse.getHits().getTotalHits().value > 0); // tag::multi-search-template-execute-listener ActionListener listener = new ActionListener() { @@ -1210,11 +1216,11 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { MultiSearchResponse.Item firstResponse = response.getResponses()[0]; // <1> assertNull(firstResponse.getFailure()); // <2> SearchResponse searchResponse = firstResponse.getResponse(); // <3> - assertEquals(4, searchResponse.getHits().getTotalHits()); + assertEquals(4, searchResponse.getHits().getTotalHits().value); MultiSearchResponse.Item secondResponse = response.getResponses()[1]; // <4> assertNull(secondResponse.getFailure()); searchResponse = secondResponse.getResponse(); - assertEquals(1, searchResponse.getHits().getTotalHits()); + assertEquals(1, searchResponse.getHits().getTotalHits().value); // end::multi-search-response // tag::multi-search-execute-listener diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java index d990710dd9a..c6c0cea0e31 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java @@ -339,7 +339,7 @@ public class WatcherDocumentationIT extends ESRestHighLevelClientTestCase { RestHighLevelClient client = highLevelClient(); { - // tag::x-pack-execute-inline-watch + // tag::x-pack-execute-watch-inline String watchJson = "{ \n" + " \"trigger\": { \"schedule\": { \"interval\": \"10h\" } },\n" + " \"input\": { \"none\": {} },\n" + @@ -352,13 +352,13 @@ public class WatcherDocumentationIT extends ESRestHighLevelClientTestCase { request.setTriggerData("{\"triggered_time\":\"now\"}"); // <4> request.setDebug(true); // <5> ExecuteWatchResponse response = client.watcher().executeWatch(request, RequestOptions.DEFAULT); - // end::x-pack-execute-inline-watch + // end::x-pack-execute-watch-inline - // tag::x-pack-execute-watch-by-id-response + // tag::x-pack-execute-watch-inline-response String id = response.getRecordId(); // <1> Map watch = response.getRecordAsMap(); // <2> String watch_id = ObjectPath.eval("watch_record.watch_id", watch); // <3> - // end::x-pack-execute-watch-by-id-response + // end::x-pack-execute-watch-inline-response } { @@ -368,7 +368,7 @@ public class WatcherDocumentationIT extends ESRestHighLevelClientTestCase { " \"actions\": { \"logme\": { \"logging\": { \"text\": \"{{ctx.payload}}\" } } }\n" + "}"; ExecuteWatchRequest request = ExecuteWatchRequest.inline(watchJson); - // tag::x-pack-execute-inline-watch-execute-listener + // tag::x-pack-execute-watch-inline-execute-listener ActionListener listener = new ActionListener() { @Override public void onResponse(ExecuteWatchResponse response) { @@ -380,15 +380,15 @@ public class WatcherDocumentationIT extends ESRestHighLevelClientTestCase { // <2> } }; - // end::x-pack-execute-inline-watch-execute-listener + // end::x-pack-execute-watch-inline-execute-listener // Replace the empty listener by a blocking listener in test final CountDownLatch latch = new CountDownLatch(1); listener = new LatchedActionListener<>(listener, latch); - // tag::x-pack-execute-inline-watch-execute-async + // tag::x-pack-execute-watch-inline-execute-async client.watcher().executeWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-execute-inline-watch-execute-async + // end::x-pack-execute-watch-inline-execute-async assertTrue(latch.await(30L, TimeUnit.SECONDS)); } diff --git a/docs/java-api/search.asciidoc b/docs/java-api/search.asciidoc index e5abe66f404..47f53ba74f4 100644 --- a/docs/java-api/search.asciidoc +++ b/docs/java-api/search.asciidoc @@ -89,7 +89,7 @@ MultiSearchResponse sr = client.prepareMultiSearch() long nbHits = 0; for (MultiSearchResponse.Item item : sr.getResponses()) { SearchResponse response = item.getResponse(); - nbHits += response.getHits().getTotalHits(); + nbHits += response.getHits().getTotalHits().value; } -------------------------------------------------- diff --git a/docs/java-rest/high-level/watcher/execute-watch.asciidoc b/docs/java-rest/high-level/watcher/execute-watch.asciidoc index 1af93f0cd6c..ed5b4b1659d 100644 --- a/docs/java-rest/high-level/watcher/execute-watch.asciidoc +++ b/docs/java-rest/high-level/watcher/execute-watch.asciidoc @@ -8,7 +8,7 @@ The execute watch API allows clients to immediately execute a watch, either one that has been previously added via the -{ref}/put-watch.html[Put Watch API] or inline as part of the request. +{ref}/watcher-api-put-watch.html[Put Watch API] or inline as part of the request. [id="{upid}-{api}-request-by-id"] ==== Execute by id diff --git a/docs/plugins/ingest-geoip.asciidoc b/docs/plugins/ingest-geoip.asciidoc index a255d0b5121..5d22a31baa8 100644 --- a/docs/plugins/ingest-geoip.asciidoc +++ b/docs/plugins/ingest-geoip.asciidoc @@ -265,7 +265,10 @@ GET /my_ip_locations/_search "failed" : 0 }, "hits" : { - "total" : 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score" : 1.0, "hits" : [ { diff --git a/docs/reference/aggregations/bucket/children-aggregation.asciidoc b/docs/reference/aggregations/bucket/children-aggregation.asciidoc index e2b3c8ec591..dc17157e910 100644 --- a/docs/reference/aggregations/bucket/children-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/children-aggregation.asciidoc @@ -143,7 +143,10 @@ Possible response: "failed": 0 }, "hits": { - "total": 3, + "total" : { + "value": 3, + "relation": "eq" + }, "max_score": null, "hits": [] }, diff --git a/docs/reference/aggregations/bucket/parent-aggregation.asciidoc b/docs/reference/aggregations/bucket/parent-aggregation.asciidoc index 056437df5c8..572357c01c1 100644 --- a/docs/reference/aggregations/bucket/parent-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/parent-aggregation.asciidoc @@ -143,7 +143,10 @@ Possible response: "failed": 0 }, "hits": { - "total": 3, + "total" : { + "value": 3, + "relation": "eq" + }, "max_score": null, "hits": [] }, diff --git a/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc index 958f48d835c..1d225c91e26 100644 --- a/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc @@ -81,7 +81,10 @@ Possible response: "doc_count": 3, "top_sales_hits": { "hits": { - "total": 3, + "total" : { + "value": 3, + "relation": "eq" + }, "max_score": null, "hits": [ { @@ -106,7 +109,10 @@ Possible response: "doc_count": 3, "top_sales_hits": { "hits": { - "total": 3, + "total" : { + "value": 3, + "relation": "eq" + }, "max_score": null, "hits": [ { @@ -131,7 +137,10 @@ Possible response: "doc_count": 1, "top_sales_hits": { "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": null, "hits": [ { @@ -319,7 +328,10 @@ Top hits response snippet with a nested hit, which resides in the first slot of "doc_count": 1, "by_nested": { "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.3616575, "hits": [ { @@ -369,7 +381,10 @@ the second slow of the `nested_child_field` field: -------------------------------------------------- ... "hits": { - "total": 2565, + "total" : { + "value": 2565, + "relation": "eq" + }, "max_score": 1, "hits": [ { diff --git a/docs/reference/aggregations/misc.asciidoc b/docs/reference/aggregations/misc.asciidoc index 20d234302a6..288643dbf93 100644 --- a/docs/reference/aggregations/misc.asciidoc +++ b/docs/reference/aggregations/misc.asciidoc @@ -133,7 +133,10 @@ In the response, the aggregations names will be changed to respectively `date_hi "doc_count" : 5, "top_hits#top_users" : { <2> "hits" : { - "total" : 5, + "total" : { + "value": 5, + "relation": "eq" + }, "max_score" : 1.0, "hits" : [ { diff --git a/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc b/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc index a998e6b11f9..046f6441c07 100644 --- a/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc +++ b/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc @@ -241,7 +241,10 @@ The output from the above is: "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.2876821, "hits": [ { diff --git a/docs/reference/analysis/tokenizers/edgengram-tokenizer.asciidoc b/docs/reference/analysis/tokenizers/edgengram-tokenizer.asciidoc index 9b6861627be..a34f5c80193 100644 --- a/docs/reference/analysis/tokenizers/edgengram-tokenizer.asciidoc +++ b/docs/reference/analysis/tokenizers/edgengram-tokenizer.asciidoc @@ -300,7 +300,10 @@ GET my_index/_search "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.5753642, "hits": [ { diff --git a/docs/reference/docs/delete-by-query.asciidoc b/docs/reference/docs/delete-by-query.asciidoc index 39ac9b134e3..d883212a331 100644 --- a/docs/reference/docs/delete-by-query.asciidoc +++ b/docs/reference/docs/delete-by-query.asciidoc @@ -483,7 +483,10 @@ Which results in a sensible `total` like this one: ---------------------------------------------------------------- { "hits": { - "total": 0 + "total" : { + "value": 0, + "relation": "eq" + } } } ---------------------------------------------------------------- @@ -537,7 +540,10 @@ Which results in a sensible `total` like this one: ---------------------------------------------------------------- { "hits": { - "total": 0 + "total" : { + "value": 0, + "relation": "eq" + } } } ---------------------------------------------------------------- diff --git a/docs/reference/docs/reindex.asciidoc b/docs/reference/docs/reindex.asciidoc index 5a5004f17ae..3dd4a98e99f 100644 --- a/docs/reference/docs/reindex.asciidoc +++ b/docs/reference/docs/reindex.asciidoc @@ -940,7 +940,10 @@ which results in a sensible `total` like this one: ---------------------------------------------------------------- { "hits": { - "total": 120 + "total" : { + "value": 120, + "relation": "eq" + } } } ---------------------------------------------------------------- @@ -983,7 +986,10 @@ which results in a sensible `total` like this one: ---------------------------------------------------------------- { "hits": { - "total": 120 + "total" : { + "value": 120, + "relation": "eq" + } } } ---------------------------------------------------------------- diff --git a/docs/reference/docs/update-by-query.asciidoc b/docs/reference/docs/update-by-query.asciidoc index fab21aa570f..0221b68ce69 100644 --- a/docs/reference/docs/update-by-query.asciidoc +++ b/docs/reference/docs/update-by-query.asciidoc @@ -526,7 +526,10 @@ Which results in a sensible `total` like this one: ---------------------------------------------------------------- { "hits": { - "total": 120 + "total": { + "value": 120, + "relation": "eq" + } } } ---------------------------------------------------------------- @@ -567,7 +570,10 @@ Which results in a sensible `total` like this one: ---------------------------------------------------------------- { "hits": { - "total": 120 + "total": { + "value": 120, + "relation": "eq" + } } } ---------------------------------------------------------------- @@ -688,7 +694,10 @@ POST test/_search?filter_path=hits.total -------------------------------------------------- { "hits" : { - "total" : 0 + "total": { + "value": 0, + "relation": "eq" + } } } -------------------------------------------------- @@ -715,7 +724,10 @@ POST test/_search?filter_path=hits.total -------------------------------------------------- { "hits" : { - "total" : 1 + "total": { + "value": 1, + "relation": "eq" + } } } -------------------------------------------------- diff --git a/docs/reference/getting-started.asciidoc b/docs/reference/getting-started.asciidoc index 1a60d4d83e2..382d881a46e 100755 --- a/docs/reference/getting-started.asciidoc +++ b/docs/reference/getting-started.asciidoc @@ -735,7 +735,10 @@ And the response (partially shown): "failed" : 0 }, "hits" : { - "total" : 1000, + "total" : { + "value": 1000, + "relation": "eq" + }, "max_score" : null, "hits" : [ { "_index" : "bank", @@ -765,11 +768,17 @@ As for the response, we see the following parts: * `timed_out` – tells us if the search timed out or not * `_shards` – tells us how many shards were searched, as well as a count of the successful/failed searched shards * `hits` – search results -* `hits.total` – total number of documents matching our search criteria +* `hits.total` – an object that contains information about the total number of documents matching our search criteria +** `hits.total.value` - the value of the total hit count (must be interpreted in the context of `hits.total.relation`). +** `hits.total.relation` - whether `hits.total.value` is the exact hit count, in which case it is equal to `"eq"` or a + lower bound of the total hit count (greater than or equals), in which case it is equal to `gte`. * `hits.hits` – actual array of search results (defaults to first 10 documents) * `hits.sort` - sort key for results (missing if sorting by score) * `hits._score` and `max_score` - ignore these fields for now +The accuracy of `hits.total` is controlled by the request parameter `track_total_hits`, when set to true +the request will track the total hits accurately (`"relation": "eq"`). + Here is the same exact search above using the alternative request body method: [source,js] @@ -803,7 +812,10 @@ to clutter the docs with it: "failed" : 0 }, "hits" : { - "total" : 1000, + "total" : { + "value": 1000, + "relation": "eq" + }, "max_score": null, "hits" : [ { "_index" : "bank", @@ -1134,7 +1146,10 @@ And the response (partially shown): "failed": 0 }, "hits" : { - "total" : 1000, + "total" : { + "value": 1000, + "relation": "eq" + }, "max_score" : null, "hits" : [ ] }, diff --git a/docs/reference/how-to/recipes/stemming.asciidoc b/docs/reference/how-to/recipes/stemming.asciidoc index c09922fe63f..83f1379cd32 100644 --- a/docs/reference/how-to/recipes/stemming.asciidoc +++ b/docs/reference/how-to/recipes/stemming.asciidoc @@ -84,7 +84,10 @@ GET index/_search "failed": 0 }, "hits": { - "total": 2, + "total" : { + "value": 2, + "relation": "eq" + }, "max_score": 0.18232156, "hits": [ { @@ -142,7 +145,10 @@ GET index/_search "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.8025915, "hits": [ { @@ -199,7 +205,10 @@ GET index/_search "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.8025915, "hits": [ { diff --git a/docs/reference/index-modules/index-sorting.asciidoc b/docs/reference/index-modules/index-sorting.asciidoc index 30c28165af8..30ea9f43c6d 100644 --- a/docs/reference/index-modules/index-sorting.asciidoc +++ b/docs/reference/index-modules/index-sorting.asciidoc @@ -188,8 +188,7 @@ as soon as N documents have been collected per segment. -------------------------------------------------- { "_shards": ... - "hits" : { - "total" : -1, <1> + "hits" : { <1> "max_score" : null, "hits" : [] }, diff --git a/docs/reference/index-modules/similarity.asciidoc b/docs/reference/index-modules/similarity.asciidoc index cf5cab106f8..06abaadd245 100644 --- a/docs/reference/index-modules/similarity.asciidoc +++ b/docs/reference/index-modules/similarity.asciidoc @@ -263,7 +263,10 @@ Which yields: "failed": 0 }, "hits": { - "total": 1, + "total": { + "value": 1, + "relation": "eq" + }, "max_score": 1.9508477, "hits": [ { @@ -437,7 +440,10 @@ GET /index/_search?explain=true "failed": 0 }, "hits": { - "total": 1, + "total": { + "value": 1, + "relation": "eq" + }, "max_score": 1.9508477, "hits": [ { diff --git a/docs/reference/mapping/params/normalizer.asciidoc b/docs/reference/mapping/params/normalizer.asciidoc index 73110cd11f5..bfd24381753 100644 --- a/docs/reference/mapping/params/normalizer.asciidoc +++ b/docs/reference/mapping/params/normalizer.asciidoc @@ -89,7 +89,10 @@ both index and query time. "failed": 0 }, "hits": { - "total": 2, + "total" : { + "value": 2, + "relation": "eq" + }, "max_score": 0.47000363, "hits": [ { @@ -150,7 +153,10 @@ returns "failed": 0 }, "hits": { - "total": 3, + "total" : { + "value": 3, + "relation": "eq" + }, "max_score": null, "hits": [] }, diff --git a/docs/reference/mapping/types/parent-join.asciidoc b/docs/reference/mapping/types/parent-join.asciidoc index d2d68fc1359..ea2e1f719a7 100644 --- a/docs/reference/mapping/types/parent-join.asciidoc +++ b/docs/reference/mapping/types/parent-join.asciidoc @@ -175,7 +175,10 @@ Will return: { ..., "hits": { - "total": 4, + "total" : { + "value": 4, + "relation": "eq" + }, "max_score": null, "hits": [ { diff --git a/docs/reference/mapping/types/percolator.asciidoc b/docs/reference/mapping/types/percolator.asciidoc index a37acb6f9f5..c6d31d942b9 100644 --- a/docs/reference/mapping/types/percolator.asciidoc +++ b/docs/reference/mapping/types/percolator.asciidoc @@ -199,7 +199,10 @@ now returns matches from the new index: "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.13076457, "hits": [ { @@ -394,7 +397,10 @@ This results in a response like this: "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.13076457, "hits": [ { @@ -553,7 +559,10 @@ GET /my_queries1/_search "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.18864399, "hits": [ { diff --git a/docs/reference/mapping/types/range.asciidoc b/docs/reference/mapping/types/range.asciidoc index 082d012a490..fcf13ed446b 100644 --- a/docs/reference/mapping/types/range.asciidoc +++ b/docs/reference/mapping/types/range.asciidoc @@ -87,7 +87,10 @@ The result produced by the above query. "failed": 0 }, "hits" : { - "total" : 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score" : 1.0, "hits" : [ { @@ -147,7 +150,10 @@ This query produces a similar result: "failed": 0 }, "hits" : { - "total" : 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score" : 1.0, "hits" : [ { diff --git a/docs/reference/migration/migrate_7_0/search.asciidoc b/docs/reference/migration/migrate_7_0/search.asciidoc index 5774f17c3e3..2ca7c6787bf 100644 --- a/docs/reference/migration/migrate_7_0/search.asciidoc +++ b/docs/reference/migration/migrate_7_0/search.asciidoc @@ -170,3 +170,37 @@ on whether queries need to access score or not. As a result `bool` queries with `minimum_should_match` to 1. This behavior has been deprecated in the previous major version. +[float] +==== `hits.total` is now an object in the search response + +The total hits that match the search request is now returned as an object +with a `value` and a `relation`. `value indicates the number of hits that +match and `relation indicates whether the value is accurate (`eq`) or a lower bound +(`gte`): +``` +{ + "hits": { + "total": { <1> + "value": 1000, + "relation": "eq" + }, + ... + } +} +``` + +The "total" object in the response indicates that the query matches exactly 1000 +documents ("eq"). The `value` is always accurate (`"relation": "eq"`) when +`track_total_hits` is set to true in the request. +You can also retrieve `hits.total` as a number in the rest response by adding +`rest_total_hits_as_int=true` in the request parameter of the search request. +This parameter has been added to ease the transition to the new format and +will be removed in the next major version (8.0). + +[float] +==== `hits.total` is omitted in the response if `track_total_hits` is disabled (false) + +If `track_total_hits` is set to `false in the search request the search response +will set `hits.total` to null and the object will not be displayed in the rest +layer. You can add `rest_total_hits_as_int=true` in the search request parameters +to get the old format back (`"total": -1`). \ No newline at end of file diff --git a/docs/reference/modules/cross-cluster-search.asciidoc b/docs/reference/modules/cross-cluster-search.asciidoc index 2db2494d2f3..61b0bb50aed 100644 --- a/docs/reference/modules/cross-cluster-search.asciidoc +++ b/docs/reference/modules/cross-cluster-search.asciidoc @@ -77,7 +77,10 @@ GET /cluster_one:twitter/_search "skipped": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1, "hits": [ { @@ -139,7 +142,10 @@ will be prefixed with their remote cluster name: "skipped": 0 }, "hits": { - "total": 2, + "total" : { + "value": 2, + "relation": "eq" + }, "max_score": 1, "hits": [ { @@ -228,7 +234,10 @@ GET /cluster_one:twitter,cluster_two:twitter,twitter/_search <1> "skipped": 1 }, "hits": { - "total": 2, + "total" : { + "value": 2, + "relation": "eq" + }, "max_score": 1, "hits": [ { diff --git a/docs/reference/query-dsl/percolate-query.asciidoc b/docs/reference/query-dsl/percolate-query.asciidoc index 11d11402ecb..a343b4dbb89 100644 --- a/docs/reference/query-dsl/percolate-query.asciidoc +++ b/docs/reference/query-dsl/percolate-query.asciidoc @@ -89,7 +89,10 @@ The above request will yield the following response: "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.26152915, "hits": [ { <1> @@ -237,7 +240,10 @@ GET /my-index/_search "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.7093853, "hits": [ { @@ -417,7 +423,10 @@ This will yield the following response. "failed": 0 }, "hits": { - "total": 2, + "total" : { + "value": 2, + "relation": "eq" + }, "max_score": 0.26152915, "hits": [ { @@ -522,7 +531,10 @@ The slightly different response: "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.7093853, "hits": [ { @@ -618,7 +630,10 @@ The above search request returns a response similar to this: "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.26152915, "hits": [ { diff --git a/docs/reference/query-dsl/terms-set-query.asciidoc b/docs/reference/query-dsl/terms-set-query.asciidoc index 4067a1e847e..fa879bb068d 100644 --- a/docs/reference/query-dsl/terms-set-query.asciidoc +++ b/docs/reference/query-dsl/terms-set-query.asciidoc @@ -72,7 +72,10 @@ Response: "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.87546873, "hits": [ { diff --git a/docs/reference/rollup/apis/rollup-search.asciidoc b/docs/reference/rollup/apis/rollup-search.asciidoc index e2252a77218..80e4595b78b 100644 --- a/docs/reference/rollup/apis/rollup-search.asciidoc +++ b/docs/reference/rollup/apis/rollup-search.asciidoc @@ -116,7 +116,10 @@ aggregation has been used on the `temperature` field, yielding the following res "terminated_early" : false, "_shards" : ... , "hits" : { - "total" : 0, + "total" : { + "value": 0, + "relation": "eq" + }, "max_score" : 0.0, "hits" : [ ] }, @@ -219,7 +222,10 @@ The response to the above query will look as expected, despite spanning rollup a "terminated_early" : false, "_shards" : ... , "hits" : { - "total" : 0, + "total" : { + "value": 0, + "relation": "eq" + }, "max_score" : 0.0, "hits" : [ ] }, diff --git a/docs/reference/rollup/rollup-getting-started.asciidoc b/docs/reference/rollup/rollup-getting-started.asciidoc index 8f99bc2c010..b487f7809bf 100644 --- a/docs/reference/rollup/rollup-getting-started.asciidoc +++ b/docs/reference/rollup/rollup-getting-started.asciidoc @@ -158,7 +158,10 @@ If you were to execute that query, you'd receive a result that looks like a norm "terminated_early" : false, "_shards" : ... , "hits" : { - "total" : 0, + "total" : { + "value": 0, + "relation": "eq" + }, "max_score" : 0.0, "hits" : [ ] }, @@ -229,7 +232,10 @@ Which returns a corresponding response: "terminated_early" : false, "_shards" : ... , "hits" : { - "total" : 0, + "total" : { + "value": 0, + "relation": "eq" + }, "max_score" : 0.0, "hits" : [ ] }, diff --git a/docs/reference/search/profile.asciidoc b/docs/reference/search/profile.asciidoc index bc7edcd3a88..2b4eb36bfe2 100644 --- a/docs/reference/search/profile.asciidoc +++ b/docs/reference/search/profile.asciidoc @@ -45,7 +45,10 @@ This will yield the following result: "failed": 0 }, "hits": { - "total": 4, + "total" : { + "value": 4, + "relation": "eq" + }, "max_score": 0.5093388, "hits": [...] <1> }, diff --git a/docs/reference/search/request-body.asciidoc b/docs/reference/search/request-body.asciidoc index 5be54662d01..7145b40c43e 100644 --- a/docs/reference/search/request-body.asciidoc +++ b/docs/reference/search/request-body.asciidoc @@ -31,7 +31,10 @@ And here is a sample response: "failed" : 0 }, "hits":{ - "total" : 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1.3862944, "hits" : [ { @@ -162,7 +165,10 @@ be set to `true` in the response. "failed": 0 }, "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": null, "hits": [] } diff --git a/docs/reference/search/request/highlighting.asciidoc b/docs/reference/search/request/highlighting.asciidoc index a506f6219fc..e798fcf1869 100644 --- a/docs/reference/search/request/highlighting.asciidoc +++ b/docs/reference/search/request/highlighting.asciidoc @@ -860,7 +860,10 @@ Response: { ... "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1.601195, "hits": [ { @@ -916,7 +919,10 @@ Response: { ... "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1.601195, "hits": [ { diff --git a/docs/reference/search/request/inner-hits.asciidoc b/docs/reference/search/request/inner-hits.asciidoc index 8e719a02c75..a1eeeb8f063 100644 --- a/docs/reference/search/request/inner-hits.asciidoc +++ b/docs/reference/search/request/inner-hits.asciidoc @@ -136,7 +136,10 @@ An example of a response snippet that could be generated from the above search r { ..., "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1.0, "hits": [ { @@ -148,7 +151,10 @@ An example of a response snippet that could be generated from the above search r "inner_hits": { "comments": { <1> "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1.0, "hits": [ { @@ -264,7 +270,10 @@ Response not included in text but tested for completeness sake. { ..., "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1.0444684, "hits": [ { @@ -276,7 +285,10 @@ Response not included in text but tested for completeness sake. "inner_hits": { "comments": { <1> "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1.0444684, "hits": [ { @@ -379,7 +391,10 @@ Which would look like: { ..., "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.6931472, "hits": [ { @@ -391,7 +406,10 @@ Which would look like: "inner_hits": { "comments.votes": { <1> "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 0.6931472, "hits": [ { @@ -490,7 +508,10 @@ An example of a response snippet that could be generated from the above search r { ..., "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1.0, "hits": [ { @@ -505,7 +526,10 @@ An example of a response snippet that could be generated from the above search r "inner_hits": { "my_child": { "hits": { - "total": 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1.0, "hits": [ { diff --git a/docs/reference/search/suggesters/completion-suggest.asciidoc b/docs/reference/search/suggesters/completion-suggest.asciidoc index c52f28bc7be..b2b7f7a4437 100644 --- a/docs/reference/search/suggesters/completion-suggest.asciidoc +++ b/docs/reference/search/suggesters/completion-suggest.asciidoc @@ -257,7 +257,10 @@ Which should look like: "failed" : 0 }, "hits": { - "total" : 0, + "total" : { + "value": 0, + "relation": "eq" + }, "max_score" : null, "hits" : [] }, diff --git a/docs/reference/search/uri-request.asciidoc b/docs/reference/search/uri-request.asciidoc index bfc50e774bf..320e65bf3ee 100644 --- a/docs/reference/search/uri-request.asciidoc +++ b/docs/reference/search/uri-request.asciidoc @@ -27,7 +27,10 @@ And here is a sample response: "failed" : 0 }, "hits":{ - "total" : 1, + "total" : { + "value": 1, + "relation": "eq" + }, "max_score": 1.3862944, "hits" : [ { diff --git a/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java b/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java index 219c3c5bbba..dad79e0c0ab 100644 --- a/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java +++ b/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java @@ -437,6 +437,7 @@ public final class ObjectParser extends AbstractObjectParser").postTags("")); searchResponse = client().search(searchRequest("first_test_index").source(source)).actionGet(); - assertThat(searchResponse.getHits().totalHits, equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); for (int i = 0; i < 2; i++) { assertHighlight(searchResponse, i, "field1", 0, 1, anyOf( equalTo("The quick browse button is a fancy thing, right bro?"), diff --git a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/10_match.yml b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/10_match.yml index fca70a57697..2f97450012d 100644 --- a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/10_match.yml +++ b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/10_match.yml @@ -16,6 +16,7 @@ tokenizer: standard filter: [lowercase] search: + rest_total_hits_as_int: true tokenizer: standard filter: [lowercase, keyword_repeat, porter_stem, unique_stem] filter: @@ -40,6 +41,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -58,6 +60,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: diff --git a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/20_ngram_search.yml b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/20_ngram_search.yml index ec7b9493ac0..8b5fd16904c 100644 --- a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/20_ngram_search.yml +++ b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/20_ngram_search.yml @@ -33,6 +33,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -80,6 +81,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -89,6 +91,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -98,6 +101,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -107,6 +111,7 @@ - do: search: + rest_total_hits_as_int: true body: query: term: @@ -116,6 +121,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -126,6 +132,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: diff --git a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/30_ngram_highligthing.yml b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/30_ngram_highligthing.yml index c1dca047f60..a69faecf2cd 100644 --- a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/30_ngram_highligthing.yml +++ b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/30_ngram_highligthing.yml @@ -53,6 +53,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -66,6 +67,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -79,6 +81,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -92,6 +95,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -105,6 +109,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -118,6 +123,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: diff --git a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/40_query_string.yml b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/40_query_string.yml index db5d6b2fad6..338ab83e1ef 100644 --- a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/40_query_string.yml +++ b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/40_query_string.yml @@ -33,6 +33,7 @@ - do: search: + rest_total_hits_as_int: true index: test q: field:bars analyzer: snowball diff --git a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/50_queries_with_synonyms.yml b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/50_queries_with_synonyms.yml index c7a8122337e..874b4852244 100644 --- a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/50_queries_with_synonyms.yml +++ b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/50_queries_with_synonyms.yml @@ -52,6 +52,7 @@ - do: search: + rest_total_hits_as_int: true body: query: common: @@ -66,6 +67,7 @@ - do: search: + rest_total_hits_as_int: true body: query: common: @@ -79,6 +81,7 @@ - do: search: + rest_total_hits_as_int: true body: query: common: @@ -92,6 +95,7 @@ - do: search: + rest_total_hits_as_int: true body: query: common: @@ -104,6 +108,7 @@ - do: search: + rest_total_hits_as_int: true body: query: common: @@ -118,6 +123,7 @@ - do: search: + rest_total_hits_as_int: true body: query: common: @@ -131,6 +137,7 @@ - do: search: + rest_total_hits_as_int: true body: query: common: @@ -142,6 +149,7 @@ - do: search: + rest_total_hits_as_int: true body: query: common: @@ -155,6 +163,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -168,6 +177,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -182,6 +192,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -195,6 +206,7 @@ - do: search: + rest_total_hits_as_int: true body: query: multi_match: @@ -225,6 +237,7 @@ tokenizer: standard filter: lowercase search: + rest_total_hits_as_int: true type: custom tokenizer: standard filter: [ lowercase, synonym ] @@ -247,6 +260,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -257,6 +271,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -267,6 +282,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -286,6 +302,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: @@ -296,6 +313,7 @@ - do: search: + rest_total_hits_as_int: true body: query: match: diff --git a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/60_synonym_graph.yml b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/60_synonym_graph.yml index 6b4c482efca..c4b1c85eddf 100644 --- a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/60_synonym_graph.yml +++ b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/60_synonym_graph.yml @@ -81,6 +81,7 @@ setup: "simple multiterm phrase": - do: search: + rest_total_hits_as_int: true body: query: match_phrase: @@ -92,6 +93,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: match_phrase: @@ -105,6 +107,7 @@ setup: "simple multiterm and": - do: search: + rest_total_hits_as_int: true body: query: match: @@ -117,6 +120,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: match: @@ -131,6 +135,7 @@ setup: "minimum should match": - do: search: + rest_total_hits_as_int: true body: query: match: @@ -143,6 +148,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: match: @@ -160,6 +166,7 @@ setup: "multiterm synonyms phrase": - do: search: + rest_total_hits_as_int: true body: query: match: @@ -193,6 +200,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: match_phrase_prefix: diff --git a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.suggest/20_phrase.yml b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.suggest/20_phrase.yml index 18c3c814625..9ac7ea7901d 100644 --- a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.suggest/20_phrase.yml +++ b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.suggest/20_phrase.yml @@ -99,6 +99,7 @@ setup: "sorts by score": - do: search: + rest_total_hits_as_int: true size: 0 index: test body: @@ -122,6 +123,7 @@ setup: # This runs the suggester without bigrams so we can be sure of the sort order - do: search: + rest_total_hits_as_int: true size: 0 index: test body: @@ -148,6 +150,7 @@ setup: - do: catch: /since it doesn't emit unigrams/ search: + rest_total_hits_as_int: true size: 0 index: test body: @@ -160,6 +163,7 @@ setup: - do: catch: /since it doesn't emit unigrams/ search: + rest_total_hits_as_int: true size: 0 index: test body: @@ -174,6 +178,7 @@ setup: "doesn't fail when asked to run on a field without unigrams when force_unigrams=false": - do: search: + rest_total_hits_as_int: true size: 0 index: test body: @@ -186,6 +191,7 @@ setup: - do: search: + rest_total_hits_as_int: true size: 0 index: test body: @@ -201,6 +207,7 @@ setup: "reverse suggestions": - do: search: + rest_total_hits_as_int: true size: 0 index: test body: diff --git a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.suggest/30_synonyms.yml b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.suggest/30_synonyms.yml index 85bc348fa41..cfac6742fbf 100644 --- a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.suggest/30_synonyms.yml +++ b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.suggest/30_synonyms.yml @@ -34,6 +34,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: suggest: diff --git a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java index 7b1e53a336c..4f8fa5f463e 100644 --- a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java +++ b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java @@ -90,7 +90,7 @@ public class MoreExpressionTests extends ESIntegTestCase { ensureGreen("test"); client().prepareIndex("test", "doc", "1").setSource("foo", 4).setRefreshPolicy(IMMEDIATE).get(); SearchResponse rsp = buildRequest("doc['foo'] + 1").get(); - assertEquals(1, rsp.getHits().getTotalHits()); + assertEquals(1, rsp.getHits().getTotalHits().value); assertEquals(5.0, rsp.getHits().getAt(0).field("foo").getValue(), 0.0D); } @@ -100,7 +100,7 @@ public class MoreExpressionTests extends ESIntegTestCase { client().prepareIndex("test", "doc", "1").setSource("foo", 4).setRefreshPolicy(IMMEDIATE).get(); SearchResponse rsp = buildRequest("doc['foo'] + abs(1)").get(); assertSearchResponse(rsp); - assertEquals(1, rsp.getHits().getTotalHits()); + assertEquals(1, rsp.getHits().getTotalHits().value); assertEquals(5.0, rsp.getHits().getAt(0).field("foo").getValue(), 0.0D); } @@ -109,7 +109,7 @@ public class MoreExpressionTests extends ESIntegTestCase { ensureGreen("test"); client().prepareIndex("test", "doc", "1").setSource("foo", 4).setRefreshPolicy(IMMEDIATE).get(); SearchResponse rsp = buildRequest("doc['foo'].value + 1").get(); - assertEquals(1, rsp.getHits().getTotalHits()); + assertEquals(1, rsp.getHits().getTotalHits().value); assertEquals(5.0, rsp.getHits().getAt(0).field("foo").getValue(), 0.0D); } @@ -128,7 +128,7 @@ public class MoreExpressionTests extends ESIntegTestCase { SearchResponse rsp = req.get(); assertSearchResponse(rsp); SearchHits hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals("1", hits.getAt(0).getId()); assertEquals("3", hits.getAt(1).getId()); assertEquals("2", hits.getAt(2).getId()); @@ -141,22 +141,22 @@ public class MoreExpressionTests extends ESIntegTestCase { client().prepareIndex("test", "doc", "1").setSource("date0", "2015-04-28T04:02:07Z", "date1", "1985-09-01T23:11:01Z"), client().prepareIndex("test", "doc", "2").setSource("date0", "2013-12-25T11:56:45Z", "date1", "1983-10-13T23:15:00Z")); SearchResponse rsp = buildRequest("doc['date0'].getSeconds() - doc['date0'].getMinutes()").get(); - assertEquals(2, rsp.getHits().getTotalHits()); + assertEquals(2, rsp.getHits().getTotalHits().value); SearchHits hits = rsp.getHits(); assertEquals(5.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(-11.0, hits.getAt(1).field("foo").getValue(), 0.0D); rsp = buildRequest("doc['date0'].getHourOfDay() + doc['date1'].getDayOfMonth()").get(); - assertEquals(2, rsp.getHits().getTotalHits()); + assertEquals(2, rsp.getHits().getTotalHits().value); hits = rsp.getHits(); assertEquals(5.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(24.0, hits.getAt(1).field("foo").getValue(), 0.0D); rsp = buildRequest("doc['date1'].getMonth() + 1").get(); - assertEquals(2, rsp.getHits().getTotalHits()); + assertEquals(2, rsp.getHits().getTotalHits().value); hits = rsp.getHits(); assertEquals(9.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(10.0, hits.getAt(1).field("foo").getValue(), 0.0D); rsp = buildRequest("doc['date1'].getYear()").get(); - assertEquals(2, rsp.getHits().getTotalHits()); + assertEquals(2, rsp.getHits().getTotalHits().value); hits = rsp.getHits(); assertEquals(1985.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(1983.0, hits.getAt(1).field("foo").getValue(), 0.0D); @@ -169,22 +169,22 @@ public class MoreExpressionTests extends ESIntegTestCase { client().prepareIndex("test", "doc", "1").setSource("date0", "2015-04-28T04:02:07Z", "date1", "1985-09-01T23:11:01Z"), client().prepareIndex("test", "doc", "2").setSource("date0", "2013-12-25T11:56:45Z", "date1", "1983-10-13T23:15:00Z")); SearchResponse rsp = buildRequest("doc['date0'].date.secondOfMinute - doc['date0'].date.minuteOfHour").get(); - assertEquals(2, rsp.getHits().getTotalHits()); + assertEquals(2, rsp.getHits().getTotalHits().value); SearchHits hits = rsp.getHits(); assertEquals(5.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(-11.0, hits.getAt(1).field("foo").getValue(), 0.0D); rsp = buildRequest("doc['date0'].date.getHourOfDay() + doc['date1'].date.dayOfMonth").get(); - assertEquals(2, rsp.getHits().getTotalHits()); + assertEquals(2, rsp.getHits().getTotalHits().value); hits = rsp.getHits(); assertEquals(5.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(24.0, hits.getAt(1).field("foo").getValue(), 0.0D); rsp = buildRequest("doc['date1'].date.monthOfYear + 1").get(); - assertEquals(2, rsp.getHits().getTotalHits()); + assertEquals(2, rsp.getHits().getTotalHits().value); hits = rsp.getHits(); assertEquals(10.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(11.0, hits.getAt(1).field("foo").getValue(), 0.0D); rsp = buildRequest("doc['date1'].date.year").get(); - assertEquals(2, rsp.getHits().getTotalHits()); + assertEquals(2, rsp.getHits().getTotalHits().value); hits = rsp.getHits(); assertEquals(1985.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(1983.0, hits.getAt(1).field("foo").getValue(), 0.0D); @@ -219,7 +219,7 @@ public class MoreExpressionTests extends ESIntegTestCase { SearchResponse rsp = buildRequest("doc['double0'].count() + doc['double1'].count()").get(); assertSearchResponse(rsp); SearchHits hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(5.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(2.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(5.0, hits.getAt(2).field("foo").getValue(), 0.0D); @@ -227,7 +227,7 @@ public class MoreExpressionTests extends ESIntegTestCase { rsp = buildRequest("doc['double0'].sum()").get(); assertSearchResponse(rsp); hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(7.5, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(5.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(6.0, hits.getAt(2).field("foo").getValue(), 0.0D); @@ -235,7 +235,7 @@ public class MoreExpressionTests extends ESIntegTestCase { rsp = buildRequest("doc['double0'].avg() + doc['double1'].avg()").get(); assertSearchResponse(rsp); hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(4.3, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(8.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(5.5, hits.getAt(2).field("foo").getValue(), 0.0D); @@ -243,7 +243,7 @@ public class MoreExpressionTests extends ESIntegTestCase { rsp = buildRequest("doc['double0'].median()").get(); assertSearchResponse(rsp); hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(1.5, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(5.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(1.25, hits.getAt(2).field("foo").getValue(), 0.0D); @@ -251,7 +251,7 @@ public class MoreExpressionTests extends ESIntegTestCase { rsp = buildRequest("doc['double0'].min()").get(); assertSearchResponse(rsp); hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(1.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(5.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(-1.5, hits.getAt(2).field("foo").getValue(), 0.0D); @@ -259,7 +259,7 @@ public class MoreExpressionTests extends ESIntegTestCase { rsp = buildRequest("doc['double0'].max()").get(); assertSearchResponse(rsp); hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(5.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(5.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(5.0, hits.getAt(2).field("foo").getValue(), 0.0D); @@ -267,7 +267,7 @@ public class MoreExpressionTests extends ESIntegTestCase { rsp = buildRequest("doc['double0'].sum()/doc['double0'].count()").get(); assertSearchResponse(rsp); hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(2.5, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(5.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(1.5, hits.getAt(2).field("foo").getValue(), 0.0D); @@ -276,7 +276,7 @@ public class MoreExpressionTests extends ESIntegTestCase { rsp = buildRequest("doc['double2'].count()").get(); assertSearchResponse(rsp); hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(1.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(0.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(0.0, hits.getAt(2).field("foo").getValue(), 0.0D); @@ -285,7 +285,7 @@ public class MoreExpressionTests extends ESIntegTestCase { rsp = buildRequest("doc['double2'].empty ? 5.0 : 2.0").get(); assertSearchResponse(rsp); hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(2.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(5.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(5.0, hits.getAt(2).field("foo").getValue(), 0.0D); @@ -315,7 +315,7 @@ public class MoreExpressionTests extends ESIntegTestCase { SearchResponse rsp = buildRequest("doc['x'] + 1").get(); ElasticsearchAssertions.assertSearchResponse(rsp); SearchHits hits = rsp.getHits(); - assertEquals(2, rsp.getHits().getTotalHits()); + assertEquals(2, rsp.getHits().getTotalHits().value); assertEquals(5.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(1.0, hits.getAt(1).field("foo").getValue(), 0.0D); } @@ -346,7 +346,7 @@ public class MoreExpressionTests extends ESIntegTestCase { String script = "doc['x'] * a + b + ((c + doc['x']) > 5000000009 ? 1 : 0)"; SearchResponse rsp = buildRequest(script, "a", 2, "b", 3.5, "c", 5000000000L).get(); SearchHits hits = rsp.getHits(); - assertEquals(3, hits.getTotalHits()); + assertEquals(3, hits.getTotalHits().value); assertEquals(24.5, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(9.5, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(13.5, hits.getAt(2).field("foo").getValue(), 0.0D); @@ -456,7 +456,7 @@ public class MoreExpressionTests extends ESIntegTestCase { ); SearchResponse rsp = req.get(); - assertEquals(3, rsp.getHits().getTotalHits()); + assertEquals(3, rsp.getHits().getTotalHits().value); Stats stats = rsp.getAggregations().get("int_agg"); assertEquals(39.0, stats.getMax(), 0.0001); @@ -587,22 +587,22 @@ public class MoreExpressionTests extends ESIntegTestCase { // access .lat SearchResponse rsp = buildRequest("doc['location'].lat").get(); assertSearchResponse(rsp); - assertEquals(1, rsp.getHits().getTotalHits()); + assertEquals(1, rsp.getHits().getTotalHits().value); assertEquals(61.5240, rsp.getHits().getAt(0).field("foo").getValue(), 1.0D); // access .lon rsp = buildRequest("doc['location'].lon").get(); assertSearchResponse(rsp); - assertEquals(1, rsp.getHits().getTotalHits()); + assertEquals(1, rsp.getHits().getTotalHits().value); assertEquals(105.3188, rsp.getHits().getAt(0).field("foo").getValue(), 1.0D); // access .empty rsp = buildRequest("doc['location'].empty ? 1 : 0").get(); assertSearchResponse(rsp); - assertEquals(1, rsp.getHits().getTotalHits()); + assertEquals(1, rsp.getHits().getTotalHits().value); assertEquals(0, rsp.getHits().getAt(0).field("foo").getValue(), 1.0D); // call haversin rsp = buildRequest("haversin(38.9072, 77.0369, doc['location'].lat, doc['location'].lon)").get(); assertSearchResponse(rsp); - assertEquals(1, rsp.getHits().getTotalHits()); + assertEquals(1, rsp.getHits().getTotalHits().value); assertEquals(3170D, rsp.getHits().getAt(0).field("foo").getValue(), 50D); } @@ -619,14 +619,14 @@ public class MoreExpressionTests extends ESIntegTestCase { // access .value SearchResponse rsp = buildRequest("doc['vip'].value").get(); assertSearchResponse(rsp); - assertEquals(3, rsp.getHits().getTotalHits()); + assertEquals(3, rsp.getHits().getTotalHits().value); assertEquals(1.0D, rsp.getHits().getAt(0).field("foo").getValue(), 1.0D); assertEquals(0.0D, rsp.getHits().getAt(1).field("foo").getValue(), 1.0D); assertEquals(0.0D, rsp.getHits().getAt(2).field("foo").getValue(), 1.0D); // access .empty rsp = buildRequest("doc['vip'].empty ? 1 : 0").get(); assertSearchResponse(rsp); - assertEquals(3, rsp.getHits().getTotalHits()); + assertEquals(3, rsp.getHits().getTotalHits().value); assertEquals(0.0D, rsp.getHits().getAt(0).field("foo").getValue(), 1.0D); assertEquals(0.0D, rsp.getHits().getAt(1).field("foo").getValue(), 1.0D); assertEquals(1.0D, rsp.getHits().getAt(2).field("foo").getValue(), 1.0D); @@ -634,7 +634,7 @@ public class MoreExpressionTests extends ESIntegTestCase { // vip's have a 50% discount rsp = buildRequest("doc['vip'] ? doc['price']/2 : doc['price']").get(); assertSearchResponse(rsp); - assertEquals(3, rsp.getHits().getTotalHits()); + assertEquals(3, rsp.getHits().getTotalHits().value); assertEquals(0.5D, rsp.getHits().getAt(0).field("foo").getValue(), 1.0D); assertEquals(2.0D, rsp.getHits().getAt(1).field("foo").getValue(), 1.0D); assertEquals(2.0D, rsp.getHits().getAt(2).field("foo").getValue(), 1.0D); @@ -651,7 +651,7 @@ public class MoreExpressionTests extends ESIntegTestCase { builder.setQuery(QueryBuilders.boolQuery().filter(QueryBuilders.scriptQuery(script))); SearchResponse rsp = builder.get(); assertSearchResponse(rsp); - assertEquals(1, rsp.getHits().getTotalHits()); + assertEquals(1, rsp.getHits().getTotalHits().value); assertEquals(1.0D, rsp.getHits().getAt(0).field("foo").getValue(), 0.0D); } } diff --git a/modules/lang-expression/src/test/resources/rest-api-spec/test/lang_expression/20_search.yml b/modules/lang-expression/src/test/resources/rest-api-spec/test/lang_expression/20_search.yml index 3f26d078bd0..a8850263d40 100644 --- a/modules/lang-expression/src/test/resources/rest-api-spec/test/lang_expression/20_search.yml +++ b/modules/lang-expression/src/test/resources/rest-api-spec/test/lang_expression/20_search.yml @@ -22,6 +22,15 @@ setup: --- "Expressions scripting test": - - do: { search: { body: { script_fields : { my_field : { script: { lang: expression, source: 'doc["age"].value + 19' } } } } } } + - do: + search: + rest_total_hits_as_int: true + body: + script_fields: + my_field : + script: + lang: expression + source: 'doc["age"].value + 19' + - match: { hits.hits.0.fields.my_field.0: 42.0 } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java index 7091c520ddb..ff63d25c794 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java @@ -42,7 +42,6 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestMultiSearchTemplateAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestMultiSearchAction.class)); - private static final Set RESPONSE_PARAMS; static { @@ -52,6 +51,7 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler { RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams); } + private final boolean allowExplicitIndex; public RestMultiSearchTemplateAction(Settings settings, RestController controller) { diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java index b352f4aadb0..7cb346ba8a5 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java @@ -39,13 +39,11 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestSearchTemplateAction extends BaseRestHandler { - + public static final String TYPED_KEYS_PARAM = "typed_keys"; private static final Set RESPONSE_PARAMS; static { - final Set responseParams = new HashSet<>( - Arrays.asList(RestSearchAction.TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HIT_AS_INT_PARAM) - ); + final Set responseParams = new HashSet<>(Arrays.asList(TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HIT_AS_INT_PARAM)); RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams); } diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateResponseTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateResponseTests.java index 53f5d1d8f84..c02c3115501 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateResponseTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateResponseTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.script.mustache; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.common.bytes.BytesReference; @@ -119,7 +120,7 @@ public class SearchTemplateResponseTests extends AbstractXContentTestCase foundIds = new ArrayList<>(); for (SearchHit hit : result.getHits()) { diff --git a/modules/mapper-extras/src/test/resources/rest-api-spec/test/feature/10_basic.yml b/modules/mapper-extras/src/test/resources/rest-api-spec/test/feature/10_basic.yml index 83185508765..b52103822a7 100644 --- a/modules/mapper-extras/src/test/resources/rest-api-spec/test/feature/10_basic.yml +++ b/modules/mapper-extras/src/test/resources/rest-api-spec/test/feature/10_basic.yml @@ -44,6 +44,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: feature: @@ -65,6 +66,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: feature: @@ -86,6 +88,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: feature: @@ -109,6 +112,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: query: feature: @@ -121,6 +125,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: feature: @@ -142,6 +147,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: feature: diff --git a/modules/mapper-extras/src/test/resources/rest-api-spec/test/feature_vector/10_basic.yml b/modules/mapper-extras/src/test/resources/rest-api-spec/test/feature_vector/10_basic.yml index 9cb8fa9c18d..ede0a0eed87 100644 --- a/modules/mapper-extras/src/test/resources/rest-api-spec/test/feature_vector/10_basic.yml +++ b/modules/mapper-extras/src/test/resources/rest-api-spec/test/feature_vector/10_basic.yml @@ -43,6 +43,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: feature: @@ -64,6 +65,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: feature: @@ -85,6 +87,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: feature: diff --git a/modules/mapper-extras/src/test/resources/rest-api-spec/test/scaled_float/10_basic.yml b/modules/mapper-extras/src/test/resources/rest-api-spec/test/scaled_float/10_basic.yml index 6840d8aae20..f40ee53a843 100644 --- a/modules/mapper-extras/src/test/resources/rest-api-spec/test/scaled_float/10_basic.yml +++ b/modules/mapper-extras/src/test/resources/rest-api-spec/test/scaled_float/10_basic.yml @@ -48,6 +48,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "my_terms" : { "terms" : { "field" : "number" } } } } - match: { hits.total: 4 } @@ -77,18 +78,21 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "number" : { "gte" : -2 } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "number" : { "gte" : 0 } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "number" : { "lt" : 1.5 } } } } - match: { hits.total: 2 } @@ -98,6 +102,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 1, "sort" : { "number" : { "order" : "asc" } } } - match: { hits.total: 4 } diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/query/ParentChildInnerHitContextBuilder.java b/modules/parent-join/src/main/java/org/elasticsearch/join/query/ParentChildInnerHitContextBuilder.java index 9e9b55872cf..090798eb51c 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/query/ParentChildInnerHitContextBuilder.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/query/ParentChildInnerHitContextBuilder.java @@ -137,8 +137,10 @@ class ParentChildInnerHitContextBuilder extends InnerHitContextBuilder { intersect(weight, innerHitQueryWeight, totalHitCountCollector, ctx); } result[i] = new TopDocsAndMaxScore( - new TopDocs(new TotalHits(totalHitCountCollector.getTotalHits(), TotalHits.Relation.EQUAL_TO), - Lucene.EMPTY_SCORE_DOCS), Float.NaN); + new TopDocs( + new TotalHits(totalHitCountCollector.getTotalHits(), TotalHits.Relation.EQUAL_TO), + Lucene.EMPTY_SCORE_DOCS + ), Float.NaN); } else { int topN = Math.min(from() + size(), context.searcher().getIndexReader().maxDoc()); TopDocsCollector topDocsCollector; diff --git a/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ChildrenIT.java b/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ChildrenIT.java index 46008451736..3d805d44ade 100644 --- a/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ChildrenIT.java +++ b/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ChildrenIT.java @@ -115,7 +115,7 @@ public class ChildrenIT extends AbstractParentChildTestCase { logger.info("bucket={}", bucket.getKey()); Children childrenBucket = bucket.getAggregations().get("to_comment"); TopHits topHits = childrenBucket.getAggregations().get("top_comments"); - logger.info("total_hits={}", topHits.getHits().getTotalHits()); + logger.info("total_hits={}", topHits.getHits().getTotalHits().value); for (SearchHit searchHit : topHits.getHits()) { logger.info("hit= {} {} {}", searchHit.getSortValues()[0], searchHit.getType(), searchHit.getId()); } @@ -129,7 +129,7 @@ public class ChildrenIT extends AbstractParentChildTestCase { assertThat(childrenBucket.getName(), equalTo("to_comment")); assertThat(childrenBucket.getDocCount(), equalTo(2L)); TopHits topHits = childrenBucket.getAggregations().get("top_comments"); - assertThat(topHits.getHits().getTotalHits(), equalTo(2L)); + assertThat(topHits.getHits().getTotalHits().value, equalTo(2L)); assertThat(topHits.getHits().getAt(0).getId(), equalTo("e")); assertThat(topHits.getHits().getAt(1).getId(), equalTo("f")); @@ -141,7 +141,7 @@ public class ChildrenIT extends AbstractParentChildTestCase { assertThat(childrenBucket.getName(), equalTo("to_comment")); assertThat(childrenBucket.getDocCount(), equalTo(1L)); topHits = childrenBucket.getAggregations().get("top_comments"); - assertThat(topHits.getHits().getTotalHits(), equalTo(1L)); + assertThat(topHits.getHits().getTotalHits().value, equalTo(1L)); assertThat(topHits.getHits().getAt(0).getId(), equalTo("f")); categoryBucket = categoryTerms.getBucketByKey("c"); @@ -152,7 +152,7 @@ public class ChildrenIT extends AbstractParentChildTestCase { assertThat(childrenBucket.getName(), equalTo("to_comment")); assertThat(childrenBucket.getDocCount(), equalTo(1L)); topHits = childrenBucket.getAggregations().get("top_comments"); - assertThat(topHits.getHits().getTotalHits(), equalTo(1L)); + assertThat(topHits.getHits().getTotalHits().value, equalTo(1L)); assertThat(topHits.getHits().getAt(0).getId(), equalTo("f")); } diff --git a/modules/parent-join/src/test/java/org/elasticsearch/join/query/ChildQuerySearchIT.java b/modules/parent-join/src/test/java/org/elasticsearch/join/query/ChildQuerySearchIT.java index 247d8aa7b24..8520b632056 100644 --- a/modules/parent-join/src/test/java/org/elasticsearch/join/query/ChildQuerySearchIT.java +++ b/modules/parent-join/src/test/java/org/elasticsearch/join/query/ChildQuerySearchIT.java @@ -109,7 +109,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .filter(hasChildQuery("grandchild", termQuery("gc_field", "gc_value1"), ScoreMode.None)) , ScoreMode.None))).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1")); searchResponse = client().prepareSearch("test") @@ -117,7 +117,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .filter(hasParentQuery("parent", termQuery("p_field", "p_value1"), false))).execute() .actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("c1")); searchResponse = client().prepareSearch("test") @@ -125,21 +125,21 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .filter(hasParentQuery("child", termQuery("c_field", "c_value1"), false))).execute() .actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("gc1")); searchResponse = client().prepareSearch("test") .setQuery(hasParentQuery("parent", termQuery("p_field", "p_value1"), false)).execute() .actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("c1")); searchResponse = client().prepareSearch("test") .setQuery(hasParentQuery("child", termQuery("c_field", "c_value1"), false)).execute() .actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("gc1")); } @@ -157,7 +157,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { setQuery(hasChildQuery("test", matchQuery("foo", 1), ScoreMode.None)) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); } @@ -181,7 +181,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { searchResponse = client().prepareSearch("test") .setQuery(idsQuery("doc").addIds("c1")).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("c1")); assertThat(extractValue("join_field.name", searchResponse.getHits().getAt(0).getSourceAsMap()), equalTo("child")); assertThat(extractValue("join_field.parent", searchResponse.getHits().getAt(0).getSourceAsMap()), equalTo("p1")); @@ -191,7 +191,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .setQuery(boolQuery().filter(termQuery("join_field#parent", "p1")).filter(termQuery("join_field", "child"))) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getAt(0).getId(), anyOf(equalTo("c1"), equalTo("c2"))); assertThat(extractValue("join_field.name", searchResponse.getHits().getAt(0).getSourceAsMap()), equalTo("child")); assertThat(extractValue("join_field.parent", searchResponse.getHits().getAt(0).getSourceAsMap()), equalTo("p1")); @@ -203,7 +203,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { searchResponse = client().prepareSearch("test").setQuery(randomHasChild("child", "c_field", "yellow")) .get(); assertHitCount(searchResponse, 1L); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1")); searchResponse = client().prepareSearch("test").setQuery(randomHasChild("child", "c_field", "blue")).execute() @@ -309,8 +309,8 @@ public class ChildQuerySearchIT extends ParentChildTestCase { assertNoFailures(searchResponse); Set childIds = parentToChildrenEntry.getValue(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo((long) childIds.size())); - for (int i = 0; i < searchResponse.getHits().getTotalHits(); i++) { + assertThat(searchResponse.getHits().getTotalHits().value, equalTo((long) childIds.size())); + for (int i = 0; i < searchResponse.getHits().getTotalHits().value; i++) { assertThat(childIds.remove(searchResponse.getHits().getAt(i).getId()), is(true)); assertThat(searchResponse.getHits().getAt(i).getScore(), is(1.0f)); } @@ -344,21 +344,21 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .setQuery(hasChildQuery("child", termQuery("c_field", "yellow"), ScoreMode.None)) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1")); searchResponse = client().prepareSearch("test") .setQuery(hasChildQuery("child", termQuery("c_field", "blue"), ScoreMode.None)) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p2")); searchResponse = client().prepareSearch("test") .setQuery(hasChildQuery("child", termQuery("c_field", "red"), ScoreMode.None)) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getAt(0).getId(), anyOf(equalTo("p2"), equalTo("p1"))); assertThat(searchResponse.getHits().getAt(1).getId(), anyOf(equalTo("p2"), equalTo("p1"))); @@ -367,21 +367,21 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .setQuery(constantScoreQuery(hasChildQuery("child", termQuery("c_field", "yellow"), ScoreMode.None))) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1")); searchResponse = client().prepareSearch("test") .setQuery(constantScoreQuery(hasChildQuery("child", termQuery("c_field", "blue"), ScoreMode.None))) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p2")); searchResponse = client().prepareSearch("test") .setQuery(constantScoreQuery(hasChildQuery("child", termQuery("c_field", "red"), ScoreMode.None))) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getAt(0).getId(), anyOf(equalTo("p2"), equalTo("p1"))); assertThat(searchResponse.getHits().getAt(1).getId(), anyOf(equalTo("p2"), equalTo("p1"))); } @@ -412,7 +412,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { boolQuery().should(termQuery("c_field", "red")).should(termQuery("c_field", "yellow"))).subAggregation( AggregationBuilders.terms("facet1").field("c_field")))).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getAt(0).getId(), anyOf(equalTo("p2"), equalTo("p1"))); assertThat(searchResponse.getHits().getAt(1).getId(), anyOf(equalTo("p2"), equalTo("p1"))); @@ -443,7 +443,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { SearchResponse searchResponse = client().prepareSearch("test") .setQuery(constantScoreQuery(hasChildQuery("child", termQuery("c_field", "yellow"), ScoreMode.None))).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1")); assertThat(searchResponse.getHits().getAt(0).getSourceAsString(), containsString("\"p_value1\"")); @@ -455,7 +455,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { searchResponse = client().prepareSearch("test") .setQuery(constantScoreQuery(hasChildQuery("child", termQuery("c_field", "yellow"), ScoreMode.None))).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1")); assertThat(searchResponse.getHits().getAt(0).getSourceAsString(), containsString("\"p_value1_updated\"")); } @@ -501,12 +501,12 @@ public class ChildQuerySearchIT extends ParentChildTestCase { SearchResponse searchResponse = client().prepareSearch("test") .setQuery(boolQuery().must(matchAllQuery()).filter(hasChildQuery("child", matchAllQuery(), ScoreMode.None))).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch("test") .setQuery(boolQuery().must(matchAllQuery()).filter(hasParentQuery("parent", matchAllQuery(), false))).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); } public void testCountApiUsage() throws Exception { @@ -627,7 +627,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { fieldValueFactorFunction("c_field1")) .boostMode(CombineFunction.REPLACE), ScoreMode.Total)).get(); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("1")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(6f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -644,7 +644,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { fieldValueFactorFunction("c_field1")) .boostMode(CombineFunction.REPLACE), ScoreMode.Max)).get(); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("3")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(4f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("2")); @@ -661,7 +661,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { fieldValueFactorFunction("c_field1")) .boostMode(CombineFunction.REPLACE), ScoreMode.Avg)).get(); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("3")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(4f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("2")); @@ -679,7 +679,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .boostMode(CombineFunction.REPLACE), true)) .addSort(SortBuilders.fieldSort("c_field3")).addSort(SortBuilders.scoreSort()).get(); - assertThat(response.getHits().getTotalHits(), equalTo(7L)); + assertThat(response.getHits().getTotalHits().value, equalTo(7L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("16")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(5f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("17")); @@ -705,7 +705,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { SearchResponse response = client().prepareSearch("test") .setQuery(hasChildQuery("child", matchQuery("text", "value"), ScoreMode.None)).get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); client().prepareIndex("test", "doc").setSource(jsonBuilder().startObject().field("text", "value").endObject()) .setRefreshPolicy(RefreshPolicy.IMMEDIATE).get(); @@ -713,22 +713,22 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = client().prepareSearch("test") .setQuery(hasChildQuery("child", matchQuery("text", "value"), ScoreMode.None)).get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); response = client().prepareSearch("test").setQuery(hasChildQuery("child", matchQuery("text", "value"), ScoreMode.Max)) .get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); response = client().prepareSearch("test") .setQuery(hasParentQuery("parent", matchQuery("text", "value"), false)).get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); response = client().prepareSearch("test").setQuery(hasParentQuery("parent", matchQuery("text", "value"), true)) .get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); } public void testHasChildAndHasParentFilter_withFilter() throws Exception { @@ -747,14 +747,14 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .setQuery(boolQuery().must(matchAllQuery()).filter(hasChildQuery("child", termQuery("c_field", 1), ScoreMode.None))) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("1")); searchResponse = client().prepareSearch("test") .setQuery(boolQuery().must(matchAllQuery()) .filter(hasParentQuery("parent", termQuery("p_field", 1), false))).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("2")); } @@ -774,7 +774,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .highlightQuery(QueryBuilders.matchQuery("c_field", "bar")))))) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("1")); SearchHit[] searchHits = searchResponse.getHits().getHits()[0].getInnerHits().get("child").getHits(); assertThat(searchHits.length, equalTo(1)); @@ -841,7 +841,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .addSort("p_field", SortOrder.ASC) .setSize(5).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(10L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(10L)); assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("p000")); assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("p001")); assertThat(searchResponse.getHits().getHits()[2].getId(), equalTo("p002")); @@ -852,7 +852,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .setQuery(hasParentQuery("parent", prefixQuery("p_field", "p"), true)).addSort("c_field", SortOrder.ASC) .setSize(5).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(500L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(500L)); assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("c000")); assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("c001")); assertThat(searchResponse.getHits().getHits()[2].getId(), equalTo("c002")); @@ -880,7 +880,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { SearchResponse searchResponse = client().prepareSearch("test") .setQuery(hasChildQuery("child", termQuery("c_field", "yellow"), ScoreMode.Total)).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1")); assertThat(searchResponse.getHits().getAt(0).getSourceAsString(), containsString("\"p_value1\"")); @@ -890,7 +890,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { boolQuery().must(matchQuery("c_field", "x")).must( hasParentQuery("parent", termQuery("p_field", "p_value2"), true))).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("c3")); assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("c4")); @@ -907,7 +907,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .setQuery(hasChildQuery("child", termQuery("c_field", "yellow"), ScoreMode.Total)) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1")); assertThat(searchResponse.getHits().getAt(0).getSourceAsString(), containsString("\"p_value1\"")); @@ -917,7 +917,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { boolQuery().must(matchQuery("c_field", "x")).must( hasParentQuery("parent", termQuery("p_field", "p_value2"), true))).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getAt(0).getId(), Matchers.anyOf(equalTo("c3"), equalTo("c4"))); assertThat(searchResponse.getHits().getAt(1).getId(), Matchers.anyOf(equalTo("c3"), equalTo("c4"))); } @@ -942,7 +942,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .setMinScore(3) // Score needs to be 3 or above! .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p2")); assertThat(searchResponse.getHits().getAt(0).getScore(), equalTo(3.0f)); } @@ -1027,7 +1027,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .setQuery(constantScoreQuery(hasChildQuery("child", termQuery("c_field", "blue"), ScoreMode.None))) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); createIndexRequest("test", "child", "c2", "p2", "c_field", "blue").get(); client().admin().indices().prepareRefresh("test").get(); @@ -1036,7 +1036,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .setQuery(constantScoreQuery(hasChildQuery("child", termQuery("c_field", "blue"), ScoreMode.None))) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); } private QueryBuilder randomHasChild(String type, String field, String value) { @@ -1150,14 +1150,14 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .filter(boolQuery().mustNot(termQuery("p_field", "3")))) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch("test") .setQuery(boolQuery().must(hasChildQuery("child", termQuery("c_field", "red"), scoreMode)) .filter(boolQuery().mustNot(termQuery("p_field", "3")))) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); } public void testNamedFilters() throws Exception { @@ -1283,7 +1283,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .must(hasChildQuery("child", matchQuery("c_field", "red"), ScoreMode.None)) .must(matchAllQuery()))) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); } @@ -1296,7 +1296,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .must(matchAllQuery()))) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); } public void testParentChildQueriesViaScrollApi() throws Exception { @@ -1327,10 +1327,10 @@ public class ChildQuerySearchIT extends ParentChildTestCase { .actionGet(); assertNoFailures(scrollResponse); - assertThat(scrollResponse.getHits().getTotalHits(), equalTo(10L)); + assertThat(scrollResponse.getHits().getTotalHits().value, equalTo(10L)); int scannedDocs = 0; do { - assertThat(scrollResponse.getHits().getTotalHits(), equalTo(10L)); + assertThat(scrollResponse.getHits().getTotalHits().value, equalTo(10L)); scannedDocs += scrollResponse.getHits().getHits().length; scrollResponse = client() .prepareSearchScroll(scrollResponse.getScrollId()) @@ -1398,7 +1398,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { // Score mode = NONE response = minMaxQuery(ScoreMode.None, 0, null); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("2")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(1f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1408,7 +1408,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.None, 1, null); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("2")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(1f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1418,7 +1418,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.None, 2, null); - assertThat(response.getHits().getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("3")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(1f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("4")); @@ -1426,17 +1426,17 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.None, 3, null); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(1f)); response = minMaxQuery(ScoreMode.None, 4, null); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); response = minMaxQuery(ScoreMode.None, 0, 4); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("2")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(1f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1446,7 +1446,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.None, 0, 3); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("2")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(1f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1456,7 +1456,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.None, 0, 2); - assertThat(response.getHits().getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("2")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(1f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1464,7 +1464,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.None, 2, 2); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("3")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(1f)); @@ -1474,7 +1474,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { // Score mode = SUM response = minMaxQuery(ScoreMode.Total, 0, null); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(6f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1484,7 +1484,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Total, 1, null); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(6f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1494,7 +1494,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Total, 2, null); - assertThat(response.getHits().getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(6f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1502,17 +1502,17 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Total, 3, null); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(6f)); response = minMaxQuery(ScoreMode.Total, 4, null); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); response = minMaxQuery(ScoreMode.Total, 0, 4); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(6f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1522,7 +1522,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Total, 0, 3); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(6f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1532,7 +1532,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Total, 0, 2); - assertThat(response.getHits().getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("3")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(3f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("2")); @@ -1540,7 +1540,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Total, 2, 2); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("3")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(3f)); @@ -1550,7 +1550,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { // Score mode = MAX response = minMaxQuery(ScoreMode.Max, 0, null); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(3f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1560,7 +1560,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Max, 1, null); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(3f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1570,7 +1570,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Max, 2, null); - assertThat(response.getHits().getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(3f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1578,17 +1578,17 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Max, 3, null); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(3f)); response = minMaxQuery(ScoreMode.Max, 4, null); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); response = minMaxQuery(ScoreMode.Max, 0, 4); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(3f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1598,7 +1598,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Max, 0, 3); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(3f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1608,7 +1608,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Max, 0, 2); - assertThat(response.getHits().getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("3")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(2f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("2")); @@ -1616,7 +1616,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Max, 2, 2); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("3")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(2f)); @@ -1626,7 +1626,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { // Score mode = AVG response = minMaxQuery(ScoreMode.Avg, 0, null); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(2f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1636,7 +1636,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Avg, 1, null); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(2f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1646,7 +1646,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Avg, 2, null); - assertThat(response.getHits().getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(2f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1654,17 +1654,17 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Avg, 3, null); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(2f)); response = minMaxQuery(ScoreMode.Avg, 4, null); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); response = minMaxQuery(ScoreMode.Avg, 0, 4); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(2f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1674,7 +1674,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Avg, 0, 3); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("4")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(2f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("3")); @@ -1684,7 +1684,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Avg, 0, 2); - assertThat(response.getHits().getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("3")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(1.5f)); assertThat(response.getHits().getHits()[1].getId(), equalTo("2")); @@ -1692,7 +1692,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { response = minMaxQuery(ScoreMode.Avg, 2, 2); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getHits()[0].getId(), equalTo("3")); assertThat(response.getHits().getHits()[0].getScore(), equalTo(1.5f)); diff --git a/modules/parent-join/src/test/java/org/elasticsearch/join/query/InnerHitsIT.java b/modules/parent-join/src/test/java/org/elasticsearch/join/query/InnerHitsIT.java index 57415d47f6e..7a8d2cd9dbc 100644 --- a/modules/parent-join/src/test/java/org/elasticsearch/join/query/InnerHitsIT.java +++ b/modules/parent-join/src/test/java/org/elasticsearch/join/query/InnerHitsIT.java @@ -126,7 +126,7 @@ public class InnerHitsIT extends ParentChildTestCase { assertThat(response.getHits().getAt(0).getInnerHits().size(), equalTo(1)); SearchHits innerHits = response.getHits().getAt(0).getInnerHits().get("comment"); - assertThat(innerHits.getTotalHits(), equalTo(2L)); + assertThat(innerHits.getTotalHits().value, equalTo(2L)); assertThat(innerHits.getAt(0).getId(), equalTo("c1")); assertThat(innerHits.getAt(0).getType(), equalTo("doc")); @@ -143,7 +143,7 @@ public class InnerHitsIT extends ParentChildTestCase { assertThat(response.getHits().getAt(0).getInnerHits().size(), equalTo(1)); innerHits = response.getHits().getAt(0).getInnerHits().get("comment"); - assertThat(innerHits.getTotalHits(), equalTo(3L)); + assertThat(innerHits.getTotalHits().value, equalTo(3L)); assertThat(innerHits.getAt(0).getId(), equalTo("c4")); assertThat(innerHits.getAt(0).getType(), equalTo("doc")); @@ -233,7 +233,7 @@ public class InnerHitsIT extends ParentChildTestCase { assertThat(searchHit.getShard(), notNullValue()); SearchHits inner = searchHit.getInnerHits().get("a"); - assertThat(inner.getTotalHits(), equalTo((long) child1InnerObjects[parent])); + assertThat(inner.getTotalHits().value, equalTo((long) child1InnerObjects[parent])); for (int child = 0; child < child1InnerObjects[parent] && child < size; child++) { SearchHit innerHit = inner.getAt(child); assertThat(innerHit.getType(), equalTo("doc")); @@ -244,7 +244,7 @@ public class InnerHitsIT extends ParentChildTestCase { offset1 += child1InnerObjects[parent]; inner = searchHit.getInnerHits().get("b"); - assertThat(inner.getTotalHits(), equalTo((long) child2InnerObjects[parent])); + assertThat(inner.getTotalHits().value, equalTo((long) child2InnerObjects[parent])); for (int child = 0; child < child2InnerObjects[parent] && child < size; child++) { SearchHit innerHit = inner.getAt(child); assertThat(innerHit.getType(), equalTo("doc")); @@ -283,14 +283,14 @@ public class InnerHitsIT extends ParentChildTestCase { SearchHit searchHit = response.getHits().getAt(0); assertThat(searchHit.getId(), equalTo("3")); assertThat(searchHit.getType(), equalTo("doc")); - assertThat(searchHit.getInnerHits().get("question").getTotalHits(), equalTo(1L)); + assertThat(searchHit.getInnerHits().get("question").getTotalHits().value, equalTo(1L)); assertThat(searchHit.getInnerHits().get("question").getAt(0).getType(), equalTo("doc")); assertThat(searchHit.getInnerHits().get("question").getAt(0).getId(), equalTo("1")); searchHit = response.getHits().getAt(1); assertThat(searchHit.getId(), equalTo("4")); assertThat(searchHit.getType(), equalTo("doc")); - assertThat(searchHit.getInnerHits().get("question").getTotalHits(), equalTo(1L)); + assertThat(searchHit.getInnerHits().get("question").getTotalHits().value, equalTo(1L)); assertThat(searchHit.getInnerHits().get("question").getAt(0).getType(), equalTo("doc")); assertThat(searchHit.getInnerHits().get("question").getAt(0).getId(), equalTo("2")); } @@ -322,12 +322,12 @@ public class InnerHitsIT extends ParentChildTestCase { assertThat(response.getHits().getAt(0).getInnerHits().size(), equalTo(1)); SearchHits innerHits = response.getHits().getAt(0).getInnerHits().get("comment"); - assertThat(innerHits.getTotalHits(), equalTo(1L)); + assertThat(innerHits.getTotalHits().value, equalTo(1L)); assertThat(innerHits.getAt(0).getId(), equalTo("3")); assertThat(innerHits.getAt(0).getType(), equalTo("doc")); innerHits = innerHits.getAt(0).getInnerHits().get("remark"); - assertThat(innerHits.getTotalHits(), equalTo(1L)); + assertThat(innerHits.getTotalHits().value, equalTo(1L)); assertThat(innerHits.getAt(0).getId(), equalTo("5")); assertThat(innerHits.getAt(0).getType(), equalTo("doc")); @@ -343,12 +343,12 @@ public class InnerHitsIT extends ParentChildTestCase { assertThat(response.getHits().getAt(0).getInnerHits().size(), equalTo(1)); innerHits = response.getHits().getAt(0).getInnerHits().get("comment"); - assertThat(innerHits.getTotalHits(), equalTo(1L)); + assertThat(innerHits.getTotalHits().value, equalTo(1L)); assertThat(innerHits.getAt(0).getId(), equalTo("4")); assertThat(innerHits.getAt(0).getType(), equalTo("doc")); innerHits = innerHits.getAt(0).getInnerHits().get("remark"); - assertThat(innerHits.getTotalHits(), equalTo(1L)); + assertThat(innerHits.getTotalHits().value, equalTo(1L)); assertThat(innerHits.getAt(0).getId(), equalTo("6")); assertThat(innerHits.getAt(0).getType(), equalTo("doc")); } @@ -391,34 +391,34 @@ public class InnerHitsIT extends ParentChildTestCase { assertThat(response.getHits().getAt(0).getId(), equalTo("duke")); SearchHits innerHits = response.getHits().getAt(0).getInnerHits().get("earls"); - assertThat(innerHits.getTotalHits(), equalTo(4L)); + assertThat(innerHits.getTotalHits().value, equalTo(4L)); assertThat(innerHits.getAt(0).getId(), equalTo("earl1")); assertThat(innerHits.getAt(1).getId(), equalTo("earl2")); assertThat(innerHits.getAt(2).getId(), equalTo("earl3")); assertThat(innerHits.getAt(3).getId(), equalTo("earl4")); SearchHits innerInnerHits = innerHits.getAt(0).getInnerHits().get("barons"); - assertThat(innerInnerHits.getTotalHits(), equalTo(1L)); + assertThat(innerInnerHits.getTotalHits().value, equalTo(1L)); assertThat(innerInnerHits.getAt(0).getId(), equalTo("baron1")); innerInnerHits = innerHits.getAt(1).getInnerHits().get("barons"); - assertThat(innerInnerHits.getTotalHits(), equalTo(1L)); + assertThat(innerInnerHits.getTotalHits().value, equalTo(1L)); assertThat(innerInnerHits.getAt(0).getId(), equalTo("baron2")); innerInnerHits = innerHits.getAt(2).getInnerHits().get("barons"); - assertThat(innerInnerHits.getTotalHits(), equalTo(1L)); + assertThat(innerInnerHits.getTotalHits().value, equalTo(1L)); assertThat(innerInnerHits.getAt(0).getId(), equalTo("baron3")); innerInnerHits = innerHits.getAt(3).getInnerHits().get("barons"); - assertThat(innerInnerHits.getTotalHits(), equalTo(1L)); + assertThat(innerInnerHits.getTotalHits().value, equalTo(1L)); assertThat(innerInnerHits.getAt(0).getId(), equalTo("baron4")); innerHits = response.getHits().getAt(0).getInnerHits().get("princes"); - assertThat(innerHits.getTotalHits(), equalTo(1L)); + assertThat(innerHits.getTotalHits().value, equalTo(1L)); assertThat(innerHits.getAt(0).getId(), equalTo("prince")); innerInnerHits = innerHits.getAt(0).getInnerHits().get("kings"); - assertThat(innerInnerHits.getTotalHits(), equalTo(1L)); + assertThat(innerInnerHits.getTotalHits().value, equalTo(1L)); assertThat(innerInnerHits.getAt(0).getId(), equalTo("king")); } @@ -440,12 +440,12 @@ public class InnerHitsIT extends ParentChildTestCase { .get(); assertHitCount(response, 2); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); - assertThat(response.getHits().getAt(0).getInnerHits().get("child").getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getAt(0).getInnerHits().get("child").getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getInnerHits().get("child").getAt(0).getMatchedQueries().length, equalTo(1)); assertThat(response.getHits().getAt(0).getInnerHits().get("child").getAt(0).getMatchedQueries()[0], equalTo("_name1")); assertThat(response.getHits().getAt(1).getId(), equalTo("2")); - assertThat(response.getHits().getAt(1).getInnerHits().get("child").getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getAt(1).getInnerHits().get("child").getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(1).getInnerHits().get("child").getAt(0).getMatchedQueries().length, equalTo(1)); assertThat(response.getHits().getAt(1).getInnerHits().get("child").getAt(0).getMatchedQueries()[0], equalTo("_name1")); @@ -457,7 +457,7 @@ public class InnerHitsIT extends ParentChildTestCase { .get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); - assertThat(response.getHits().getAt(0).getInnerHits().get("child").getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getAt(0).getInnerHits().get("child").getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getInnerHits().get("child").getAt(0).getMatchedQueries().length, equalTo(1)); assertThat(response.getHits().getAt(0).getInnerHits().get("child").getAt(0).getMatchedQueries()[0], equalTo("_name2")); } diff --git a/modules/parent-join/src/test/resources/rest-api-spec/test/11_parent_child.yml b/modules/parent-join/src/test/resources/rest-api-spec/test/11_parent_child.yml index 3936e03f9b0..7273ac6a95d 100644 --- a/modules/parent-join/src/test/resources/rest-api-spec/test/11_parent_child.yml +++ b/modules/parent-join/src/test/resources/rest-api-spec/test/11_parent_child.yml @@ -33,6 +33,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "query" : { "has_child" : { "type" : "child", "query" : { "match_all" : {} }, "inner_hits" : {} } } } - match: { hits.total: 1 } - match: { hits.hits.0._index: "test" } diff --git a/modules/parent-join/src/test/resources/rest-api-spec/test/20_parent_join.yml b/modules/parent-join/src/test/resources/rest-api-spec/test/20_parent_join.yml index d0e36dfd360..66f9c1f1869 100644 --- a/modules/parent-join/src/test/resources/rest-api-spec/test/20_parent_join.yml +++ b/modules/parent-join/src/test/resources/rest-api-spec/test/20_parent_join.yml @@ -61,6 +61,7 @@ setup: "Test basic": - do: search: + rest_total_hits_as_int: true body: { sort: ["join_field", "_id"] } - match: { hits.total: 6 } @@ -102,6 +103,7 @@ setup: "Test parent_id query": - do: search: + rest_total_hits_as_int: true body: sort: [ "_id" ] query: diff --git a/modules/percolator/src/test/resources/rest-api-spec/test/10_basic.yml b/modules/percolator/src/test/resources/rest-api-spec/test/10_basic.yml index cdb88f7da51..9dbe3dfe0d1 100644 --- a/modules/percolator/src/test/resources/rest-api-spec/test/10_basic.yml +++ b/modules/percolator/src/test/resources/rest-api-spec/test/10_basic.yml @@ -26,6 +26,7 @@ - do: search: + rest_total_hits_as_int: true body: - query: percolate: @@ -36,6 +37,7 @@ - do: msearch: + rest_total_hits_as_int: true body: - index: queries_index - query: diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteResponseParsers.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteResponseParsers.java index 30f598f8f70..c7e814237d6 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteResponseParsers.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteResponseParsers.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.reindex.remote; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.Version; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.index.reindex.ScrollableHitSource.BasicHit; @@ -36,6 +37,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.search.SearchHits; import java.io.IOException; import java.util.List; @@ -108,7 +110,16 @@ final class RemoteResponseParsers { public static final ConstructingObjectParser HITS_PARSER = new ConstructingObjectParser<>("hits", true, a -> a); static { - HITS_PARSER.declareLong(constructorArg(), new ParseField("total")); + HITS_PARSER.declareField(constructorArg(), (p, c) -> { + if (p.currentToken() == XContentParser.Token.START_OBJECT) { + final TotalHits totalHits = SearchHits.parseTotalHitsFragment(p); + assert totalHits.relation == TotalHits.Relation.EQUAL_TO; + return totalHits.value; + } else { + // For BWC with nodes pre 7.0 + return p.longValue(); + } + }, new ParseField("total"), ValueType.OBJECT_OR_LONG); HITS_PARSER.declareObjectArray(constructorArg(), HIT_PARSER, new ParseField("hits")); } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java index b4199293f79..e6aee3596b1 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.reindex; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; @@ -463,7 +464,7 @@ public class AsyncBulkByScrollActionTests extends ESTestCase { // Now we can simulate a response and check the delay that we used for the task SearchHit hit = new SearchHit(0, "id", new Text("type"), emptyMap()); - SearchHits hits = new SearchHits(new SearchHit[] { hit }, 0, 0); + SearchHits hits = new SearchHits(new SearchHit[] { hit }, new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0); InternalSearchResponse internalResponse = new InternalSearchResponse(hits, null, null, null, false, false, 1); SearchResponse searchResponse = new SearchResponse(internalResponse, scrollId(), 5, 4, 0, randomLong(), null, SearchResponse.Clusters.EMPTY); diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java index 408c5fb0f4c..5bef735be5e 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java @@ -162,7 +162,7 @@ public class DeleteByQueryBasicTests extends ReindexTestCase { String routing = String.valueOf(randomIntBetween(2, docs)); logger.info("--> counting documents with routing [{}]", routing); - long expected = client().prepareSearch().setSize(0).setRouting(routing).get().getHits().getTotalHits(); + long expected = client().prepareSearch().setSize(0).setRouting(routing).get().getHits().getTotalHits().value; logger.info("--> delete all documents with routing [{}] with a delete-by-query", routing); DeleteByQueryRequestBuilder delete = deleteByQuery().source("test").filter(QueryBuilders.matchAllQuery()); diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/80_slices.yml b/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/80_slices.yml index 6e911e3f1ba..2f40d6bfd3e 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/80_slices.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/80_slices.yml @@ -162,6 +162,7 @@ indices.refresh: {} - do: search: + rest_total_hits_as_int: true index: .tasks - match: { hits.total: 1 } @@ -275,6 +276,7 @@ indices.refresh: {} - do: search: + rest_total_hits_as_int: true index: .tasks - match: { hits.total: 1 } diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml index 0cfb1355008..61ae775b208 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml @@ -29,6 +29,7 @@ - do: search: + rest_total_hits_as_int: true index: target - match: { hits.total: 1 } @@ -62,11 +63,13 @@ - do: search: + rest_total_hits_as_int: true index: target - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: target q: order:1 - match: { hits.total: 1 } diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/40_versioning.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/40_versioning.yml index 7a06ea082aa..4a53814b982 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/40_versioning.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/40_versioning.yml @@ -38,11 +38,13 @@ - do: search: + rest_total_hits_as_int: true index: dest q: company:cat - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: dest q: company:cow - match: { hits.total: 1 } @@ -85,11 +87,13 @@ - do: search: + rest_total_hits_as_int: true index: dest q: company:dog - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: dest q: company:cow - match: { hits.total: 1 } @@ -131,11 +135,13 @@ - do: search: + rest_total_hits_as_int: true index: dest q: company:cat - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: dest q: company:cow - match: { hits.total: 1 } @@ -175,11 +181,13 @@ - do: search: + rest_total_hits_as_int: true index: dest q: company:cat - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: dest q: company:cow - match: { hits.total: 1 } diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/80_slices.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/80_slices.yml index fb06018d7c0..7c4d24d917f 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/80_slices.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/80_slices.yml @@ -171,6 +171,7 @@ indices.refresh: {} - do: search: + rest_total_hits_as_int: true index: .tasks - match: { hits.total: 1 } @@ -288,6 +289,7 @@ indices.refresh: {} - do: search: + rest_total_hits_as_int: true index: .tasks - match: { hits.total: 1 } diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/85_scripting.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/85_scripting.yml index 901f24f022c..1d380aa888e 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/85_scripting.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/85_scripting.yml @@ -25,6 +25,7 @@ - do: search: + rest_total_hits_as_int: true index: new_twitter body: query: @@ -65,6 +66,7 @@ - do: search: + rest_total_hits_as_int: true index: new_twitter body: query: @@ -74,6 +76,7 @@ - do: search: + rest_total_hits_as_int: true index: new_twitter body: query: @@ -161,6 +164,7 @@ - do: search: + rest_total_hits_as_int: true index: new_twitter body: query: @@ -170,6 +174,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -255,6 +260,7 @@ - do: search: + rest_total_hits_as_int: true index: new_twitter body: query: @@ -295,6 +301,7 @@ - do: search: + rest_total_hits_as_int: true index: new_twitter body: query: @@ -335,6 +342,7 @@ - do: search: + rest_total_hits_as_int: true index: other_new_twitter body: query: @@ -344,6 +352,7 @@ - do: search: + rest_total_hits_as_int: true index: new_twitter body: query: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml index 32de51d022a..8b8841fee78 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml @@ -39,6 +39,7 @@ - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -96,6 +97,7 @@ - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -143,6 +145,7 @@ - do: search: + rest_total_hits_as_int: true index: dest routing: foo body: @@ -204,6 +207,7 @@ - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -267,6 +271,7 @@ - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -455,6 +460,7 @@ - do: search: + rest_total_hits_as_int: true index: dest body: query: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/95_parent_join.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/95_parent_join.yml index 4fee2090e78..24f263c4210 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/95_parent_join.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/95_parent_join.yml @@ -58,6 +58,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -69,6 +70,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -114,6 +116,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -125,6 +128,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: dest body: query: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/30_new_fields.yml b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/30_new_fields.yml index 65206b9fd44..201410d6822 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/30_new_fields.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/30_new_fields.yml @@ -31,6 +31,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -46,6 +47,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/70_slices.yml b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/70_slices.yml index dbb79f87037..709e08854b2 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/70_slices.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/70_slices.yml @@ -154,6 +154,7 @@ indices.refresh: {} - do: search: + rest_total_hits_as_int: true index: .tasks - match: { hits.total: 1 } @@ -262,6 +263,7 @@ indices.refresh: {} - do: search: + rest_total_hits_as_int: true index: .tasks - match: { hits.total: 1 } diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/80_scripting.yml b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/80_scripting.yml index 1a3880f3d15..b30f639591e 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/80_scripting.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/80_scripting.yml @@ -22,6 +22,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -50,6 +51,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -87,6 +89,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -96,6 +99,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -215,6 +219,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -224,6 +229,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -287,6 +293,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -296,6 +303,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -305,6 +313,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -397,6 +406,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -406,6 +416,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: @@ -415,6 +426,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: diff --git a/modules/repository-url/src/test/java/org/elasticsearch/repositories/url/URLSnapshotRestoreTests.java b/modules/repository-url/src/test/java/org/elasticsearch/repositories/url/URLSnapshotRestoreTests.java index 1a006f56bc3..ab9268b0814 100644 --- a/modules/repository-url/src/test/java/org/elasticsearch/repositories/url/URLSnapshotRestoreTests.java +++ b/modules/repository-url/src/test/java/org/elasticsearch/repositories/url/URLSnapshotRestoreTests.java @@ -68,7 +68,7 @@ public class URLSnapshotRestoreTests extends ESIntegTestCase { index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client @@ -112,7 +112,7 @@ public class URLSnapshotRestoreTests extends ESIntegTestCase { .actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> list available shapshots"); GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("url-repo").get(); diff --git a/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/20_search.yml b/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/20_search.yml index 89ef510c72b..d739db2ff72 100644 --- a/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/20_search.yml +++ b/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/20_search.yml @@ -36,6 +36,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_nori/20_search.yml b/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_nori/20_search.yml index 490025dda66..729c5b418e1 100644 --- a/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_nori/20_search.yml +++ b/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_nori/20_search.yml @@ -24,6 +24,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/plugins/analysis-nori/src/test/resources/rest-api-spec/test/analysis_nori/20_search.yml b/plugins/analysis-nori/src/test/resources/rest-api-spec/test/analysis_nori/20_search.yml index cfb0ec5ee94..0f4752ba62a 100644 --- a/plugins/analysis-nori/src/test/resources/rest-api-spec/test/analysis_nori/20_search.yml +++ b/plugins/analysis-nori/src/test/resources/rest-api-spec/test/analysis_nori/20_search.yml @@ -24,6 +24,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/40_search.yml b/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/40_search.yml index 34a5bfa1da1..98e9df0c861 100644 --- a/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/40_search.yml +++ b/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/40_search.yml @@ -36,6 +36,7 @@ - do: search: + rest_total_hits_as_int: true index: phonetic_sample body: query: diff --git a/plugins/analysis-smartcn/src/test/resources/rest-api-spec/test/analysis_smartcn/20_search.yml b/plugins/analysis-smartcn/src/test/resources/rest-api-spec/test/analysis_smartcn/20_search.yml index 87261cd4030..4c343c3a7ec 100644 --- a/plugins/analysis-smartcn/src/test/resources/rest-api-spec/test/analysis_smartcn/20_search.yml +++ b/plugins/analysis-smartcn/src/test/resources/rest-api-spec/test/analysis_smartcn/20_search.yml @@ -24,6 +24,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/20_search.yml b/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/20_search.yml index d22639ab93b..153f3528e7d 100644 --- a/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/20_search.yml +++ b/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/20_search.yml @@ -24,6 +24,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/plugins/analysis-ukrainian/src/test/resources/rest-api-spec/test/analysis_ukrainian/20_search.yml b/plugins/analysis-ukrainian/src/test/resources/rest-api-spec/test/analysis_ukrainian/20_search.yml index c07be73e443..fca9711a855 100644 --- a/plugins/analysis-ukrainian/src/test/resources/rest-api-spec/test/analysis_ukrainian/20_search.yml +++ b/plugins/analysis-ukrainian/src/test/resources/rest-api-spec/test/analysis_ukrainian/20_search.yml @@ -24,6 +24,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/plugins/examples/custom-suggester/src/test/resources/rest-api-spec/test/custom-suggester/20_suggest.yml b/plugins/examples/custom-suggester/src/test/resources/rest-api-spec/test/custom-suggester/20_suggest.yml index bac4e1014ef..8e56a004545 100644 --- a/plugins/examples/custom-suggester/src/test/resources/rest-api-spec/test/custom-suggester/20_suggest.yml +++ b/plugins/examples/custom-suggester/src/test/resources/rest-api-spec/test/custom-suggester/20_suggest.yml @@ -38,6 +38,7 @@ - do: search: + rest_total_hits_as_int: true size: 0 index: test body: diff --git a/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/20_whitelist.yml b/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/20_whitelist.yml index b864edaa2a9..9cd5f781aab 100644 --- a/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/20_whitelist.yml +++ b/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/20_whitelist.yml @@ -12,6 +12,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/30_static.yml b/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/30_static.yml index 1dbaf655bf5..e55fdb45748 100644 --- a/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/30_static.yml +++ b/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/30_static.yml @@ -12,6 +12,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/40_instance.yml b/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/40_instance.yml index 712294baa6d..edad5bc9993 100644 --- a/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/40_instance.yml +++ b/plugins/examples/painless-whitelist/src/test/resources/rest-api-spec/test/painless_whitelist/40_instance.yml @@ -12,6 +12,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -27,6 +28,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/plugins/examples/rescore/src/test/resources/rest-api-spec/test/example-rescore/20_score.yml b/plugins/examples/rescore/src/test/resources/rest-api-spec/test/example-rescore/20_score.yml index ab660b395d0..68710e8b383 100644 --- a/plugins/examples/rescore/src/test/resources/rest-api-spec/test/example-rescore/20_score.yml +++ b/plugins/examples/rescore/src/test/resources/rest-api-spec/test/example-rescore/20_score.yml @@ -27,6 +27,7 @@ setup: "just factor": - do: search: + rest_total_hits_as_int: true index: test body: rescore: @@ -38,6 +39,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: rescore: @@ -52,6 +54,7 @@ setup: "with factor field": - do: search: + rest_total_hits_as_int: true index: test body: rescore: diff --git a/plugins/examples/script-expert-scoring/src/test/resources/rest-api-spec/test/script_expert_scoring/20_score.yml b/plugins/examples/script-expert-scoring/src/test/resources/rest-api-spec/test/script_expert_scoring/20_score.yml index 9347cb343a9..4f0ef22fc84 100644 --- a/plugins/examples/script-expert-scoring/src/test/resources/rest-api-spec/test/script_expert_scoring/20_score.yml +++ b/plugins/examples/script-expert-scoring/src/test/resources/rest-api-spec/test/script_expert_scoring/20_score.yml @@ -31,6 +31,7 @@ setup: "document scoring": - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/plugins/mapper-annotated-text/src/test/resources/rest-api-spec/test/mapper_annotatedtext/10_basic.yml b/plugins/mapper-annotated-text/src/test/resources/rest-api-spec/test/mapper_annotatedtext/10_basic.yml index d55ee0ff15b..461e9a7ec50 100644 --- a/plugins/mapper-annotated-text/src/test/resources/rest-api-spec/test/mapper_annotatedtext/10_basic.yml +++ b/plugins/mapper-annotated-text/src/test/resources/rest-api-spec/test/mapper_annotatedtext/10_basic.yml @@ -33,12 +33,14 @@ - do: search: + rest_total_hits_as_int: true body: { "query" : {"term" : { "entityID" : "entity_3789" } }, "highlight" : { "type" : "annotated", "require_field_match": false, "fields" : { "text" : {} } } } - match: {hits.hits.0.highlight.text.0: "The [quick brown fox](_hit_term=entity_3789&entity_3789) is brown."} - do: search: + rest_total_hits_as_int: true body: { "query" : {"term" : { "text" : "quick" } }, "highlight" : { "type" : "annotated", "require_field_match": false, "fields" : { "text" : {} } } } - match: {hits.hits.0.highlight.text.0: "The [quick](_hit_term=quick) brown fox is brown."} diff --git a/plugins/mapper-murmur3/src/test/resources/rest-api-spec/test/mapper_murmur3/10_basic.yml b/plugins/mapper-murmur3/src/test/resources/rest-api-spec/test/mapper_murmur3/10_basic.yml index 15da53ec32c..d24c3d1eec2 100644 --- a/plugins/mapper-murmur3/src/test/resources/rest-api-spec/test/mapper_murmur3/10_basic.yml +++ b/plugins/mapper-murmur3/src/test/resources/rest-api-spec/test/mapper_murmur3/10_basic.yml @@ -23,6 +23,7 @@ - do: search: + rest_total_hits_as_int: true body: { "aggs": { "foo_count": { "cardinality": { "field": "foo.hash" } } } } - match: { aggregations.foo_count.value: 0 } @@ -60,6 +61,7 @@ - do: search: + rest_total_hits_as_int: true body: { "aggs": { "foo_count": { "cardinality": { "field": "foo.hash" } } } } - match: { aggregations.foo_count.value: 3 } diff --git a/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsTests.java b/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsTests.java index 9a0a590efe8..88454188da5 100644 --- a/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsTests.java +++ b/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsTests.java @@ -212,6 +212,6 @@ public class HdfsTests extends ESSingleNodeTestCase { } private long count(Client client, String index) { - return client.prepareSearch(index).setSize(0).get().getHits().getTotalHits(); + return client.prepareSearch(index).setSize(0).get().getHits().getTotalHits().value; } } diff --git a/plugins/store-smb/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTestCase.java b/plugins/store-smb/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTestCase.java index 3033f6d4008..c632fa184ee 100644 --- a/plugins/store-smb/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTestCase.java +++ b/plugins/store-smb/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTestCase.java @@ -44,6 +44,6 @@ public abstract class AbstractAzureFsTestCase extends ESIntegTestCase { } refresh(); SearchResponse response = client().prepareSearch("test").get(); - assertThat(response.getHits().getTotalHits(), is(nbDocs)); + assertThat(response.getHits().getTotalHits().value, is(nbDocs)); } } diff --git a/qa/ccs-unavailable-clusters/src/test/java/org/elasticsearch/search/CrossClusterSearchUnavailableClusterIT.java b/qa/ccs-unavailable-clusters/src/test/java/org/elasticsearch/search/CrossClusterSearchUnavailableClusterIT.java index 56764d44893..8397646b12f 100644 --- a/qa/ccs-unavailable-clusters/src/test/java/org/elasticsearch/search/CrossClusterSearchUnavailableClusterIT.java +++ b/qa/ccs-unavailable-clusters/src/test/java/org/elasticsearch/search/CrossClusterSearchUnavailableClusterIT.java @@ -143,7 +143,7 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase { { SearchResponse response = restHighLevelClient.search(new SearchRequest("index"), RequestOptions.DEFAULT); assertSame(SearchResponse.Clusters.EMPTY, response.getClusters()); - assertEquals(10, response.getHits().totalHits); + assertEquals(10, response.getHits().getTotalHits().value); assertEquals(10, response.getHits().getHits().length); } { @@ -151,7 +151,7 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase { assertEquals(2, response.getClusters().getTotal()); assertEquals(2, response.getClusters().getSuccessful()); assertEquals(0, response.getClusters().getSkipped()); - assertEquals(10, response.getHits().totalHits); + assertEquals(10, response.getHits().getTotalHits().value); assertEquals(10, response.getHits().getHits().length); } { @@ -159,7 +159,7 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase { assertEquals(1, response.getClusters().getTotal()); assertEquals(1, response.getClusters().getSuccessful()); assertEquals(0, response.getClusters().getSkipped()); - assertEquals(0, response.getHits().totalHits); + assertEquals(0, response.getHits().getTotalHits().value); } { @@ -168,12 +168,12 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase { assertEquals(2, response.getClusters().getTotal()); assertEquals(2, response.getClusters().getSuccessful()); assertEquals(0, response.getClusters().getSkipped()); - assertEquals(10, response.getHits().totalHits); + assertEquals(10, response.getHits().getTotalHits().value); assertEquals(10, response.getHits().getHits().length); String scrollId = response.getScrollId(); SearchResponse scrollResponse = restHighLevelClient.scroll(new SearchScrollRequest(scrollId), RequestOptions.DEFAULT); assertSame(SearchResponse.Clusters.EMPTY, scrollResponse.getClusters()); - assertEquals(10, scrollResponse.getHits().totalHits); + assertEquals(10, scrollResponse.getHits().getTotalHits().value); assertEquals(0, scrollResponse.getHits().getHits().length); } @@ -186,7 +186,7 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase { assertEquals(2, response.getClusters().getTotal()); assertEquals(1, response.getClusters().getSuccessful()); assertEquals(1, response.getClusters().getSkipped()); - assertEquals(10, response.getHits().totalHits); + assertEquals(10, response.getHits().getTotalHits().value); assertEquals(10, response.getHits().getHits().length); } { @@ -194,7 +194,7 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase { assertEquals(1, response.getClusters().getTotal()); assertEquals(0, response.getClusters().getSuccessful()); assertEquals(1, response.getClusters().getSkipped()); - assertEquals(0, response.getHits().totalHits); + assertEquals(0, response.getHits().getTotalHits().value); } { @@ -203,12 +203,12 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase { assertEquals(2, response.getClusters().getTotal()); assertEquals(1, response.getClusters().getSuccessful()); assertEquals(1, response.getClusters().getSkipped()); - assertEquals(10, response.getHits().totalHits); + assertEquals(10, response.getHits().getTotalHits().value); assertEquals(10, response.getHits().getHits().length); String scrollId = response.getScrollId(); SearchResponse scrollResponse = restHighLevelClient.scroll(new SearchScrollRequest(scrollId), RequestOptions.DEFAULT); assertSame(SearchResponse.Clusters.EMPTY, scrollResponse.getClusters()); - assertEquals(10, scrollResponse.getHits().totalHits); + assertEquals(10, scrollResponse.getHits().getTotalHits().value); assertEquals(0, scrollResponse.getHits().getHits().length); } diff --git a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java index d26dc2029f6..ef6ed913854 100644 --- a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java @@ -203,7 +203,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { search.addParameter("preference", "_only_nodes:" + node); Map responseBody = entityAsMap(client().performRequest(search)); assertNoFailures(responseBody); - int hits = (int) XContentMapValues.extractValue("hits.total", responseBody); + int hits = extractTotalHits(responseBody); counts.add(hits); } assertEquals("All nodes should have a consistent number of documents", 1, counts.size()); @@ -268,7 +268,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { // We can read from the alias just like we can read from the index. String aliasName = "%23" + index; // %23 == # Map searchRsp = entityAsMap(client().performRequest(new Request("GET", "/" + aliasName + "/_search"))); - int totalHits = (int) XContentMapValues.extractValue("hits.total", searchRsp); + int totalHits = extractTotalHits(searchRsp); assertEquals(count, totalHits); if (isRunningAgainstOldCluster() == false) { // We can remove the alias. @@ -380,7 +380,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertThat(totalShards, greaterThan(1)); int successfulShards = (int) XContentMapValues.extractValue("_shards.successful", response); assertEquals(totalShards, successfulShards); - int totalHits = (int) XContentMapValues.extractValue("hits.total", response); + int totalHits = extractTotalHits(response); assertEquals(numDocs, totalHits); response = entityAsMap(client().performRequest(new Request("GET", "/" + shrunkenIndex+ "/_search"))); @@ -389,7 +389,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertEquals(1, totalShards); successfulShards = (int) XContentMapValues.extractValue("_shards.successful", response); assertEquals(1, successfulShards); - totalHits = (int) XContentMapValues.extractValue("hits.total", response); + totalHits = extractTotalHits(response); assertEquals(numDocs, totalHits); } @@ -445,7 +445,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertThat(totalShards, greaterThan(1)); int successfulShards = (int) XContentMapValues.extractValue("_shards.successful", response); assertEquals(totalShards, successfulShards); - int totalHits = (int) XContentMapValues.extractValue("hits.total", response); + int totalHits = extractTotalHits(response); assertEquals(numDocs, totalHits); if (isRunningAgainstOldCluster() == false) { @@ -455,7 +455,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertEquals(1, totalShards); successfulShards = (int) XContentMapValues.extractValue("_shards.successful", response); assertEquals(1, successfulShards); - totalHits = (int) XContentMapValues.extractValue("hits.total", response); + totalHits = extractTotalHits(response); assertEquals(numDocs, totalHits); } } @@ -513,7 +513,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertNoFailures(count); int expectedCount = bulkCount + (isRunningAgainstOldCluster() ? 0 : bulkCount); - assertEquals(expectedCount, (int) XContentMapValues.extractValue("hits.total", count)); + assertEquals(expectedCount, extractTotalHits(count)); } void assertBasicSearchWorks(int count) throws IOException { @@ -521,7 +521,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { { Map response = entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search"))); assertNoFailures(response); - int numDocs = (int) XContentMapValues.extractValue("hits.total", response); + int numDocs = extractTotalHits(response); logger.info("Found {} in old index", numDocs); assertEquals(count, numDocs); } @@ -659,11 +659,19 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertEquals(0, failed); } - static void assertTotalHits(int expectedTotalHits, Map response) { - int actualTotalHits = (Integer) XContentMapValues.extractValue("hits.total", response); + void assertTotalHits(int expectedTotalHits, Map response) { + int actualTotalHits = extractTotalHits(response); assertEquals(expectedTotalHits, actualTotalHits); } + int extractTotalHits(Map response) { + if (isRunningAgainstOldCluster() && getOldClusterVersion().before(Version.V_7_0_0)) { + return (Integer) XContentMapValues.extractValue("hits.total", response); + } else { + return (Integer) XContentMapValues.extractValue("hits.total.value", response); + } + } + /** * Tests that a single document survives. Super basic smoke test. */ @@ -752,8 +760,8 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { // Count the documents in the index to make sure we have as many as we put there Request countRequest = new Request("GET", "/" + index + "/_search"); countRequest.addParameter("size", "0"); - String countResponse = toStr(client().performRequest(countRequest)); - assertThat(countResponse, containsString("\"total\":" + count)); + Map countResponse = entityAsMap(client().performRequest(countRequest)); + assertTotalHits(count, countResponse); if (false == isRunningAgainstOldCluster()) { boolean restoredFromTranslog = false; @@ -838,8 +846,8 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { // Count the documents in the index to make sure we have as many as we put there Request countRequest = new Request("GET", "/" + index + "/_search"); countRequest.addParameter("size", "0"); - String countResponse = toStr(client().performRequest(countRequest)); - assertThat(countResponse, containsString("\"total\":" + count)); + Map countResponse = entityAsMap(client().performRequest(countRequest)); + assertTotalHits(count, countResponse); // Stick a routing attribute into to cluster settings so we can see it after the restore Request addRoutingSettings = new Request("PUT", "/_cluster/settings"); @@ -988,8 +996,8 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { // Make sure search finds all documents Request countRequest = new Request("GET", "/restored_" + index + "/_search"); countRequest.addParameter("size", "0"); - String countResponse = toStr(client().performRequest(countRequest)); - assertThat(countResponse, containsString("\"total\":" + count)); + Map countResponse = entityAsMap(client().performRequest(countRequest)); + assertTotalHits(count, countResponse); // Add some extra documents to the index to be sure we can still write to it after restoring it int extras = between(1, 100); @@ -1007,8 +1015,8 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { // Make sure search finds all documents Request countAfterWriteRequest = new Request("GET", "/restored_" + index + "/_search"); countAfterWriteRequest.addParameter("size", "0"); - String countAfterWriteResponse = toStr(client().performRequest(countAfterWriteRequest)); - assertThat(countAfterWriteResponse, containsString("\"total\":" + (count + extras))); + Map countAfterResponse = entityAsMap(client().performRequest(countRequest)); + assertTotalHits(count+extras, countAfterResponse); // Clean up the index for the next iteration client().performRequest(new Request("DELETE", "/restored_*")); diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/10_basic.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/10_basic.yml index e2b15bc0d5d..70afa9bf917 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/10_basic.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/10_basic.yml @@ -27,6 +27,7 @@ - do: search: + rest_total_hits_as_int: true index: test_index,my_remote_cluster:test_index body: aggs: @@ -44,6 +45,7 @@ - do: search: + rest_total_hits_as_int: true index: test_index,my_remote_cluster:test_index body: query: @@ -63,6 +65,7 @@ - do: search: + rest_total_hits_as_int: true index: my_remote_cluster:test_index body: aggs: @@ -79,6 +82,7 @@ - do: search: + rest_total_hits_as_int: true index: test_index body: aggs: @@ -112,6 +116,7 @@ - do: search: + rest_total_hits_as_int: true index: test_remote_cluster:test_index - match: { _shards.total: 3 } @@ -137,6 +142,7 @@ - do: search: + rest_total_hits_as_int: true index: "*:test_index" - match: { _shards.total: 6 } @@ -147,6 +153,7 @@ - do: search: + rest_total_hits_as_int: true index: my_remote_cluster:aliased_test_index - match: { _shards.total: 3 } @@ -159,6 +166,7 @@ - do: search: + rest_total_hits_as_int: true index: my_remote_cluster:aliased_test_index,my_remote_cluster:field_caps_index_1 - match: { _shards.total: 4 } @@ -171,6 +179,7 @@ - do: search: + rest_total_hits_as_int: true index: "my_remote_cluster:single_doc_index" - match: { _shards.total: 1 } diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/20_info.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/20_info.yml index 45cc570ecea..1b0f9830e26 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/20_info.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/20_info.yml @@ -29,6 +29,7 @@ # otherwise the cluster might not have been connected yet. - do: search: + rest_total_hits_as_int: true index: test_remote_cluster:test_index - match: { _shards.total: 3 } diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/40_scroll.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/40_scroll.yml index df266bb1be9..6a7fe3c5356 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/40_scroll.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/40_scroll.yml @@ -3,6 +3,7 @@ - do: search: + rest_total_hits_as_int: true index: my_remote_cluster:test_index size: 4 scroll: 1m @@ -24,6 +25,7 @@ - do: scroll: + rest_total_hits_as_int: true body: { "scroll_id": "$scroll_id", "scroll": "1m"} - is_false: _clusters @@ -33,6 +35,7 @@ - match: {hits.hits.1._source.filter_field: 1 } - do: scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 1m diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml index ac47fe000dd..007f1633f73 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml @@ -3,16 +3,19 @@ - do: catch: "missing" search: + rest_total_hits_as_int: true index: "my_remote_cluster:foo" - do: search: + rest_total_hits_as_int: true index: "my_remote_cluster:fooo*" - match: { _shards.total: 0 } - match: { hits.total: 0 } - do: search: + rest_total_hits_as_int: true index: "*:foo*" - match: { _shards.total: 0 } @@ -20,6 +23,7 @@ - do: search: + rest_total_hits_as_int: true index: "my_remote_cluster:test_index,my_remote_cluster:foo*" body: aggs: @@ -36,6 +40,7 @@ - do: catch: "missing" search: + rest_total_hits_as_int: true index: "my_remote_cluster:test_index,my_remote_cluster:foo" body: aggs: diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/60_tophits.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/60_tophits.yml index 53f50daf693..9d94e7d5abb 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/60_tophits.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/60_tophits.yml @@ -28,6 +28,7 @@ teardown: - '{"f1": "local_cluster", "sort_field": 0}' - do: search: + rest_total_hits_as_int: true index: "single_doc_index,my_remote_cluster:single_doc_index" body: sort: "sort_field" diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/70_skip_shards.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/70_skip_shards.yml index e50b32c5e4b..81c09da54c0 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/70_skip_shards.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/70_skip_shards.yml @@ -26,6 +26,7 @@ # check that we skip the remote shard - do: search: + rest_total_hits_as_int: true index: "skip_shards_index,my_remote_cluster:single_doc_index" pre_filter_shard_size: 1 body: { "size" : 10, "query" : { "range" : { "created_at" : { "gte" : "2016-02-01", "lt": "2018-02-01"} } } } @@ -41,6 +42,7 @@ # check that we skip the local shard - do: search: + rest_total_hits_as_int: true index: "skip_shards_index,my_remote_cluster:single_doc_index" pre_filter_shard_size: 1 body: { "size" : 10, "query" : { "range" : { "created_at" : { "gte" : "2015-02-01", "lt": "2016-02-01"} } } } diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/80_index_name_agg.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/80_index_name_agg.yml index 3e9d67a8cf1..d2fcd6878f8 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/80_index_name_agg.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/80_index_name_agg.yml @@ -29,6 +29,7 @@ teardown: - do: search: + rest_total_hits_as_int: true index: "single_doc_index,my_remote_cluster:single_doc_index" body: sort: "sort_field" diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/remote_cluster/10_basic.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/remote_cluster/10_basic.yml index c2840c1ce98..24dc2532937 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/remote_cluster/10_basic.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/remote_cluster/10_basic.yml @@ -108,6 +108,7 @@ - do: search: + rest_total_hits_as_int: true index: test_index body: aggs: @@ -123,6 +124,7 @@ - do: search: + rest_total_hits_as_int: true index: aliased_test_index - match: { _shards.total: 3 } diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java index 6aba4475a18..1d8872da4f5 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HIT_AS_INT_PARAM; import static org.hamcrest.Matchers.equalTo; /** @@ -157,6 +158,7 @@ public class IndexingIT extends AbstractRollingTestCase { private void assertCount(String index, int count) throws IOException { Request searchTestIndexRequest = new Request("POST", "/" + index + "/_search"); + searchTestIndexRequest.addParameter(TOTAL_HIT_AS_INT_PARAM, "true"); searchTestIndexRequest.addParameter("filter_path", "hits.total"); Response searchTestIndexResponse = client().performRequest(searchTestIndexRequest); assertEquals("{\"hits\":{\"total\":" + count + "}}", diff --git a/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/10_basic.yml b/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/10_basic.yml index 0cce81c8985..f50a3fd9ea4 100644 --- a/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/10_basic.yml +++ b/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/10_basic.yml @@ -2,6 +2,7 @@ "Verify that we can still find things with the template": - do: search_template: + rest_total_hits_as_int: true index: test_search_template body: id: test_search_template @@ -25,6 +26,7 @@ "Use the percolate query in mixed cluster": - do: search: + rest_total_hits_as_int: true index: queries body: query: @@ -37,6 +39,7 @@ - do: search: + rest_total_hits_as_int: true index: queries body: sort: _id @@ -52,6 +55,7 @@ - do: search: + rest_total_hits_as_int: true index: queries body: query: diff --git a/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/10_basic.yml b/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/10_basic.yml index 41ab663597f..ffa9e0ce2a6 100644 --- a/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/10_basic.yml +++ b/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/10_basic.yml @@ -50,6 +50,7 @@ - do: search_template: + rest_total_hits_as_int: true index: test_search_template body: id: test_search_template @@ -120,6 +121,7 @@ - do: search: + rest_total_hits_as_int: true index: queries body: query: @@ -132,6 +134,7 @@ - do: search: + rest_total_hits_as_int: true index: queries body: sort: _id @@ -147,6 +150,7 @@ - do: search: + rest_total_hits_as_int: true index: queries body: sort: _id diff --git a/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml b/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml index 7408b96be11..39c72dfd533 100644 --- a/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml +++ b/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml @@ -2,6 +2,7 @@ "Verify that we can still find things with the template": - do: search_template: + rest_total_hits_as_int: true index: test_search_template body: id: test_search_template @@ -41,6 +42,7 @@ - do: search: + rest_total_hits_as_int: true index: queries body: query: @@ -53,6 +55,7 @@ - do: search: + rest_total_hits_as_int: true index: queries body: sort: _id @@ -69,6 +72,7 @@ - do: search: + rest_total_hits_as_int: true index: queries body: query: @@ -87,6 +91,7 @@ - do: search: + rest_total_hits_as_int: true index: .tasks body: query: diff --git a/qa/smoke-test-client/src/test/java/org/elasticsearch/smoketest/SmokeTestClientIT.java b/qa/smoke-test-client/src/test/java/org/elasticsearch/smoketest/SmokeTestClientIT.java index 2e86ce82221..53753b06b8a 100644 --- a/qa/smoke-test-client/src/test/java/org/elasticsearch/smoketest/SmokeTestClientIT.java +++ b/qa/smoke-test-client/src/test/java/org/elasticsearch/smoketest/SmokeTestClientIT.java @@ -65,7 +65,7 @@ public class SmokeTestClientIT extends ESSmokeClientTestCase { // START SNIPPET: java-doc-search-simple final SearchResponse searchResponse = client.prepareSearch(index).get(); - assertThat(searchResponse.getHits().getTotalHits(), is(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, is(1L)); // END SNIPPET: java-doc-search-simple } diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/30_update_by_query_with_ingest.yml b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/30_update_by_query_with_ingest.yml index faff5bd5b57..a8f1a3fea66 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/30_update_by_query_with_ingest.yml +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/30_update_by_query_with_ingest.yml @@ -34,6 +34,7 @@ - do: search: + rest_total_hits_as_int: true index: twitter body: query: diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/40_reindex_with_ingest.yml b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/40_reindex_with_ingest.yml index c463c7b7e3c..8703eca4a5a 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/40_reindex_with_ingest.yml +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/40_reindex_with_ingest.yml @@ -38,6 +38,7 @@ - do: search: + rest_total_hits_as_int: true index: new_twitter body: query: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/msearch.json b/rest-api-spec/src/main/resources/rest-api-spec/api/msearch.json index 4acc769a97e..13a6005c9a1 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/msearch.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/msearch.json @@ -41,7 +41,7 @@ }, "rest_total_hits_as_int" : { "type" : "boolean", - "description" : "This parameter is ignored in this version. It is used in the next major version to control whether the rest response should render the total.hits as an object or a number", + "description" : "Indicates whether hits.total should be rendered as an integer or an object in the rest search response", "default" : false } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/msearch_template.json b/rest-api-spec/src/main/resources/rest-api-spec/api/msearch_template.json index dd02ed80786..e49cc2083f9 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/msearch_template.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/msearch_template.json @@ -31,7 +31,7 @@ }, "rest_total_hits_as_int" : { "type" : "boolean", - "description" : "This parameter is ignored in this version. It is used in the next major version to control whether the rest response should render the total.hits as an object or a number", + "description" : "Indicates whether hits.total should be rendered as an integer or an object in the rest search response", "default" : false } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/scroll.json b/rest-api-spec/src/main/resources/rest-api-spec/api/scroll.json index f03653fa2f4..fc04caeb808 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/scroll.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/scroll.json @@ -22,7 +22,7 @@ }, "rest_total_hits_as_int" : { "type" : "boolean", - "description" : "This parameter is ignored in this version. It is used in the next major version to control whether the rest response should render the total.hits as an object or a number", + "description" : "Indicates whether hits.total should be rendered as an integer or an object in the rest search response", "default" : false } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/search.json b/rest-api-spec/src/main/resources/rest-api-spec/api/search.json index da9bcb82f3b..5834ca623a9 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/search.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/search.json @@ -185,7 +185,7 @@ }, "rest_total_hits_as_int" : { "type" : "boolean", - "description" : "This parameter is ignored in this version. It is used in the next major version to control whether the rest response should render the total.hits as an object or a number", + "description" : "Indicates whether hits.total should be rendered as an integer or an object in the rest search response", "default" : false } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/search_template.json b/rest-api-spec/src/main/resources/rest-api-spec/api/search_template.json index c5c9770222b..528ee905e7e 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/search_template.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/search_template.json @@ -65,7 +65,7 @@ }, "rest_total_hits_as_int" : { "type" : "boolean", - "description" : "This parameter is ignored in this version. It is used in the next major version to control whether the rest response should render the total.hits as an object or a number", + "description" : "Indicates whether hits.total should be rendered as an integer or an object in the rest search response", "default" : false } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.fielddata/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.fielddata/10_basic.yml index 363ff9b477c..6c57a31de14 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.fielddata/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.fielddata/10_basic.yml @@ -42,6 +42,7 @@ - do: search: + rest_total_hits_as_int: true index: index body: query: { match_all: {} } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/60_refresh.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/60_refresh.yml index e461691ace2..e24bdf42603 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/create/60_refresh.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/60_refresh.yml @@ -17,6 +17,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -34,6 +35,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 2 }} @@ -53,6 +55,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -72,6 +75,7 @@ - do: search: + rest_total_hits_as_int: true index: create_60_refresh_1 body: query: { term: { _id: create_60_refresh_id1 }} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/delete/50_refresh.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/delete/50_refresh.yml index 121959d2d97..22d9a6971f4 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/delete/50_refresh.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/delete/50_refresh.yml @@ -39,6 +39,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { terms: { _id: [1,3] }} @@ -52,6 +53,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { terms: { _id: [1,3] }} @@ -70,6 +72,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { terms: { _id: [1,3] }} @@ -93,6 +96,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -106,6 +110,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -128,6 +133,7 @@ - do: search: + rest_total_hits_as_int: true index: delete_50_refresh_1 body: query: { term: { _id: delete_50_refresh_id1 }} @@ -142,6 +148,7 @@ - do: search: + rest_total_hits_as_int: true index: delete_50_refresh_1 body: query: { term: { _id: delete_50_refresh_id1 }} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/delete/51_refresh_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/delete/51_refresh_with_types.yml index ad27bb68601..a901c1033f7 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/delete/51_refresh_with_types.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/delete/51_refresh_with_types.yml @@ -36,6 +36,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { terms: { _id: [1,3] }} @@ -50,6 +51,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { terms: { _id: [1,3] }} @@ -69,6 +71,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { terms: { _id: [1,3] }} @@ -88,6 +91,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -102,6 +106,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -120,6 +125,7 @@ - do: search: + rest_total_hits_as_int: true index: delete_50_refresh_1 body: query: { term: { _id: delete_50_refresh_id1 }} @@ -135,6 +141,7 @@ - do: search: + rest_total_hits_as_int: true index: delete_50_refresh_1 body: query: { term: { _id: delete_50_refresh_id1 }} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/index/60_refresh.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/index/60_refresh.yml index ec52d0cae89..c991d7d2c30 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/index/60_refresh.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/index/60_refresh.yml @@ -22,6 +22,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -38,6 +39,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 2 }} @@ -61,6 +63,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -84,6 +87,7 @@ - do: search: + rest_total_hits_as_int: true index: index_60_refresh_1 body: query: { term: { _id: index_60_refresh_id1 }} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/index/61_refresh_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/index/61_refresh_with_types.yml index cd78a4e4282..be44cafd430 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/index/61_refresh_with_types.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/index/61_refresh_with_types.yml @@ -18,6 +18,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -35,6 +36,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 2 }} @@ -54,6 +56,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -73,6 +76,7 @@ - do: search: + rest_total_hits_as_int: true index: index_60_refresh_1 body: query: { term: { _id: index_60_refresh_id1 }} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/10_basic.yml index 8b46aec04b2..64e59d59392 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/10_basic.yml @@ -18,6 +18,7 @@ - do: catch: bad_request search: + rest_total_hits_as_int: true index: test_index - do: @@ -30,6 +31,7 @@ - do: search: + rest_total_hits_as_int: true index: test_index --- diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/20_multiple_indices.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/20_multiple_indices.yml index 1aecbcf37d7..8e1bf660f63 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/20_multiple_indices.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/20_multiple_indices.yml @@ -30,6 +30,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true index: test_index2 - do: @@ -42,6 +43,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test_index2 --- @@ -53,6 +55,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true index: test_index2 - do: @@ -65,6 +68,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test_index2 --- @@ -76,6 +80,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true index: test_index3 - do: @@ -88,5 +93,6 @@ setup: - do: search: + rest_total_hits_as_int: true index: test_index3 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yml index 3a2b859a5b7..342adced064 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yml @@ -69,6 +69,7 @@ # check alias points to the new index - do: search: + rest_total_hits_as_int: true index: logs_search - match: { hits.total: 1 } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.sort/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.sort/10_basic.yml index 9281882a70a..b7df22647eb 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.sort/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.sort/10_basic.yml @@ -88,6 +88,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: sort: ["rank"] @@ -99,6 +100,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: sort: ["rank"] @@ -121,6 +123,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: sort: _doc @@ -138,6 +141,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: sort: ["rank"] @@ -154,6 +158,7 @@ - do: catch: /disabling \[track_total_hits\] is not allowed in a scroll context/ search: + rest_total_hits_as_int: true index: test scroll: 1m body: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/13_fields.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/13_fields.yml index 82655c5778d..cb67ef26b82 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/13_fields.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/13_fields.yml @@ -51,6 +51,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test1 body: suggest: @@ -61,6 +62,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test1 body: suggest: @@ -71,6 +73,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: sort: [ "bar", "baz" ] diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/14_groups.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/14_groups.yml index 0ac1409c659..052e243f585 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/14_groups.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/14_groups.yml @@ -10,6 +10,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: stats: [ bar, baz ] diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/10_basic.yml index ee577f6a228..9ad62f09538 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/10_basic.yml @@ -31,6 +31,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/20_docs.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/20_docs.yml index 42b6619a5f8..50eeab8aba4 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/20_docs.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/20_docs.yml @@ -36,6 +36,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/30_unlike.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/30_unlike.yml index f3d641081e8..8f06086732b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/30_unlike.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/30_unlike.yml @@ -36,6 +36,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml index 557492623a8..0d178a389be 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml @@ -37,6 +37,7 @@ setup: - do: msearch: + rest_total_hits_as_int: true body: - index: index_* - query: @@ -67,6 +68,7 @@ setup: # only passing these parameters to make sure they are consumed - do: msearch: + rest_total_hits_as_int: true max_concurrent_shard_requests: 1 max_concurrent_searches: 1 body: @@ -95,14 +97,13 @@ setup: - match: { responses.4.hits.total: 4 } --- -"Search with rest_total_hits_as_int": +"Search with new response format": - skip: - version: " - 6.5.99" - reason: rest_total_hits_as_int was introduced in 6.6.0 + version: " - 6.99.99" + reason: hits.total is returned as an object in 7.0.0 - do: msearch: - rest_total_hits_as_int: true body: - index: index_* - query: @@ -114,7 +115,11 @@ setup: - query: match: {foo: foo} - - match: { responses.0.hits.total: 2 } - - match: { responses.1.hits.total: 1 } - - match: { responses.2.hits.total: 1 } + - match: { responses.0.hits.total.value: 2 } + - match: { responses.0.hits.total.relation: eq } + - match: { responses.1.hits.total.value: 1 } + - match: { responses.1.hits.total.relation: eq } + - match: { responses.2.hits.total.value: 1 } + - match: { responses.2.hits.total.relation: eq } + diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/11_status.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/11_status.yml index 1451edaf5be..d3c1916b2c5 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/11_status.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/11_status.yml @@ -7,6 +7,7 @@ setup: "Check Status": - do: msearch: + rest_total_hits_as_int: true body: - index: test_2 - query: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/12_basic_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/12_basic_with_types.yml index a14423cef11..64e88de404a 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/12_basic_with_types.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/12_basic_with_types.yml @@ -37,6 +37,7 @@ setup: - do: msearch: + rest_total_hits_as_int: true body: - index: index_* - query: @@ -67,6 +68,7 @@ setup: # only passing these parameters to make sure they are consumed - do: msearch: + rest_total_hits_as_int: true max_concurrent_shard_requests: 1 max_concurrent_searches: 1 body: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/20_typed_keys.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/20_typed_keys.yml index 7348cd4d14b..269282e17cd 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/20_typed_keys.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/20_typed_keys.yml @@ -59,6 +59,7 @@ setup: "Multisearch test with typed_keys parameter": - do: msearch: + rest_total_hits_as_int: true typed_keys: true body: # Testing aggegrations @@ -93,6 +94,7 @@ setup: "Multisearch test with typed_keys parameter for sampler and significant terms": - do: msearch: + rest_total_hits_as_int: true typed_keys: true body: - index: test-* diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/range/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/range/10_basic.yml index 56e2e91b4ad..eac9c23704b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/range/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/range/10_basic.yml @@ -57,36 +57,42 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4 } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "query_string" : { "query" : "integer_range:[3 TO 4]" } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } - match: { hits.total: 0 } - do: search: + rest_total_hits_as_int: true body: { "query" : { "match_all": {} } } - match: { hits.total: 4 } @@ -121,30 +127,35 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4 } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "query_string" : { "query" : "long_range:[3 TO 4]" } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } - match: { hits.total: 0 } @@ -179,30 +190,35 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4 } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "query_string" : { "query" : "float_range:[3 TO 4]" } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } - match: { hits.total: 0 } @@ -237,30 +253,35 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4 } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "query_string" : { "query" : "double_range:[3 TO 4]" } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } - match: { hits.total: 0 } @@ -295,30 +316,35 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4" } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "query_string" : { "query" : "ip_range:[192.168.0.3 TO 192.168.0.4]" } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4", "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4", "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4", "relation": "within" } } } } - match: { hits.total: 0 } @@ -353,30 +379,35 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04" } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "query_string" : { "query" : "date_range:[2017-09-03 TO 2017-09-04]" } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04", "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04", "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04", "relation": "within" } } } } - match: { hits.total: 0 } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/10_basic.yml index d4a4e4ee462..3fec62f60e7 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/10_basic.yml @@ -22,6 +22,7 @@ - do: search: + rest_total_hits_as_int: true index: test_scroll size: 1 scroll: 1m @@ -47,6 +48,7 @@ - do: scroll: + rest_total_hits_as_int: true body: { "scroll_id": "$scroll_id", "scroll": "1m"} - match: {hits.total: 2 } @@ -55,6 +57,7 @@ - do: scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 1m @@ -94,6 +97,7 @@ - do: search: + rest_total_hits_as_int: true index: test_scroll size: 1 scroll: 1m @@ -119,6 +123,7 @@ - do: scroll: + rest_total_hits_as_int: true body: { "scroll_id": "$scroll_id", "scroll": "1m"} - match: {hits.total: 2 } @@ -127,6 +132,7 @@ - do: scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 1m @@ -161,6 +167,7 @@ - do: search: + rest_total_hits_as_int: true index: test_scroll size: 1 scroll: 1m @@ -186,6 +193,7 @@ - do: scroll: + rest_total_hits_as_int: true scroll_id: invalid_scroll_id body: { "scroll_id": "$scroll_id", "scroll": "1m"} @@ -208,6 +216,7 @@ - do: catch: /\[request_cache\] cannot be used in a scroll context/ search: + rest_total_hits_as_int: true index: test_scroll scroll: 1m request_cache: true @@ -226,6 +235,7 @@ - do: catch: /\[size\] cannot be \[0\] in a scroll context/ search: + rest_total_hits_as_int: true index: test_scroll scroll: 1m request_cache: true @@ -262,6 +272,7 @@ - do: search: + rest_total_hits_as_int: true index: test_scroll size: 1 scroll: 1m @@ -276,6 +287,7 @@ - do: scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 1m @@ -283,10 +295,10 @@ - match: { hits.max_score: null } --- -"Scroll with rest_total_as_int": +"Scroll with new response format": - skip: - version: " - 6.5.99" - reason: rest_total_hits_as_int was introduced in 6.6.0 + version: " - 6.9.99" + reason: hits.total is returned as an object in 7.0.0 - do: indices.create: index: test_scroll @@ -313,32 +325,32 @@ size: 1 scroll: 1m sort: foo - rest_total_hits_as_int: true body: query: match_all: {} - set: {_scroll_id: scroll_id} - - match: {hits.total: 2 } + - match: {hits.total.value: 2 } + - match: {hits.total.relation: eq } - length: {hits.hits: 1 } - match: {hits.hits.0._id: "42" } - do: scroll: - rest_total_hits_as_int: true body: { "scroll_id": "$scroll_id", "scroll": "1m"} - - match: {hits.total: 2 } + - match: {hits.total.value: 2 } + - match: {hits.total.relation: eq } - length: {hits.hits: 1 } - match: {hits.hits.0._id: "43" } - do: scroll: - rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 1m - - match: {hits.total: 2 } + - match: {hits.total.value: 2 } + - match: {hits.total.relation: eq } - length: {hits.hits: 0 } - do: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/11_clear.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/11_clear.yml index 4368cf790e5..40eb1fb004d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/11_clear.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/11_clear.yml @@ -15,6 +15,7 @@ - do: search: + rest_total_hits_as_int: true index: test_scroll scroll: 1m body: @@ -30,6 +31,7 @@ - do: catch: missing scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id1 - do: @@ -54,6 +56,7 @@ - do: search: + rest_total_hits_as_int: true index: test_scroll scroll: 1m body: @@ -70,6 +73,7 @@ - do: catch: missing scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id1 - do: @@ -94,6 +98,7 @@ - do: search: + rest_total_hits_as_int: true index: test_scroll scroll: 1m body: @@ -110,6 +115,7 @@ - do: catch: missing scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id1 - do: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/12_slices.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/12_slices.yml index 845cbc54bc7..ef5b55ad131 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/12_slices.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/12_slices.yml @@ -43,6 +43,7 @@ setup: "Sliced scroll": - do: search: + rest_total_hits_as_int: true index: test_sliced_scroll scroll: 1m sort: foo @@ -62,6 +63,7 @@ setup: - do: scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 1m @@ -74,6 +76,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test_sliced_scroll scroll: 1m sort: foo @@ -91,6 +94,7 @@ setup: - do: scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 1m @@ -110,6 +114,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true index: test_sliced_scroll size: 1 scroll: 1m @@ -128,6 +133,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test_sliced_scroll size: 1 scroll: 1m diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/20_keep_alive.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/20_keep_alive.yml index 8577835502a..6ebc26e3790 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/20_keep_alive.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/scroll/20_keep_alive.yml @@ -41,6 +41,7 @@ - do: catch: /.*Keep alive for scroll.*is too large.*/ search: + rest_total_hits_as_int: true index: test_scroll size: 1 scroll: 2m @@ -51,6 +52,7 @@ - do: search: + rest_total_hits_as_int: true index: test_scroll size: 1 scroll: 1m @@ -66,5 +68,6 @@ - do: catch: /.*Keep alive for scroll.*is too large.*/ scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 3m diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml index a17bdade656..0cc2918d4c9 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml @@ -53,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_avg: @@ -72,6 +73,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -92,6 +94,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -118,6 +121,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_avg: @@ -134,6 +138,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_avg: @@ -149,6 +154,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_avg: @@ -168,6 +174,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: the_string_avg: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/10_histogram.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/10_histogram.yml index 11aaa93aebf..08d4ea5d6e4 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/10_histogram.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/10_histogram.yml @@ -51,6 +51,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "aggs" : { "histo" : { "histogram" : { "field" : "number", "interval" : 50 } } } } - match: { hits.total: 4 } @@ -116,6 +117,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "aggs" : { "histo" : { "histogram" : { "field" : "number", "interval" : 50, "format" : "Value is ##0.0" } } } } - match: { hits.total: 4 } @@ -186,6 +188,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "aggs" : { "histo" : { "date_histogram" : { "field" : "date", "interval" : "month", "order" : { "_time" : "desc" } } } } } warnings: - "Deprecated aggregation order key [_time] used, replaced by [_key]" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml index 30b0bafe3b0..ff7d4ee6988 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml @@ -53,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_max: @@ -72,6 +73,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -92,6 +94,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -118,6 +121,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_max: @@ -134,6 +138,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_max: @@ -149,6 +154,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_max: @@ -168,6 +174,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: the_string_avg: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml index f56719dfe6e..5b6fb031312 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml @@ -53,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_min: @@ -72,6 +73,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -92,6 +94,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -118,6 +121,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_min: @@ -134,6 +138,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_min: @@ -149,6 +154,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_min: @@ -168,6 +174,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: the_string_min: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml index 9fbb15fdab3..e80d95ca6b5 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml @@ -53,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_sum: @@ -72,6 +73,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -92,6 +94,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -118,6 +121,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_sum: @@ -134,6 +138,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_sum: @@ -149,6 +154,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_sum: @@ -168,6 +174,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: the_string_sum: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/140_value_count_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/140_value_count_metric.yml index 088f81a0db3..6d4d6554b44 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/140_value_count_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/140_value_count_metric.yml @@ -53,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_value_count: @@ -76,6 +77,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -100,6 +102,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -130,6 +133,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_value_count: @@ -146,6 +150,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_value_count: @@ -161,6 +166,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_value_count: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/150_stats_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/150_stats_metric.yml index a27f7225098..ca59de61484 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/150_stats_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/150_stats_metric.yml @@ -53,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_stats: @@ -80,6 +81,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -108,6 +110,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -142,6 +145,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_stats: @@ -162,6 +166,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_stats: @@ -177,6 +182,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_stats: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/160_extended_stats_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/160_extended_stats_metric.yml index 6ad8166a6a8..599b17ff2af 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/160_extended_stats_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/160_extended_stats_metric.yml @@ -53,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_extended_stats: @@ -88,6 +89,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -126,6 +128,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -170,6 +173,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_extended_stats: @@ -195,6 +199,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_missing_extended_stats: @@ -210,6 +215,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_extended_stats: @@ -235,6 +241,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_extended_stats: @@ -273,6 +280,7 @@ setup: - do: catch: /\[sigma\] must be greater than or equal to 0. Found \[-1.0\] in \[the_int_extended_stats\]/ search: + rest_total_hits_as_int: true body: aggs: the_int_extended_stats: @@ -283,6 +291,7 @@ setup: - do: catch: /x_content_parse_exception/ search: + rest_total_hits_as_int: true body: aggs: the_int_extended_stats: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/170_cardinality_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/170_cardinality_metric.yml index f706c5d8640..b493ff609db 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/170_cardinality_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/170_cardinality_metric.yml @@ -53,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: distinct_int: @@ -73,6 +74,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: distinct_int: @@ -99,6 +101,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -123,6 +126,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -153,6 +157,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: distinct_missing: @@ -169,6 +174,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: distinct_missing: @@ -184,6 +190,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: distinct_missing: @@ -203,6 +210,7 @@ setup: - do: catch: /\[precisionThreshold\] must be greater than or equal to 0. Found \[-1\] in \[distinct_int\]/ search: + rest_total_hits_as_int: true body: aggs: distinct_int: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/180_percentiles_tdigest_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/180_percentiles_tdigest_metric.yml index 4413a7a5c7d..2f612ad83d5 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/180_percentiles_tdigest_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/180_percentiles_tdigest_metric.yml @@ -53,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -83,6 +84,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -122,6 +124,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -158,6 +161,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -197,6 +201,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_missing: @@ -220,6 +225,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_missing: @@ -235,6 +241,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -262,6 +269,7 @@ setup: - do: catch: /\[compression\] must be greater than or equal to 0. Found \[-1.0\] in \[percentiles_int\]/ search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -273,6 +281,7 @@ setup: - do: catch: /\[percents\] must not be empty/ search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -283,6 +292,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -293,6 +303,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -303,6 +314,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: percentiles_string: @@ -314,6 +326,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -342,6 +355,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/190_percentiles_hdr_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/190_percentiles_hdr_metric.yml index a8b7f1c6299..8cd758b5f35 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/190_percentiles_hdr_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/190_percentiles_hdr_metric.yml @@ -55,6 +55,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -88,6 +89,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -127,6 +129,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -164,6 +167,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -206,6 +210,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_missing: @@ -230,6 +235,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_missing: @@ -246,6 +252,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -273,6 +280,7 @@ setup: - do: catch: /\[numberOfSignificantValueDigits\] must be between 0 and 5/ search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -284,6 +292,7 @@ setup: - do: catch: /\[numberOfSignificantValueDigits\] must be between 0 and 5/ search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -295,6 +304,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -306,6 +316,7 @@ setup: - do: catch: /\[percents\] must not be empty/ search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -317,6 +328,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -328,6 +340,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -339,6 +352,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: aggs: percentiles_string: @@ -351,6 +365,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -383,6 +398,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: @@ -418,6 +434,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: percentiles_int: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/200_top_hits_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/200_top_hits_metric.yml index 8d53322274b..267a9e85d1d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/200_top_hits_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/200_top_hits_metric.yml @@ -56,6 +56,7 @@ - do: search: + rest_total_hits_as_int: true body: aggs: to-users: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yml index 0086b3c5941..37982421179 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yml @@ -67,6 +67,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str" } } } } - match: { hits.total: 3 } @@ -113,6 +114,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "ip_terms" : { "terms" : { "field" : "ip" } } } } - match: { hits.total: 3 } @@ -133,6 +135,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "ip_terms" : { "terms" : { "field" : "ip", "include" : [ "127.0.0.1" ] } } } } - match: { hits.total: 3 } @@ -143,6 +146,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "ip_terms" : { "terms" : { "field" : "ip", "exclude" : [ "127.0.0.1" ] } } } } - match: { hits.total: 3 } @@ -154,6 +158,7 @@ setup: - do: catch: request search: + rest_total_hits_as_int: true index: test_1 body: { "size" : 0, "aggs" : { "ip_terms" : { "terms" : { "field" : "ip", "exclude" : "127.*" } } } } @@ -187,6 +192,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "boolean_terms" : { "terms" : { "field" : "boolean" } } } } - match: { hits.total: 3 } @@ -233,6 +239,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "integer_terms" : { "terms" : { "field" : "integer" } } } } - match: { hits.total: 3 } @@ -279,6 +286,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "double_terms" : { "terms" : { "field" : "double" } } } } - match: { hits.total: 3 } @@ -325,6 +333,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "date" } } } } - match: { hits.total: 3 } @@ -345,6 +354,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "date", "include" : [ "2016-05-03" ] } } } } - match: { hits.total: 3 } @@ -357,6 +367,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "date", "exclude" : [ "2016-05-03" ] } } } } - match: { hits.total: 3 } @@ -396,6 +407,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str", "include" : {"partition": 0, "num_partitions": 2 } } } } } - match: { hits.total : 3 } @@ -410,6 +422,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str", "include" : {"partition": 1, "num_partitions": 2 } } } } } - match: { hits.total: 3 } @@ -451,6 +464,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "integer", "include" : {"partition": 0, "num_partitions": 2 } } } } } - match: { hits.total: 3 } @@ -463,6 +477,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "integer", "include" : {"partition": 1, "num_partitions": 2 } } } } } - match: { hits.total: 3 } @@ -488,6 +503,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "string_terms" : { "terms" : { "field" : "unmapped_string", "value_type" : "string", "missing": "abc" } } } } - match: { hits.total: 1 } @@ -513,6 +529,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "boolean_terms" : { "terms" : { "field" : "unmapped_boolean", "value_type" : "boolean", "missing": true } } } } - match: { hits.total: 1 } @@ -540,6 +557,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "unmapped_date", "value_type" : "date", "missing": "2016-05-11" } } } } - match: { hits.total: 1 } @@ -567,6 +585,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "long_terms" : { "terms" : { "field" : "unmapped_long", "value_type" : "long", "missing": 3 } } } } - match: { hits.total: 1 } @@ -592,6 +611,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "double_terms" : { "terms" : { "field" : "unmapped_double", "value_type" : "double", "missing": 3.5 } } } } - match: { hits.total: 1 } @@ -645,6 +665,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "number_terms" : { "terms" : { "field" : "number" } } } } - match: { hits.total: 5 } @@ -696,6 +717,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str", "order" : { "_term" : "desc" } } } } } warnings: - "Deprecated aggregation order key [_term] used, replaced by [_key]" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/220_filters_bucket.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/220_filters_bucket.yml index 696a420953d..b7578a9ae6b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/220_filters_bucket.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/220_filters_bucket.yml @@ -53,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_filter: @@ -72,6 +73,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_filter: @@ -100,6 +102,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_filter: @@ -117,6 +120,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_filter: @@ -143,6 +147,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -163,6 +168,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_filter: @@ -191,6 +197,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: constant_score: @@ -226,6 +233,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_filter: @@ -251,6 +259,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_filter: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/230_composite.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/230_composite.yml index 7b29ddd2f03..26c530551a9 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/230_composite.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/230_composite.yml @@ -69,6 +69,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: aggregations: @@ -98,6 +99,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: aggregations: @@ -147,6 +149,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: aggregations: @@ -188,6 +191,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: aggregations: @@ -218,6 +222,7 @@ setup: - do: catch: /\[composite\] aggregation cannot be used with a parent aggregation/ search: + rest_total_hits_as_int: true index: test body: aggregations: @@ -245,6 +250,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: aggregations: @@ -271,6 +277,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: aggregations: @@ -304,6 +311,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: aggregations: @@ -332,6 +340,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: aggregations: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/240_max_buckets.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/240_max_buckets.yml index f8d960e0c25..0a8c951e7af 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/240_max_buckets.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/240_max_buckets.yml @@ -97,6 +97,7 @@ setup: - do: catch: /.*Trying to create too many buckets.*/ search: + rest_total_hits_as_int: true index: test body: aggregations: @@ -108,6 +109,7 @@ setup: - do: catch: /.*Trying to create too many buckets.*/ search: + rest_total_hits_as_int: true index: test body: aggregations: @@ -129,6 +131,7 @@ setup: - do: catch: /.*Trying to create too many buckets.*/ search: + rest_total_hits_as_int: true index: test body: aggregations: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/250_moving_fn.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/250_moving_fn.yml index f5b80509db8..0a7affd276a 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/250_moving_fn.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/250_moving_fn.yml @@ -9,6 +9,7 @@ setup: - do: catch: /\[window\] must be a positive, non-zero integer\./ search: + rest_total_hits_as_int: true body: size: 0 aggs: @@ -32,6 +33,7 @@ setup: - do: catch: /\[window\] must be a positive, non-zero integer\./ search: + rest_total_hits_as_int: true body: size: 0 aggs: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/260_weighted_avg.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/260_weighted_avg.yml index 6f8ea9565e3..5d9e46a67b1 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/260_weighted_avg.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/260_weighted_avg.yml @@ -52,6 +52,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: the_int_avg: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/270_median_absolute_deviation_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/270_median_absolute_deviation_metric.yml index b52027f98c8..ce86adce665 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/270_median_absolute_deviation_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/270_median_absolute_deviation_metric.yml @@ -44,6 +44,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: mad_int: @@ -64,6 +65,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: mad_int: @@ -86,6 +88,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: query: bool: @@ -107,6 +110,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: mad_missing: @@ -125,6 +129,7 @@ setup: - do: catch: /\[compression\] must be greater than 0. Found \[0.0\] in \[mad\]/ search: + rest_total_hits_as_int: true body: aggs: mad: @@ -135,6 +140,7 @@ setup: - do: catch: /\[compression\] must be greater than 0. Found \[-1.0\] in \[mad\]/ search: + rest_total_hits_as_int: true body: aggs: mad: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/30_sig_terms.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/30_sig_terms.yml index fe8c33926d0..39c83727d1b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/30_sig_terms.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/30_sig_terms.yml @@ -66,12 +66,14 @@ - do: search: + rest_total_hits_as_int: true index: goodbad - match: {hits.total: 7} - do: search: + rest_total_hits_as_int: true index: goodbad body: {"aggs": {"class": {"terms": {"field": "class"},"aggs": {"sig_terms": {"significant_terms": {"field": "text"}}}}}} @@ -108,6 +110,7 @@ - do: search: + rest_total_hits_as_int: true body: { "query" : { "exists" : { "field" : "ip" } }, "aggs" : { "ip_terms" : { "significant_terms" : { "field" : "ip", "min_doc_count" : 1 } } } } - match: { hits.total: 1 } @@ -122,6 +125,7 @@ - do: search: + rest_total_hits_as_int: true body: { "query" : { "exists" : { "field" : "ip" } }, "aggs" : { "ip_terms" : { "significant_terms" : { "field" : "ip", "min_doc_count" : 1, "include" : [ "::1" ] } } } } - match: { hits.total: 1 } @@ -132,6 +136,7 @@ - do: search: + rest_total_hits_as_int: true body: { "query" : { "exists" : { "field" : "ip" } }, "aggs" : { "ip_terms" : { "significant_terms" : { "field" : "ip", "min_doc_count" : 1, "exclude" : [ "::1" ] } } } } - match: { hits.total: 1 } @@ -141,6 +146,7 @@ - do: catch: request search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "ip_terms" : { "significant_terms" : { "field" : "ip", "exclude" : "127.*" } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/40_range.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/40_range.yml index c75f4175e6b..21eb7959cf2 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/40_range.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/40_range.yml @@ -48,6 +48,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "double_range" : { "range" : { "field" : "double", "ranges": [ { "to": 50 }, { "from": 50, "to": 150 }, { "from": 150 } ] } } } } - match: { hits.total: 3 } @@ -80,6 +81,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "double_range" : { "range" : { "field" : "double", "ranges": [ { "from": null, "to": 50 }, { "from": 50, "to": 150 }, { "from": 150, "to": null } ] } } } } - match: { hits.total: 3 } @@ -138,6 +140,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "ip_range" : { "ip_range" : { "field" : "ip", "ranges": [ { "to": "192.168.0.0" }, { "from": "192.168.0.0", "to": "192.169.0.0" }, { "from": "192.169.0.0" } ] } } } } - match: { hits.total: 3 } @@ -164,6 +167,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "ip_range" : { "ip_range" : { "field" : "ip", "ranges": [ { "from": null, "to": "192.168.0.0" }, { "from": "192.168.0.0", "to": "192.169.0.0" }, { "from": "192.169.0.0", "to": null } ] } } } } - match: { hits.total: 3 } @@ -190,6 +194,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "ip_range" : { "ip_range" : { "field" : "ip", "ranges": [ { "mask": "::/24" }, { "mask": "192.168.0.0/16" } ] } } } } - match: { hits.total: 3 } @@ -218,6 +223,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "ip_range" : { "ip_range" : { "field" : "ip", "ranges": [ { "to": "192.168.0.0" }, { "from": "192.168.0.0", "to": "192.169.0.0" }, { "from": "192.169.0.0" } ] } } } } - length: { aggregations.ip_range.buckets: 3 } @@ -253,6 +259,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_range" : { "date_range" : { "field" : "date", "ranges": [ { "from" : 1000, "to": 3000 }, { "from": 3000, "to": 4000 } ] } } } } - match: { hits.total: 3 } @@ -311,6 +318,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: aggs: age_groups: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/50_filter.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/50_filter.yml index 14e83433ff4..75ced7fc43d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/50_filter.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/50_filter.yml @@ -36,6 +36,7 @@ setup: # Because the filter agg rewrites the terms lookup in the rewrite phase the request can be cached - do: search: + rest_total_hits_as_int: true size: 0 request_cache: true body: {"aggs": { "itemsNotify": { "filter": { "terms": { "mentions": { "index": "test", "type": "test", "id": "foo|bar|baz0", "path": "notifications"}}}, "aggs": { "mentions" : {"terms" : { "field" : "mentions" }}}}}} @@ -58,6 +59,7 @@ setup: # now run without lookup and ensure we get cached or at least do the lookup - do: search: + rest_total_hits_as_int: true size: 0 request_cache: true body: {"aggs": { "itemsNotify": { "filter": { "terms": { "mentions": ["abc"]}}, "aggs": { "mentions" : {"terms" : { "field" : "mentions" }}}}}} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/70_adjacency_matrix.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/70_adjacency_matrix.yml index 9416f4c3f29..0ec46f10e3d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/70_adjacency_matrix.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/70_adjacency_matrix.yml @@ -42,6 +42,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size": 0, "aggs": { "conns": { "adjacency_matrix": { "filters": { "1": { "term": { "num": 1 } }, "2": { "term": { "num": 2 } }, "4": { "term": { "num": 4 } } } } } } } - match: { hits.total: 3 } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/80_typed_keys.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/80_typed_keys.yml index eb6e4efcdca..d7bb2b22ccc 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/80_typed_keys.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/80_typed_keys.yml @@ -33,6 +33,7 @@ setup: "Test typed keys parameter for avg aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -46,6 +47,7 @@ setup: "Test typed keys parameter for cardinality aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -59,6 +61,7 @@ setup: "Test typed keys parameter for extended_stats aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -72,6 +75,7 @@ setup: "Test typed keys parameter for max aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -85,6 +89,7 @@ setup: "Test typed keys parameter for min aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -98,6 +103,7 @@ setup: "Test typed keys parameter for percentiles aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -111,6 +117,7 @@ setup: "Test typed keys parameter for percentile_ranks aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -125,6 +132,7 @@ setup: "Test typed keys parameter for stats aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -138,6 +146,7 @@ setup: "Test typed keys parameter for sum aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -151,6 +160,7 @@ setup: "Test typed keys parameter for terms and top_hits aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -171,6 +181,7 @@ setup: "Test typed keys parameter for terms aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -184,6 +195,7 @@ setup: "Test typed keys parameter for value_count aggregation": - do: search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 @@ -203,6 +215,7 @@ setup: warnings: - 'The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.' search: + rest_total_hits_as_int: true typed_keys: true body: size: 0 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/90_sig_text.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/90_sig_text.yml index 305623e6f04..4b1372303c1 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/90_sig_text.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/90_sig_text.yml @@ -67,12 +67,14 @@ - do: search: + rest_total_hits_as_int: true index: goodbad - match: {hits.total: 7} - do: search: + rest_total_hits_as_int: true index: goodbad body: {"aggs": {"class": {"terms": {"field": "class"},"aggs": {"sig_text": {"significant_text": {"field": "text"}}}}}} @@ -148,12 +150,14 @@ - do: search: + rest_total_hits_as_int: true index: goodbad - match: {hits.total: 7} - do: search: + rest_total_hits_as_int: true index: goodbad body: {"aggs": {"class": {"terms": {"field": "class"},"aggs": {"sig_text": {"significant_text": {"field": "text", "filter_duplicate_text": true}}}}}} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/10_unified.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/10_unified.yml index b799fb8f3e0..5bb9937844a 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/10_unified.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/10_unified.yml @@ -29,6 +29,7 @@ setup: "Basic": - do: search: + rest_total_hits_as_int: true body: { "query" : {"multi_match" : { "query" : "quick brown fox", "fields" : [ "text*"] } }, "highlight" : { "type" : "unified", "fields" : { "*" : {} } } } - match: {hits.hits.0.highlight.text.0: "The quick brown fox is brown."} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/20_fvh.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/20_fvh.yml index 58590236b87..64d9c8c28aa 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/20_fvh.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/20_fvh.yml @@ -27,6 +27,7 @@ setup: "Highlight query": - do: search: + rest_total_hits_as_int: true body: highlight: type: fvh diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/30_max_analyzed_offset.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/30_max_analyzed_offset.yml index c7afdc665d7..840d5c849c7 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/30_max_analyzed_offset.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.highlight/30_max_analyzed_offset.yml @@ -36,6 +36,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true index: test1 body: {"query" : {"match" : {"field1" : "fox"}}, "highlight" : {"type" : "unified", "fields" : {"field1" : {}}}} - match: { error.root_cause.0.type: "illegal_argument_exception" } @@ -49,6 +50,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true index: test1 body: {"query" : {"match" : {"field1" : "fox"}}, "highlight" : {"type" : "unified", "fields" : {"field1" : {}}}} - match: { error.root_cause.0.type: "illegal_argument_exception" } @@ -61,6 +63,7 @@ setup: reason: index.highligt.max_analyzed_offset setting has been added in 7.0.0 - do: search: + rest_total_hits_as_int: true index: test1 body: {"query" : {"match" : {"field2" : "fox"}}, "highlight" : {"type" : "unified", "fields" : {"field2" : {}}}} - match: {hits.hits.0.highlight.field2.0: "The quick brown fox went to the forest and saw another fox."} @@ -74,6 +77,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true index: test1 body: {"query" : {"match" : {"field2" : "fox"}}, "highlight" : {"type" : "plain", "fields" : {"field2" : {}}}} - match: { error.root_cause.0.type: "illegal_argument_exception" } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yml index 884a50507c7..c5bfca5c5b1 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yml @@ -28,6 +28,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "query" : { "nested" : { "path" : "nested_field", "query" : { "match_all" : {} }, "inner_hits" : {} } } } - match: { hits.total: 1 } - match: { hits.hits.0._index: "test" } @@ -60,6 +61,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "query" : { "nested" : { "path" : "nested_field", "query" : { "match_all" : {} }, "inner_hits" : { version: true, "docvalue_fields": [ { "field": "_seq_no", "format": "use_field_mapping" } ]} }}, "version": true, "docvalue_fields" : [ { "field": "_seq_no", "format": "use_field_mapping" } ] } - match: { hits.total: 1 } @@ -83,6 +85,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "query" : { "nested" : { "path" : "nested_field", "query" : { "match_all" : {} }, "inner_hits" : { version: true, "docvalue_fields": [ { "field": "_seq_no", "format": "use_field_mapping" } ]} }}, "version": true, "docvalue_fields" : [ { "field": "_seq_no", "format": "use_field_mapping" } ] } - match: { hits.total: 1 } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/100_stored_fields.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/100_stored_fields.yml index 92910a4f1f9..eaff6167a05 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/100_stored_fields.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/100_stored_fields.yml @@ -16,6 +16,7 @@ setup: "Stored fields": - do: search: + rest_total_hits_as_int: true index: test - is_true: hits.hits.0._id @@ -24,6 +25,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: stored_fields: [] @@ -34,6 +36,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: stored_fields: "_none_" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/110_field_collapsing.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/110_field_collapsing.yml index dad05cce4eb..885fdbdd06b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/110_field_collapsing.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/110_field_collapsing.yml @@ -65,6 +65,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: collapse: { field: numeric_group } @@ -96,6 +97,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: from: 2 @@ -116,6 +118,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: collapse: { field: numeric_group, inner_hits: { name: sub_hits, size: 2, sort: [{ sort: asc }] } } @@ -155,6 +158,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: collapse: { field: numeric_group, max_concurrent_group_searches: 10, inner_hits: { name: sub_hits, size: 2, sort: [{ sort: asc }] } } @@ -196,6 +200,7 @@ setup: - do: catch: /cannot use \`collapse\` in a scroll context/ search: + rest_total_hits_as_int: true index: test scroll: 1s body: @@ -207,6 +212,7 @@ setup: - do: catch: /cannot use \`collapse\` in conjunction with \`search_after\`/ search: + rest_total_hits_as_int: true index: test body: collapse: { field: numeric_group } @@ -219,6 +225,7 @@ setup: - do: catch: /cannot use \`collapse\` in conjunction with \`rescore\`/ search: + rest_total_hits_as_int: true index: test body: collapse: { field: numeric_group } @@ -235,6 +242,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: size: 0 @@ -253,6 +261,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: size: 0 @@ -266,6 +275,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: collapse: @@ -322,6 +332,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: collapse: { field: numeric_group, inner_hits: { name: sub_hits, version: true, size: 2, sort: [{ sort: asc }] } } @@ -380,6 +391,7 @@ setup: group_alias: { type: alias, path: numeric_group } - do: search: + rest_total_hits_as_int: true index: test body: collapse: { field: group_alias, inner_hits: { name: sub_hits } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/115_multiple_field_collapsing.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/115_multiple_field_collapsing.yml index 212ce6785a1..191473ebcce 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/115_multiple_field_collapsing.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/115_multiple_field_collapsing.yml @@ -43,6 +43,7 @@ - do: catch: /parse_exception/ search: + rest_total_hits_as_int: true index: addresses body: query: { "match" : { "address" : "victoria" }} @@ -58,6 +59,7 @@ - do: catch: /parse_exception/ search: + rest_total_hits_as_int: true index: addresses body: query: { "match" : { "address" : "victoria" }} @@ -73,6 +75,7 @@ # ************* top scored - do: search: + rest_total_hits_as_int: true index: addresses body: query: { "match" : { "address" : "victoria" }} @@ -108,6 +111,7 @@ # ************* sorted - do: search: + rest_total_hits_as_int: true index: addresses body: query: { "match" : { "address" : "victoria" }} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/120_batch_reduce_size.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/120_batch_reduce_size.yml index e57dfaa8e93..df8034be98b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/120_batch_reduce_size.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/120_batch_reduce_size.yml @@ -17,6 +17,7 @@ setup: - do: catch: /batchedReduceSize must be >= 2/ search: + rest_total_hits_as_int: true index: test_1 batched_reduce_size: 1 @@ -48,6 +49,7 @@ setup: - do: search: + rest_total_hits_as_int: true batched_reduce_size: 2 body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str" } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/140_pre_filter_search_shards.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/140_pre_filter_search_shards.yml index c63dee2e211..0038ee4eed7 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/140_pre_filter_search_shards.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/140_pre_filter_search_shards.yml @@ -42,6 +42,7 @@ setup: - do: catch: /preFilterShardSize must be >= 1/ search: + rest_total_hits_as_int: true index: test_1 pre_filter_shard_size: 0 @@ -72,6 +73,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { "size" : 0, "query" : { "range" : { "created_at" : { "gte" : "2016-02-01", "lt": "2018-02-01"} } } } - match: { _shards.total: 3 } @@ -83,6 +85,7 @@ setup: # this is the case where we have an empty body and don't skip anything since it's match_all - do: search: + rest_total_hits_as_int: true pre_filter_shard_size: 1 - match: { _shards.total: 3 } @@ -94,6 +97,7 @@ setup: # this is a case where we can actually skip due to rewrite - do: search: + rest_total_hits_as_int: true pre_filter_shard_size: 1 body: { "size" : 0, "query" : { "range" : { "created_at" : { "gte" : "2016-02-01", "lt": "2018-02-01"} } } } @@ -106,6 +110,7 @@ setup: # this case we skip all except of one since we need a real result - do: search: + rest_total_hits_as_int: true pre_filter_shard_size: 1 body: { "size" : 0, "query" : { "range" : { "created_at" : { "gte" : "2019-02-01", "lt": "2020-02-01"} } } } @@ -118,6 +123,7 @@ setup: - do: search: + rest_total_hits_as_int: true pre_filter_shard_size: 1 body: {"size" : 0, "query" : { "range" : { "created_at" : { "gte" : "2016-02-01", "lt": "2018-02-01"} } }, "aggs" : { "some_agg" : { "global" : {} }}} @@ -130,6 +136,7 @@ setup: - do: search: + rest_total_hits_as_int: true pre_filter_shard_size: 1 body: { "size" : 0, "query" : { "range" : { "created_at" : { "gte" : "2016-02-01", "lt": "2018-02-01"}}}, "aggs" : { "idx_terms" : { "terms" : { "field" : "_index", "min_doc_count" : 0 } } } } @@ -142,6 +149,7 @@ setup: - do: search: + rest_total_hits_as_int: true pre_filter_shard_size: 1 body: { "size" : 0, "query" : { "range" : { "created_at" : { "gte" : "2016-02-01", "lt": "2018-02-01"}}}, "aggs" : { "idx_terms" : { "terms" : { "field" : "_index" } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/150_rewrite_on_coordinator.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/150_rewrite_on_coordinator.yml index deeb18ef848..3320a8f87bb 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/150_rewrite_on_coordinator.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/150_rewrite_on_coordinator.yml @@ -37,6 +37,7 @@ - do: catch: /no such index/ search: + rest_total_hits_as_int: true index: "search_index" body: { "size" : 0, "query" : { "terms" : { "user" : { "index": "lookup_index", "type": "doc", "id": "1", "path": "followers"} } } } - do: @@ -61,6 +62,7 @@ - do: search: + rest_total_hits_as_int: true index: "search_index" body: { "size" : 0, "query" : { "terms" : { "user" : { "index": "lookup_index", "type": "doc", "id": "1", "path": "followers"} } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/160_exists_query.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/160_exists_query.yml index 868754d5930..5fb06abc721 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/160_exists_query.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/160_exists_query.yml @@ -369,6 +369,7 @@ setup: "Test exists query on mapped binary field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -381,6 +382,7 @@ setup: "Test exists query on mapped boolean field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -393,6 +395,7 @@ setup: "Test exists query on mapped date field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -405,6 +408,7 @@ setup: "Test exists query on mapped geo_point field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -417,6 +421,7 @@ setup: "Test exists query on mapped geo_shape field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -429,6 +434,7 @@ setup: "Test exists query on mapped ip field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -441,6 +447,7 @@ setup: "Test exists query on mapped keyword field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -453,6 +460,7 @@ setup: "Test exists query on mapped byte field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -465,6 +473,7 @@ setup: "Test exists query on mapped double field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -477,6 +486,7 @@ setup: "Test exists query on mapped float field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -489,6 +499,7 @@ setup: "Test exists query on mapped half_float field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -501,6 +512,7 @@ setup: "Test exists query on mapped integer field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -513,6 +525,7 @@ setup: "Test exists query on mapped long field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -525,6 +538,7 @@ setup: "Test exists query on mapped short field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -537,6 +551,7 @@ setup: "Test exists query on mapped object field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -549,6 +564,7 @@ setup: "Test exists query on mapped object inner field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -561,6 +577,7 @@ setup: "Test exists query on mapped text field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -573,6 +590,7 @@ setup: "Test exists query on _id field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -588,6 +606,7 @@ setup: reason: exists on _index not supported prior to 6.1.0 - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -603,6 +622,7 @@ setup: reason: exists on _type not supported prior to 6.1.0 - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -615,6 +635,7 @@ setup: "Test exists query on _routing field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -627,6 +648,7 @@ setup: "Test exists query on _seq_no field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -643,6 +665,7 @@ setup: - do: catch: /query_shard_exception/ search: + rest_total_hits_as_int: true index: test body: query: @@ -653,6 +676,7 @@ setup: "Test exists query on _version field": - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -665,6 +689,7 @@ setup: "Test exists query on unmapped binary field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -677,6 +702,7 @@ setup: "Test exists query on unmapped boolean field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -689,6 +715,7 @@ setup: "Test exists query on unmapped date field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -701,6 +728,7 @@ setup: "Test exists query on unmapped geo_point field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -713,6 +741,7 @@ setup: "Test exists query on unmapped geo_shape field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -725,6 +754,7 @@ setup: "Test exists query on unmapped ip field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -737,6 +767,7 @@ setup: "Test exists query on unmapped keyword field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -749,6 +780,7 @@ setup: "Test exists query on unmapped byte field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -761,6 +793,7 @@ setup: "Test exists query on unmapped double field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -773,6 +806,7 @@ setup: "Test exists query on unmapped float field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -785,6 +819,7 @@ setup: "Test exists query on unmapped half_float field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -797,6 +832,7 @@ setup: "Test exists query on unmapped integer field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -809,6 +845,7 @@ setup: "Test exists query on unmapped long field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -821,6 +858,7 @@ setup: "Test exists query on unmapped short field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -833,6 +871,7 @@ setup: "Test exists query on unmapped object field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -845,6 +884,7 @@ setup: "Test exists query on unmapped object inner field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -857,6 +897,7 @@ setup: "Test exists query on unmapped text field": - do: search: + rest_total_hits_as_int: true index: test-unmapped body: query: @@ -869,6 +910,7 @@ setup: "Test exists query on binary field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -881,6 +923,7 @@ setup: "Test exists query on boolean field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -893,6 +936,7 @@ setup: "Test exists query on date field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -905,6 +949,7 @@ setup: "Test exists query on geo_point field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -917,6 +962,7 @@ setup: "Test exists query on geo_shape field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -929,6 +975,7 @@ setup: "Test exists query on ip field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -941,6 +988,7 @@ setup: "Test exists query on keyword field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -953,6 +1001,7 @@ setup: "Test exists query on byte field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -965,6 +1014,7 @@ setup: "Test exists query on double field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -977,6 +1027,7 @@ setup: "Test exists query on float field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -989,6 +1040,7 @@ setup: "Test exists query on half_float field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -1001,6 +1053,7 @@ setup: "Test exists query on integer field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -1013,6 +1066,7 @@ setup: "Test exists query on long field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -1025,6 +1079,7 @@ setup: "Test exists query on short field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -1037,6 +1092,7 @@ setup: "Test exists query on object field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -1049,6 +1105,7 @@ setup: "Test exists query on object inner field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -1061,6 +1118,7 @@ setup: "Test exists query on text field in empty index": - do: search: + rest_total_hits_as_int: true index: test-empty body: query: @@ -1073,6 +1131,7 @@ setup: "Test exists query on mapped binary field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1085,6 +1144,7 @@ setup: "Test exists query on mapped boolean field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1097,6 +1157,7 @@ setup: "Test exists query on mapped date field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1109,6 +1170,7 @@ setup: "Test exists query on mapped geo_point field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1121,6 +1183,7 @@ setup: "Test exists query on mapped geo_shape field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1133,6 +1196,7 @@ setup: "Test exists query on mapped ip field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1145,6 +1209,7 @@ setup: "Test exists query on mapped keyword field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1157,6 +1222,7 @@ setup: "Test exists query on mapped byte field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1169,6 +1235,7 @@ setup: "Test exists query on mapped double field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1181,6 +1248,7 @@ setup: "Test exists query on mapped float field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1193,6 +1261,7 @@ setup: "Test exists query on mapped half_float field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1205,6 +1274,7 @@ setup: "Test exists query on mapped integer field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1217,6 +1287,7 @@ setup: "Test exists query on mapped long field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1229,6 +1300,7 @@ setup: "Test exists query on mapped short field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1241,6 +1313,7 @@ setup: "Test exists query on mapped object field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1253,6 +1326,7 @@ setup: "Test exists query on mapped object inner field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: @@ -1265,6 +1339,7 @@ setup: "Test exists query on mapped text field with no doc values": - do: search: + rest_total_hits_as_int: true index: test-no-dv body: query: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/170_terms_query.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/170_terms_query.yml index a20df2b9279..515dcfe4630 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/170_terms_query.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/170_terms_query.yml @@ -32,6 +32,7 @@ - do: search: + rest_total_hits_as_int: true index: test_index body: {"query" : {"terms" : {"user" : ["u1", "u2"]}}} - match: { hits.total: 2 } @@ -39,11 +40,13 @@ - do: catch: bad_request search: + rest_total_hits_as_int: true index: test_index body: {"query" : {"terms" : {"user" : ["u1", "u2", "u3"]}}} - do: search: + rest_total_hits_as_int: true index: test_index body: {"query" : {"terms" : {"user" : {"index" : "test_index", "type" : "test_type", "id" : "u1", "path" : "followers"}}}} - match: { hits.total: 2 } @@ -51,5 +54,6 @@ - do: catch: bad_request search: + rest_total_hits_as_int: true index: test_index body: {"query" : {"terms" : {"user" : {"index" : "test_index", "type" : "test_type", "id" : "u2", "path" : "followers"}}}} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/180_local_dependent_mapping.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/180_local_dependent_mapping.yml index aac970d7ba8..0e50f7f327b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/180_local_dependent_mapping.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/180_local_dependent_mapping.yml @@ -27,12 +27,14 @@ - do: search: + rest_total_hits_as_int: true index: test_index body: {"query" : {"range" : {"date_field" : {"gte": "Di, 05 Dez 2000 02:55:00 -0800", "lte": "Do, 07 Dez 2000 00:00:00 -0800"}}}} - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: test_index body: {"query" : {"range" : {"date_field" : {"gte": "Di, 05 Dez 2000 02:55:00 -0800", "lte": "Fr, 08 Dez 2000 00:00:00 -0800"}}}} - match: { hits.total: 2 } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/190_index_prefix_search.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/190_index_prefix_search.yml index 62770e2915d..016bb7c6046 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/190_index_prefix_search.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/190_index_prefix_search.yml @@ -34,6 +34,7 @@ setup: reason: index_prefixes is only available as of 6.3.0 - do: search: + rest_total_hits_as_int: true index: test q: shor* df: text @@ -44,6 +45,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -58,6 +60,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test q: stupendousl* df: text @@ -74,6 +77,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/200_ignore_malformed.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/200_ignore_malformed.yml index 996501e7d79..cc930de47f0 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/200_ignore_malformed.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/200_ignore_malformed.yml @@ -48,6 +48,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { query: { exists: { "field": "_ignored" } } } - length: { hits.hits: 3 } @@ -57,6 +58,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { query: { term: { "_ignored": "my_date" } } } - length: { hits.hits: 2 } @@ -66,6 +68,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { query: { terms: { "_ignored": [ "my_date", "my_ip" ] } } } - length: { hits.hits: 3 } @@ -75,6 +78,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { query: { ids: { "values": [ "3" ] } } } - length: { hits.hits: 1 } @@ -85,6 +89,7 @@ setup: - do: search: + rest_total_hits_as_int: true stored_fields: [ "my_date" ] body: { query: { ids: { "values": [ "3" ] } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/200_index_phrase_search.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/200_index_phrase_search.yml index 241fbc187de..10c2869ac03 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/200_index_phrase_search.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/200_index_phrase_search.yml @@ -27,6 +27,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -38,6 +39,7 @@ - do: search: + rest_total_hits_as_int: true index: test q: '"peter piper"~1' df: text @@ -46,6 +48,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: @@ -56,6 +59,7 @@ - do: search: + rest_total_hits_as_int: true index: test body: query: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/20_default_values.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/20_default_values.yml index 0f42b1bd6b5..db9e0f586d0 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/20_default_values.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/20_default_values.yml @@ -28,6 +28,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: _all body: query: @@ -38,6 +39,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test_1 body: query: @@ -51,6 +53,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test_2 body: query: @@ -68,17 +71,21 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true body: match: foo: bar --- -"Search with rest_total_hits_as_int": +"Search with new response format": - skip: - version: " - 6.5.99" - reason: rest_total_hits_as_int was introduced in 6.6.0 + version: " - 6.99.99" + reason: hits.total is returned as an object in 7.0.0 - do: search: - rest_total_hits_as_int: true + body: + query: + match_all: {} - - match: {hits.total: 2} + - match: {hits.total.value: 2} + - match: {hits.total.relation: eq} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/210_rescore_explain.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/210_rescore_explain.yml index 4d7ee91bef5..ad38260837b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/210_rescore_explain.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/210_rescore_explain.yml @@ -16,6 +16,7 @@ - do: search: + rest_total_hits_as_int: true index: test_index body: explain: true 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 new file mode 100644 index 00000000000..f1660980869 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/220_total_hits_object.yml @@ -0,0 +1,87 @@ +setup: + - do: + indices.create: + index: test_2 + - do: + indices.create: + index: test_1 + - do: + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + + - do: + index: + index: test_2 + type: test + id: 42 + body: { foo: bar } + + - do: + indices.refresh: + index: [test_1, test_2] + +--- +"hits.total as an object": + - skip: + version: " - 6.99.99" + reason: hits.total is rendered as an object in 7.0.0 + - do: + search: + index: _all + body: + query: + match: + foo: bar + + - match: {hits.total.value: 2} + - match: {hits.total.relation: eq} + + - do: + search: + index: test_1 + body: + query: + match: + foo: bar + + - match: {hits.total.value: 1} + - match: {hits.total.relation: eq} + + - do: + search: + track_total_hits: false + index: _all + body: + query: + match: + foo: bar + + - is_false: hits.total + + - do: + search: + track_total_hits: false + rest_total_hits_as_int: true + index: _all + body: + query: + match: + foo: bar + + - match: {hits.total: -1} + + - do: + search: + rest_total_hits_as_int: true + index: test_2 + body: + query: + match: + foo: bar + + - match: {hits.total: 1} + + diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/30_limits.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/30_limits.yml index 8b51a6c2d39..18a004077ae 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/30_limits.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/30_limits.yml @@ -22,6 +22,7 @@ setup: - do: catch: /Result window is too large, from \+ size must be less than or equal to[:] \[10000\] but was \[10010\]\. See the scroll api for a more efficient way to request large data sets\./ search: + rest_total_hits_as_int: true index: test_1 from: 10000 @@ -30,6 +31,7 @@ setup: - do: catch: /\[from\] parameter cannot be negative/ search: + rest_total_hits_as_int: true index: test_1 from: -2 @@ -38,6 +40,7 @@ setup: - do: catch: /Batch size is too large, size must be less than or equal to[:] \[10000\] but was \[10010\]\. Scroll batch sizes cost as much memory as result windows so they are controlled by the \[index.max_result_window\] index level setting\./ search: + rest_total_hits_as_int: true index: test_1 scroll: 5m size: 10010 @@ -47,6 +50,7 @@ setup: - do: catch: /Rescore window \[10001\] is too large\. It must be less than \[10000\]\./ search: + rest_total_hits_as_int: true index: test_1 body: query: @@ -68,6 +72,7 @@ setup: - do: catch: /Trying to retrieve too many docvalue_fields\. Must be less than or equal to[:] \[2\] but was \[3\]\. This limit can be set by changing the \[index.max_docvalue_fields_search\] index level setting\./ search: + rest_total_hits_as_int: true index: test_1 body: query: @@ -86,6 +91,7 @@ setup: - do: catch: /Trying to retrieve too many script_fields\. Must be less than or equal to[:] \[2\] but was \[3\]\. This limit can be set by changing the \[index.max_script_fields\] index level setting\./ search: + rest_total_hits_as_int: true index: test_1 body: query: @@ -104,6 +110,7 @@ setup: - do: catch: /The length of regex \[1110\] used in the Regexp Query request has exceeded the allowed maximum of \[1000\]\. This maximum can be set by changing the \[index.max_regex_length\] index level setting\./ search: + rest_total_hits_as_int: true index: test_1 body: query: @@ -126,6 +133,7 @@ setup: - do: catch: /The length of regex \[1110\]/ search: + rest_total_hits_as_int: true index: test_1 body: query: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/40_indices_boost.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/40_indices_boost.yml index b6793f9e225..37d53fe8a6d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/40_indices_boost.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/40_indices_boost.yml @@ -44,6 +44,7 @@ setup: warnings: - 'Object format in indices_boost is deprecated, please use array format instead' search: + rest_total_hits_as_int: true index: _all body: indices_boost: {test_1: 2.0, test_2: 1.0} @@ -56,6 +57,7 @@ setup: warnings: - 'Object format in indices_boost is deprecated, please use array format instead' search: + rest_total_hits_as_int: true index: _all body: indices_boost: {test_1: 1.0, test_2: 2.0} @@ -68,6 +70,7 @@ setup: "Indices boost using array": - do: search: + rest_total_hits_as_int: true index: _all body: indices_boost: [{test_1: 2.0}, {test_2: 1.0}] @@ -78,6 +81,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: _all body: indices_boost: [{test_1: 1.0}, {test_2: 2.0}] @@ -90,6 +94,7 @@ setup: "Indices boost using array with alias": - do: search: + rest_total_hits_as_int: true index: _all body: indices_boost: [{alias_1: 2.0}] @@ -100,6 +105,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: _all body: indices_boost: [{alias_2: 2.0}] @@ -112,6 +118,7 @@ setup: "Indices boost using array with wildcard": - do: search: + rest_total_hits_as_int: true index: _all body: indices_boost: [{"*_1": 2.0}] @@ -122,6 +129,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: _all body: indices_boost: [{"*_2": 2.0}] @@ -134,6 +142,7 @@ setup: "Indices boost using array multiple match": - do: search: + rest_total_hits_as_int: true index: _all body: # First match (3.0) is used for test_1 @@ -145,6 +154,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: _all body: # First match (1.0) is used for test_1 @@ -159,12 +169,14 @@ setup: - do: catch: /no such index/ search: + rest_total_hits_as_int: true index: _all body: indices_boost: [{nonexistent: 2.0}, {test_1: 1.0}, {test_2: 2.0}] - do: search: + rest_total_hits_as_int: true index: _all ignore_unavailable: true body: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/60_query_string.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/60_query_string.yml index 3e7c46e7476..897f4df2985 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/60_query_string.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/60_query_string.yml @@ -23,6 +23,7 @@ - do: search: + rest_total_hits_as_int: true index: test q: bar df: field @@ -31,6 +32,7 @@ - do: search: + rest_total_hits_as_int: true index: test q: field:foo field:xyz @@ -38,6 +40,7 @@ - do: search: + rest_total_hits_as_int: true index: test q: field:foo field:xyz default_operator: AND @@ -46,6 +49,7 @@ - do: search: + rest_total_hits_as_int: true index: test q: field:BA* @@ -53,6 +57,7 @@ - do: search: + rest_total_hits_as_int: true index: test q: number:foo lenient: true diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/70_response_filtering.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/70_response_filtering.yml index ef60d48258c..ec73c63fce6 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/70_response_filtering.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/70_response_filtering.yml @@ -23,6 +23,7 @@ - do: search: + rest_total_hits_as_int: true index: test filter_path: "*" body: "{ \"query\": { \"match_all\": {} } }" @@ -40,6 +41,7 @@ - do: search: + rest_total_hits_as_int: true index: test filter_path: "took" body: "{ \"query\": { \"match_all\": {} } }" @@ -56,6 +58,7 @@ - do: search: + rest_total_hits_as_int: true index: test filter_path: "_shards.*" body: "{ \"query\": { \"match_all\": {} } }" @@ -72,6 +75,7 @@ - do: search: + rest_total_hits_as_int: true index: test filter_path: [ "hits.**._i*", "**.total" ] body: "{ \"query\": { \"match_all\": {} } }" @@ -99,6 +103,7 @@ - do: search: + rest_total_hits_as_int: true filter_path: [ "-**._source.properties", "**._source" ] body: { query: { match_all: {} } } @@ -112,6 +117,7 @@ - do: search: + rest_total_hits_as_int: true filter_path: [ "**.properties" , "-hits.hits._source.properties.meta" ] body: { query: { match_all: {} } } @@ -129,6 +135,7 @@ - do: search: + rest_total_hits_as_int: true filter_path: "**._source,-**.meta.foo" body: { query: { match_all: {} } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/80_indices_options.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/80_indices_options.yml index d3cb5dae846..71b554f2a5a 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/80_indices_options.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/80_indices_options.yml @@ -4,6 +4,7 @@ - do: catch: /logstash-\d{4}\.\d{2}\.\d{2}/ search: + rest_total_hits_as_int: true index: --- @@ -12,10 +13,12 @@ - do: catch: missing search: + rest_total_hits_as_int: true index: missing_index - do: search: + rest_total_hits_as_int: true index: missing_index ignore_unavailable: true @@ -35,10 +38,12 @@ - do: catch: /index_closed_exception/ search: + rest_total_hits_as_int: true index: index_closed - do: search: + rest_total_hits_as_int: true index: index_closed ignore_unavailable: true @@ -46,6 +51,7 @@ - do: search: + rest_total_hits_as_int: true index: index* - match: {hits.total: 0} @@ -53,11 +59,13 @@ - do: catch: missing search: + rest_total_hits_as_int: true index: index* allow_no_indices: false - do: catch: /index_closed_exception/ search: + rest_total_hits_as_int: true index: index* expand_wildcards: ["open","closed"] diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/90_search_after.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/90_search_after.yml index 968095ae698..d1867b9a818 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/90_search_after.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/90_search_after.yml @@ -32,6 +32,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: size: 1 @@ -49,6 +50,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: size: 1 @@ -67,6 +69,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: size: 1 @@ -85,6 +88,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: size: 1 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/issue4895.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/issue4895.yml index 96a2ca4854a..2c673831388 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/issue4895.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/issue4895.yml @@ -24,6 +24,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true index: test type: test body: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/issue9606.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/issue9606.yml index 3e46531c034..ca75adf1c73 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/issue9606.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/issue9606.yml @@ -21,6 +21,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true index: test type: test search_type: query_and_fetch @@ -35,6 +36,7 @@ setup: - do: catch: bad_request search: + rest_total_hits_as_int: true index: test type: test search_type: dfs_query_and_fetch diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/10_basic.yml index 44ba197f9e0..67b9f38de77 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/10_basic.yml @@ -14,6 +14,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: test_suggestion: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/20_completion.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/20_completion.yml index 3ac9b4ee2dd..ab459e2ad23 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/20_completion.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/20_completion.yml @@ -51,6 +51,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -77,6 +78,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -90,6 +92,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -129,6 +132,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -173,6 +177,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -187,6 +192,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -216,6 +222,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -229,6 +236,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -272,6 +280,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -319,6 +328,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/30_context.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/30_context.yml index 1bf70e7dc42..9ddbc922f61 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/30_context.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/30_context.yml @@ -75,6 +75,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -116,6 +117,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -131,6 +133,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -146,6 +149,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -195,6 +199,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: suggest: @@ -246,6 +251,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: suggest: @@ -264,6 +270,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test body: suggest: @@ -322,6 +329,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: suggest: result: @@ -373,6 +381,7 @@ setup: - do: catch: /Missing mandatory contexts in context query/ search: + rest_total_hits_as_int: true allow_partial_search_results: false body: suggest: @@ -384,6 +393,7 @@ setup: - do: catch: /Missing mandatory contexts in context query/ search: + rest_total_hits_as_int: true allow_partial_search_results: false body: suggest: @@ -396,6 +406,7 @@ setup: - do: catch: /Missing mandatory contexts in context query/ search: + rest_total_hits_as_int: true allow_partial_search_results: false body: suggest: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/40_typed_keys.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/40_typed_keys.yml index 44cd6d589c2..6a04997d244 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/40_typed_keys.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/40_typed_keys.yml @@ -34,6 +34,7 @@ setup: - do: search: + rest_total_hits_as_int: true typed_keys: true body: query: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/50_completion_with_multi_fields.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/50_completion_with_multi_fields.yml index 42207a073fb..321ea8db215 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/50_completion_with_multi_fields.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/suggest/50_completion_with_multi_fields.yml @@ -40,6 +40,7 @@ - do: search: + rest_total_hits_as_int: true index: completion_with_sub_keyword body: suggest: @@ -54,6 +55,7 @@ - do: search: + rest_total_hits_as_int: true index: completion_with_sub_keyword body: query: { term: { suggest_1.text_raw: "bar" }} @@ -103,6 +105,7 @@ - do: search: + rest_total_hits_as_int: true index: completion_with_sub_completion body: suggest: @@ -170,6 +173,7 @@ - do: search: + rest_total_hits_as_int: true index: completion_with_context body: suggest: @@ -230,6 +234,7 @@ - do: search: + rest_total_hits_as_int: true index: completion_with_weight body: suggest: @@ -286,6 +291,7 @@ - do: search: + rest_total_hits_as_int: true index: geofield_with_completion body: suggest: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/update/60_refresh.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/update/60_refresh.yml index b590d01f93a..9e7dfdf4698 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/update/60_refresh.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/update/60_refresh.yml @@ -24,6 +24,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -42,6 +43,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 2 }} @@ -74,6 +76,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { cat: dog }} @@ -97,6 +100,7 @@ - do: search: + rest_total_hits_as_int: true index: update_60_refresh_1 body: query: { term: { _id: update_60_refresh_id1 }} @@ -113,6 +117,7 @@ - do: search: + rest_total_hits_as_int: true index: update_60_refresh_1 body: query: { match: { test: asdf } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/update/61_refresh_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/update/61_refresh_with_types.yml index 8ac1568a127..be2d9f9f796 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/update/61_refresh_with_types.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/update/61_refresh_with_types.yml @@ -20,6 +20,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 1 }} @@ -39,6 +40,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { _id: 2 }} @@ -68,6 +70,7 @@ - do: search: + rest_total_hits_as_int: true index: test_1 body: query: { term: { cat: dog }} @@ -87,6 +90,7 @@ - do: search: + rest_total_hits_as_int: true index: update_60_refresh_1 body: query: { term: { _id: update_60_refresh_id1 }} @@ -104,6 +108,7 @@ - do: search: + rest_total_hits_as_int: true index: update_60_refresh_1 body: query: { match: { test: asdf } } diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index 651fba0b77e..0aa41a0d652 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -112,6 +112,8 @@ public class Version implements Comparable, ToXContentFragment { public static final Version V_6_5_1 = new Version(V_6_5_1_ID, org.apache.lucene.util.Version.LUCENE_7_5_0); public static final int V_6_5_2_ID = 6050299; public static final Version V_6_5_2 = new Version(V_6_5_2_ID, org.apache.lucene.util.Version.LUCENE_7_5_0); + public static final int V_6_5_3_ID = 6050399; + public static final Version V_6_5_3 = new Version(V_6_5_3_ID, org.apache.lucene.util.Version.LUCENE_7_5_0); public static final int V_6_6_0_ID = 6060099; public static final Version V_6_6_0 = new Version(V_6_6_0_ID, org.apache.lucene.util.Version.LUCENE_7_6_0); public static final int V_7_0_0_ID = 7000099; @@ -134,6 +136,8 @@ public class Version implements Comparable, ToXContentFragment { return V_7_0_0; case V_6_6_0_ID: return V_6_6_0; + case V_6_5_3_ID: + return V_6_5_3; case V_6_5_2_ID: return V_6_5_2; case V_6_5_1_ID: 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 01ef94c428a..28a71936460 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java @@ -402,8 +402,7 @@ public final class SearchPhaseController { hits.add(searchHit); } } - return new SearchHits(hits.toArray(new SearchHit[hits.size()]), reducedQueryPhase.totalHits, - reducedQueryPhase.maxScore); + return new SearchHits(hits.toArray(new SearchHit[hits.size()]), reducedQueryPhase.totalHits, reducedQueryPhase.maxScore); } /** @@ -443,7 +442,8 @@ public final class SearchPhaseController { boolean timedOut = false; Boolean terminatedEarly = null; if (queryResults.isEmpty()) { // early terminate we have nothing to reduce - return new ReducedQueryPhase(topDocsStats.totalHits, topDocsStats.fetchHits, topDocsStats.maxScore, + final TotalHits totalHits = topDocsStats.getTotalHits(); + return new ReducedQueryPhase(totalHits, topDocsStats.fetchHits, topDocsStats.maxScore, timedOut, terminatedEarly, null, null, null, EMPTY_DOCS, null, null, numReducePhases, false, 0, 0, true); } @@ -508,7 +508,8 @@ public final class SearchPhaseController { firstResult.pipelineAggregators(), reduceContext); final SearchProfileShardResults shardResults = profileResults.isEmpty() ? null : new SearchProfileShardResults(profileResults); final SortedTopDocs scoreDocs = this.sortDocs(isScrollRequest, queryResults, bufferedTopDocs, topDocsStats, from, size); - return new ReducedQueryPhase(topDocsStats.totalHits, topDocsStats.fetchHits, topDocsStats.maxScore, + final TotalHits totalHits = topDocsStats.getTotalHits(); + return new ReducedQueryPhase(totalHits, topDocsStats.fetchHits, topDocsStats.maxScore, timedOut, terminatedEarly, suggest, aggregations, shardResults, scoreDocs.scoreDocs, scoreDocs.sortFields, firstResult != null ? firstResult.sortValueFormats() : null, numReducePhases, scoreDocs.isSortedByField, size, from, firstResult == null); @@ -543,7 +544,7 @@ public final class SearchPhaseController { public static final class ReducedQueryPhase { // the sum of all hits across all reduces shards - final long totalHits; + final TotalHits totalHits; // the number of returned hits (doc IDs) across all reduces shards final long fetchHits; // the max score across all reduces hits or {@link Float#NaN} if no hits returned @@ -575,7 +576,7 @@ public final class SearchPhaseController { // sort value formats used to sort / format the result final DocValueFormat[] sortValueFormats; - ReducedQueryPhase(long totalHits, long fetchHits, float maxScore, boolean timedOut, Boolean terminatedEarly, Suggest suggest, + ReducedQueryPhase(TotalHits totalHits, long fetchHits, float maxScore, boolean timedOut, Boolean terminatedEarly, Suggest suggest, InternalAggregations aggregations, SearchProfileShardResults shardResults, ScoreDoc[] scoreDocs, SortField[] sortFields, DocValueFormat[] sortValueFormats, int numReducePhases, boolean isSortedByField, int size, int from, boolean isEmptyResult) { @@ -748,8 +749,8 @@ public final class SearchPhaseController { static final class TopDocsStats { final boolean trackTotalHits; - long totalHits; - TotalHits.Relation totalHitsRelation = TotalHits.Relation.EQUAL_TO; + private long totalHits; + private TotalHits.Relation totalHitsRelation; long fetchHits; float maxScore = Float.NEGATIVE_INFINITY; @@ -759,7 +760,12 @@ public final class SearchPhaseController { TopDocsStats(boolean trackTotalHits) { this.trackTotalHits = trackTotalHits; - this.totalHits = trackTotalHits ? 0 : -1; + this.totalHits = 0; + this.totalHitsRelation = trackTotalHits ? Relation.EQUAL_TO : Relation.GREATER_THAN_OR_EQUAL_TO; + } + + TotalHits getTotalHits() { + return trackTotalHits ? new TotalHits(totalHits, totalHitsRelation) : null; } void add(TopDocsAndMaxScore topDocs) { diff --git a/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java b/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java index 32c527f06ff..abd67a47049 100644 --- a/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java +++ b/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java @@ -163,7 +163,13 @@ public final class SearchSlowLog implements SearchOperationListener { .append(" ") .append("took[").append(TimeValue.timeValueNanos(tookInNanos)).append("], ") .append("took_millis[").append(TimeUnit.NANOSECONDS.toMillis(tookInNanos)).append("], ") - .append("total_hits[").append(context.queryResult().getTotalHits()).append("], "); + .append("total_hits["); + if (context.queryResult().getTotalHits() != null) { + sb.append(context.queryResult().getTotalHits()); + } else { + sb.append("-1"); + } + sb.append("], "); if (context.getQueryShardContext().getTypes() == null) { sb.append("types[], "); } else { diff --git a/server/src/main/java/org/elasticsearch/index/reindex/ClientScrollableHitSource.java b/server/src/main/java/org/elasticsearch/index/reindex/ClientScrollableHitSource.java index eb8c0e14f43..7ba30134979 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/ClientScrollableHitSource.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/ClientScrollableHitSource.java @@ -198,7 +198,8 @@ public class ClientScrollableHitSource extends ScrollableHitSource { } hits = unmodifiableList(hits); } - return new Response(response.isTimedOut(), failures, response.getHits().getTotalHits(), + long total = response.getHits().getTotalHits().value; + return new Response(response.isTimedOut(), failures, total, hits, response.getScrollId()); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java index 840f4de5ea7..7dd0758c008 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.cat; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; @@ -60,7 +61,7 @@ public class RestCountAction extends AbstractCatAction { public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) { String[] indices = Strings.splitStringByCommaToArray(request.param("index")); SearchRequest countRequest = new SearchRequest(indices); - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0).trackTotalHits(true); countRequest.source(searchSourceBuilder); try { request.withContentOrSourceParamParserOrNull(parser -> { @@ -79,6 +80,7 @@ public class RestCountAction extends AbstractCatAction { return channel -> client.search(countRequest, new RestResponseListener(channel) { @Override public RestResponse buildResponse(SearchResponse countResponse) throws Exception { + assert countResponse.getHits().getTotalHits().relation == TotalHits.Relation.EQUAL_TO; return RestTable.buildResponse(buildTable(request, countResponse), channel); } }); @@ -96,7 +98,7 @@ public class RestCountAction extends AbstractCatAction { private Table buildTable(RestRequest request, SearchResponse response) { Table table = getTableWithHeader(request); table.startRow(); - table.addCell(response.getHits().getTotalHits()); + table.addCell(response.getHits().getTotalHits().value); table.endRow(); return table; diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java index 99ea1c81fa9..cd092733969 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java @@ -108,7 +108,7 @@ public class RestCountAction extends BaseRestHandler { if (terminateAfter != DEFAULT_TERMINATE_AFTER) { builder.field("terminated_early", response.isTerminatedEarly()); } - builder.field("count", response.getHits().getTotalHits()); + builder.field("count", response.getHits().getTotalHits().value); buildBroadcastShardsHeader(builder, request, response.getTotalShards(), response.getSuccessfulShards(), 0, response.getFailedShards(), response.getShardFailures()); diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 65d640cf310..f33280999de 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -55,8 +55,12 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.search.suggest.SuggestBuilders.termSuggestion; public class RestSearchAction extends BaseRestHandler { - public static final String TYPED_KEYS_PARAM = "typed_keys"; + /** + * Indicates whether hits.total should be rendered as an integer or an object + * in the rest search response. + */ public static final String TOTAL_HIT_AS_INT_PARAM = "rest_total_hits_as_int"; + public static final String TYPED_KEYS_PARAM = "typed_keys"; private static final Set RESPONSE_PARAMS; static { diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java index 67f70b129c1..6d2f0971ad7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java @@ -37,7 +37,7 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestSearchScrollAction extends BaseRestHandler { - Set RESPONSE_PARAMS = Collections.singleton(RestSearchAction.TOTAL_HIT_AS_INT_PARAM); + private static final Set RESPONSE_PARAMS = Collections.singleton(RestSearchAction.TOTAL_HIT_AS_INT_PARAM); public RestSearchScrollAction(Settings settings, RestController controller) { super(settings); diff --git a/server/src/main/java/org/elasticsearch/search/SearchHit.java b/server/src/main/java/org/elasticsearch/search/SearchHit.java index 4532385f313..3d8ea384546 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchHit.java +++ b/server/src/main/java/org/elasticsearch/search/SearchHit.java @@ -117,7 +117,7 @@ public final class SearchHit implements Streamable, ToXContentObject, Iterable innerHits; - private SearchHit() { + SearchHit() { } @@ -792,6 +792,8 @@ public final class SearchHit implements Streamable, ToXContentObject, Iterable hits = new ArrayList<>(); - long totalHits = 0; + TotalHits totalHits = null; float maxScore = 0f; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (Fields.TOTAL.equals(currentFieldName)) { - totalHits = parser.longValue(); + // For BWC with nodes pre 7.0 + long value = parser.longValue(); + totalHits = value == -1 ? null : new TotalHits(value, Relation.EQUAL_TO); } else if (Fields.MAX_SCORE.equals(currentFieldName)) { maxScore = parser.floatValue(); } @@ -153,15 +168,17 @@ public final class SearchHits implements Streamable, ToXContentFragment, Iterabl parser.skipChildren(); } } else if (token == XContentParser.Token.START_OBJECT) { - parser.skipChildren(); + if (Fields.TOTAL.equals(currentFieldName)) { + totalHits = parseTotalHitsFragment(parser); + } else { + parser.skipChildren(); + } } } - SearchHits searchHits = new SearchHits(hits.toArray(new SearchHit[hits.size()]), totalHits, - maxScore); + SearchHits searchHits = new SearchHits(hits.toArray(new SearchHit[hits.size()]), totalHits, maxScore); return searchHits; } - public static SearchHits readSearchHits(StreamInput in) throws IOException { SearchHits hits = new SearchHits(); hits.readFrom(in); @@ -170,16 +187,11 @@ public final class SearchHits implements Streamable, ToXContentFragment, Iterabl @Override public void readFrom(StreamInput in) throws IOException { - final boolean hasTotalHits; - if (in.getVersion().onOrAfter(Version.V_6_0_0_beta1)) { - hasTotalHits = in.readBoolean(); + if (in.readBoolean()) { + totalHits = new Total(in); } else { - hasTotalHits = true; - } - if (hasTotalHits) { - totalHits = in.readVLong(); - } else { - totalHits = -1; + // track_total_hits is false + totalHits = null; } maxScore = in.readFloat(); int size = in.readVInt(); @@ -195,16 +207,10 @@ public final class SearchHits implements Streamable, ToXContentFragment, Iterabl @Override public void writeTo(StreamOutput out) throws IOException { - final boolean hasTotalHits; - if (out.getVersion().onOrAfter(Version.V_6_0_0_beta1)) { - hasTotalHits = totalHits >= 0; - out.writeBoolean(hasTotalHits); - } else { - assert totalHits >= 0; - hasTotalHits = true; - } + final boolean hasTotalHits = totalHits != null; + out.writeBoolean(hasTotalHits); if (hasTotalHits) { - out.writeVLong(totalHits); + totalHits.writeTo(out); } out.writeFloat(maxScore); out.writeVInt(hits.length); @@ -228,6 +234,91 @@ public final class SearchHits implements Streamable, ToXContentFragment, Iterabl @Override public int hashCode() { - return Objects.hash(totalHits, maxScore, Arrays.hashCode(hits)); + return Objects.hash(totalHits, totalHits, maxScore, Arrays.hashCode(hits)); + } + + public static TotalHits parseTotalHitsFragment(XContentParser parser) throws IOException { + long value = -1; + Relation relation = null; + XContentParser.Token token; + String currentFieldName = null; + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + if (token == XContentParser.Token.FIELD_NAME) { + currentFieldName = parser.currentName(); + } else if (token.isValue()) { + if ("value".equals(currentFieldName)) { + value = parser.longValue(); + } else if ("relation".equals(currentFieldName)) { + relation = parseRelation(parser.text()); + } + } else { + parser.skipChildren(); + } + } + return new TotalHits(value, relation); + } + + private static Relation parseRelation(String relation) { + if ("gte".equals(relation)) { + return Relation.GREATER_THAN_OR_EQUAL_TO; + } else if ("eq".equals(relation)) { + return Relation.EQUAL_TO; + } else { + throw new IllegalArgumentException("invalid total hits relation: " + relation); + } + } + + private static String printRelation(Relation relation) { + return relation == Relation.EQUAL_TO ? "eq" : "gte"; + } + + private static class Total implements Writeable, ToXContentFragment { + final TotalHits in; + + Total(StreamInput in) throws IOException { + final long value = in.readVLong(); + final Relation relation; + if (in.getVersion().onOrAfter(Version.V_7_0_0)) { + relation = in.readEnum(Relation.class); + } else { + relation = Relation.EQUAL_TO; + } + this.in = new TotalHits(value, relation); + } + + Total(TotalHits in) { + this.in = Objects.requireNonNull(in); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Total total = (Total) o; + return in.value == total.in.value && + in.relation == total.in.relation; + } + + @Override + public int hashCode() { + return Objects.hash(in.value, in.relation); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeVLong(in.value); + if (out.getVersion().onOrAfter(Version.V_7_0_0)) { + out.writeEnum(in.relation); + } else { + assert in.relation == Relation.EQUAL_TO; + } + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.field("value", in.value); + builder.field("relation", printRelation(in.relation)); + return builder; + } } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalTopHits.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalTopHits.java index 0c85191379f..ff6e10baee5 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalTopHits.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalTopHits.java @@ -161,7 +161,7 @@ public class InternalTopHits extends InternalAggregation implements TopHits { assert reducedTopDocs.totalHits.relation == Relation.EQUAL_TO; return new InternalTopHits(name, this.from, this.size, new TopDocsAndMaxScore(reducedTopDocs, maxScore), - new SearchHits(hits, reducedTopDocs.totalHits.value, maxScore), pipelineAggregators(), getMetaData()); + new SearchHits(hits, reducedTopDocs.totalHits, maxScore), pipelineAggregators(), getMetaData()); } @Override diff --git a/server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java b/server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java index d5d081e9697..ab2f864bfce 100644 --- a/server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java +++ b/server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java @@ -28,7 +28,6 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TotalHits; -import org.apache.lucene.search.TotalHits.Relation; import org.apache.lucene.search.Weight; import org.apache.lucene.util.BitSet; import org.elasticsearch.ExceptionsHelper; @@ -182,8 +181,7 @@ public class FetchPhase implements SearchPhase { } TotalHits totalHits = context.queryResult().getTotalHits(); - long totalHitsAsLong = totalHits.relation == Relation.EQUAL_TO ? totalHits.value : -1; - context.fetchResult().hits(new SearchHits(hits, totalHitsAsLong, context.queryResult().getMaxScore())); + context.fetchResult().hits(new SearchHits(hits, totalHits, context.queryResult().getMaxScore())); } catch (IOException e) { throw ExceptionsHelper.convertToElastic(e); } diff --git a/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java b/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java index 036c0b97cca..2dbb52d547f 100644 --- a/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java +++ b/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java @@ -565,7 +565,7 @@ public class IndicesRequestIT extends ESIntegTestCase { SearchRequest searchRequest = new SearchRequest(randomIndicesOrAliases).searchType(SearchType.QUERY_THEN_FETCH); SearchResponse searchResponse = internalCluster().coordOnlyNodeClient().search(searchRequest).actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L)); clearInterceptedActions(); assertSameIndices(searchRequest, SearchTransportService.QUERY_ACTION_NAME, SearchTransportService.FETCH_ID_ACTION_NAME); @@ -586,7 +586,7 @@ public class IndicesRequestIT extends ESIntegTestCase { SearchRequest searchRequest = new SearchRequest(randomIndicesOrAliases).searchType(SearchType.DFS_QUERY_THEN_FETCH); SearchResponse searchResponse = internalCluster().coordOnlyNodeClient().search(searchRequest).actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L)); clearInterceptedActions(); assertSameIndices(searchRequest, SearchTransportService.DFS_ACTION_NAME, SearchTransportService.QUERY_ID_ACTION_NAME, diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java index ad7b1c51b51..a2147544a87 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java @@ -757,13 +757,13 @@ public class TasksIT extends ESIntegTestCase { .setSource(SearchSourceBuilder.searchSource().query(QueryBuilders.termQuery("task.action", taskInfo.getAction()))) .get(); - assertEquals(1L, searchResponse.getHits().getTotalHits()); + assertEquals(1L, searchResponse.getHits().getTotalHits().value); searchResponse = client().prepareSearch(TaskResultsService.TASK_INDEX).setTypes(TaskResultsService.TASK_TYPE) .setSource(SearchSourceBuilder.searchSource().query(QueryBuilders.termQuery("task.node", taskInfo.getTaskId().getNodeId()))) .get(); - assertEquals(1L, searchResponse.getHits().getTotalHits()); + assertEquals(1L, searchResponse.getHits().getTotalHits().value); GetTaskResponse getResponse = expectFinishedTask(taskId); assertEquals(result, getResponse.getTask().getResponseAsMap()); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java index 88a2cdf6c06..3253eb1dc1c 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java @@ -260,8 +260,8 @@ public class CreateIndexIT extends ESIntegTestCase { SearchResponse expected = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setQuery(new RangeQueryBuilder("index_version").from(indexVersion.get(), true)).get(); SearchResponse all = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()).get(); - assertEquals(expected + " vs. " + all, expected.getHits().getTotalHits(), all.getHits().getTotalHits()); - logger.info("total: {}", expected.getHits().getTotalHits()); + assertEquals(expected + " vs. " + all, expected.getHits().getTotalHits().value, all.getHits().getTotalHits().value); + logger.info("total: {}", expected.getHits().getTotalHits().value); } public void testRestartIndexCreationAfterFullClusterRestart() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java index 044f3263b4a..0cc83cee897 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java @@ -275,7 +275,7 @@ public class SplitIndexIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch(index).setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1_1"), ScoreMode.Avg)).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo((long)numDocs)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo((long)numDocs)); } public void assertAllUniqueDocs(SearchResponse response, int numDocs) { diff --git a/server/src/test/java/org/elasticsearch/action/bulk/BulkProcessorRetryIT.java b/server/src/test/java/org/elasticsearch/action/bulk/BulkProcessorRetryIT.java index f1731083ae3..515c539a884 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/BulkProcessorRetryIT.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/BulkProcessorRetryIT.java @@ -149,11 +149,11 @@ public class BulkProcessorRetryIT extends ESIntegTestCase { .get(); if (rejectedExecutionExpected) { - assertThat((int) results.getHits().getTotalHits(), lessThanOrEqualTo(numberOfAsyncOps)); + assertThat((int) results.getHits().getTotalHits().value, lessThanOrEqualTo(numberOfAsyncOps)); } else if (rejectedAfterAllRetries) { - assertThat((int) results.getHits().getTotalHits(), lessThan(numberOfAsyncOps)); + assertThat((int) results.getHits().getTotalHits().value, lessThan(numberOfAsyncOps)); } else { - assertThat((int) results.getHits().getTotalHits(), equalTo(numberOfAsyncOps)); + assertThat((int) results.getHits().getTotalHits().value, equalTo(numberOfAsyncOps)); } } diff --git a/server/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java b/server/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java index 9fe4f92ef2b..9378a2cdd86 100644 --- a/server/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.search; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.ActionListener; import org.elasticsearch.common.document.DocumentField; import org.elasticsearch.common.text.Text; @@ -53,7 +54,7 @@ public class ExpandSearchPhaseTests extends ESTestCase { for (int innerHitNum = 0; innerHitNum < numInnerHits; innerHitNum++) { SearchHits hits = new SearchHits(new SearchHit[]{new SearchHit(innerHitNum, "ID", new Text("type"), Collections.emptyMap()), new SearchHit(innerHitNum + 1, "ID", new Text("type"), - Collections.emptyMap())}, 2, 1.0F); + Collections.emptyMap())}, new TotalHits(2, TotalHits.Relation.EQUAL_TO), 1.0F); collapsedHits.add(hits); } @@ -104,7 +105,7 @@ public class ExpandSearchPhaseTests extends ESTestCase { SearchHits hits = new SearchHits(new SearchHit[]{new SearchHit(1, "ID", new Text("type"), Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(collapseValue))))}, - 1, 1.0F); + new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F); InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1); AtomicReference reference = new AtomicReference<>(); ExpandSearchPhase phase = new ExpandSearchPhase(mockSearchPhaseContext, internalSearchResponse, (r) -> @@ -136,7 +137,7 @@ public class ExpandSearchPhaseTests extends ESTestCase { SearchHits collapsedHits = new SearchHits(new SearchHit[]{new SearchHit(2, "ID", new Text("type"), Collections.emptyMap()), new SearchHit(3, "ID", new Text("type"), - Collections.emptyMap())}, 1, 1.0F); + Collections.emptyMap())}, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F); MockSearchPhaseContext mockSearchPhaseContext = new MockSearchPhaseContext(1); String collapseValue = randomBoolean() ? null : "boom"; mockSearchPhaseContext.getRequest().source(new SearchSourceBuilder() @@ -159,8 +160,8 @@ public class ExpandSearchPhaseTests extends ESTestCase { SearchHits hits = new SearchHits(new SearchHit[]{new SearchHit(1, "ID", new Text("type"), Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(collapseValue)))), new SearchHit(2, "ID2", new Text("type"), - Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(collapseValue))))}, 1, - 1.0F); + Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(collapseValue))))}, + new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F); InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1); AtomicReference reference = new AtomicReference<>(); ExpandSearchPhase phase = new ExpandSearchPhase(mockSearchPhaseContext, internalSearchResponse, r -> @@ -191,7 +192,8 @@ public class ExpandSearchPhaseTests extends ESTestCase { SearchHits hits = new SearchHits(new SearchHit[]{new SearchHit(1, "ID", new Text("type"), Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(null)))), new SearchHit(2, "ID2", new Text("type"), - Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(null))))}, 1, 1.0F); + Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(null))))}, + new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F); InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1); AtomicReference reference = new AtomicReference<>(); ExpandSearchPhase phase = new ExpandSearchPhase(mockSearchPhaseContext, internalSearchResponse, r -> @@ -219,7 +221,7 @@ public class ExpandSearchPhaseTests extends ESTestCase { mockSearchPhaseContext.getRequest().source(new SearchSourceBuilder() .collapse(new CollapseBuilder("someField").setInnerHits(new InnerHitBuilder().setName("foobarbaz")))); - SearchHits hits = new SearchHits(new SearchHit[0], 1, 1.0f); + SearchHits hits = new SearchHits(new SearchHit[0], new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0f); InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1); AtomicReference reference = new AtomicReference<>(); ExpandSearchPhase phase = new ExpandSearchPhase(mockSearchPhaseContext, internalSearchResponse, r -> @@ -259,7 +261,7 @@ public class ExpandSearchPhaseTests extends ESTestCase { .preference("foobar") .routing("baz"); - SearchHits hits = new SearchHits(new SearchHit[0], 1, 1.0f); + SearchHits hits = new SearchHits(new SearchHit[0], new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0f); InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1); AtomicReference reference = new AtomicReference<>(); ExpandSearchPhase phase = new ExpandSearchPhase(mockSearchPhaseContext, internalSearchResponse, r -> diff --git a/server/src/test/java/org/elasticsearch/action/search/FetchSearchPhaseTests.java b/server/src/test/java/org/elasticsearch/action/search/FetchSearchPhaseTests.java index 3db14ec19b8..b00c7f0bb15 100644 --- a/server/src/test/java/org/elasticsearch/action/search/FetchSearchPhaseTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/FetchSearchPhaseTests.java @@ -60,7 +60,7 @@ public class FetchSearchPhaseTests extends ESTestCase { new ScoreDoc[] {new ScoreDoc(42, 1.0F)}), 1.0F), new DocValueFormat[0]); queryResult.size(1); FetchSearchResult fetchResult = new FetchSearchResult(); - fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(42)}, 1, 1.0F)); + fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(42)}, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F)); QueryFetchSearchResult fetchSearchResult = new QueryFetchSearchResult(queryResult, fetchResult); fetchSearchResult.setShardIndex(0); results.consumeResult(fetchSearchResult); @@ -80,7 +80,7 @@ public class FetchSearchPhaseTests extends ESTestCase { phase.run(); mockSearchPhaseContext.assertNoFailure(); assertNotNull(responseRef.get()); - assertEquals(numHits, responseRef.get().getHits().totalHits); + assertEquals(numHits, responseRef.get().getHits().getTotalHits().value); if (numHits != 0) { assertEquals(42, responseRef.get().getHits().getAt(0).docId()); } @@ -115,10 +115,12 @@ public class FetchSearchPhaseTests extends ESTestCase { SearchActionListener listener) { FetchSearchResult fetchResult = new FetchSearchResult(); if (request.id() == 321) { - fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(84)}, 1, 2.0F)); + fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(84)}, + new TotalHits(1, TotalHits.Relation.EQUAL_TO), 2.0F)); } else { assertEquals(123, request.id()); - fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(42)}, 1, 1.0F)); + fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(42)}, + new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F)); } listener.onResponse(fetchResult); } @@ -135,7 +137,7 @@ public class FetchSearchPhaseTests extends ESTestCase { phase.run(); mockSearchPhaseContext.assertNoFailure(); assertNotNull(responseRef.get()); - assertEquals(2, responseRef.get().getHits().totalHits); + assertEquals(2, responseRef.get().getHits().getTotalHits().value); assertEquals(84, responseRef.get().getHits().getAt(0).docId()); assertEquals(42, responseRef.get().getHits().getAt(1).docId()); assertEquals(0, responseRef.get().getFailedShards()); @@ -171,7 +173,8 @@ public class FetchSearchPhaseTests extends ESTestCase { SearchActionListener listener) { if (request.id() == 321) { FetchSearchResult fetchResult = new FetchSearchResult(); - fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(84)}, 1, 2.0F)); + fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(84)}, + new TotalHits(1, TotalHits.Relation.EQUAL_TO), 2.0F)); listener.onResponse(fetchResult); } else { listener.onFailure(new MockDirectoryWrapper.FakeIOException()); @@ -191,7 +194,7 @@ public class FetchSearchPhaseTests extends ESTestCase { phase.run(); mockSearchPhaseContext.assertNoFailure(); assertNotNull(responseRef.get()); - assertEquals(2, responseRef.get().getHits().totalHits); + assertEquals(2, responseRef.get().getHits().getTotalHits().value); assertEquals(84, responseRef.get().getHits().getAt(0).docId()); assertEquals(1, responseRef.get().getFailedShards()); assertEquals(1, responseRef.get().getSuccessfulShards()); @@ -225,7 +228,8 @@ public class FetchSearchPhaseTests extends ESTestCase { SearchActionListener listener) { new Thread(() -> { FetchSearchResult fetchResult = new FetchSearchResult(); - fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit((int) (request.id()+1))}, 1, 100F)); + fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit((int) (request.id()+1))}, + new TotalHits(1, TotalHits.Relation.EQUAL_TO), 100F)); listener.onResponse(fetchResult); }).start(); } @@ -245,7 +249,7 @@ public class FetchSearchPhaseTests extends ESTestCase { latch.await(); mockSearchPhaseContext.assertNoFailure(); assertNotNull(responseRef.get()); - assertEquals(numHits, responseRef.get().getHits().totalHits); + assertEquals(numHits, responseRef.get().getHits().getTotalHits().value); assertEquals(Math.min(numHits, resultSetSize), responseRef.get().getHits().getHits().length); SearchHit[] hits = responseRef.get().getHits().getHits(); for (int i = 0; i < hits.length; i++) { @@ -291,10 +295,12 @@ public class FetchSearchPhaseTests extends ESTestCase { throw new RuntimeException("BOOM"); } if (request.id() == 321) { - fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(84)}, 1, 2.0F)); + fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(84)}, + new TotalHits(1, TotalHits.Relation.EQUAL_TO), 2.0F)); } else { assertEquals(request, 123); - fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(42)}, 1, 1.0F)); + fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(42)}, + new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F)); } listener.onResponse(fetchResult); } @@ -343,7 +349,8 @@ public class FetchSearchPhaseTests extends ESTestCase { SearchActionListener listener) { FetchSearchResult fetchResult = new FetchSearchResult(); if (request.id() == 321) { - fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(84)}, 1, 2.0F)); + fetchResult.hits(new SearchHits(new SearchHit[] {new SearchHit(84)}, + new TotalHits(1, TotalHits.Relation.EQUAL_TO), 2.0F)); } else { fail("requestID 123 should not be fetched but was"); } @@ -362,7 +369,7 @@ public class FetchSearchPhaseTests extends ESTestCase { phase.run(); mockSearchPhaseContext.assertNoFailure(); assertNotNull(responseRef.get()); - assertEquals(2, responseRef.get().getHits().totalHits); + assertEquals(2, responseRef.get().getHits().getTotalHits().value); assertEquals(1, responseRef.get().getHits().getHits().length); assertEquals(84, responseRef.get().getHits().getAt(0).docId()); assertEquals(0, responseRef.get().getFailedShards()); diff --git a/server/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java b/server/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java index f4cb7d224d2..d87ddc84831 100644 --- a/server/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java @@ -126,7 +126,8 @@ public class SearchPhaseControllerTests extends ESTestCase { assertEquals(sortedDocs[i].score, sortedDocs2[i].score, 0.0f); } assertEquals(topDocsStats.maxScore, topDocsStats2.maxScore, 0.0f); - assertEquals(topDocsStats.totalHits, topDocsStats2.totalHits); + assertEquals(topDocsStats.getTotalHits().value, topDocsStats2.getTotalHits().value); + assertEquals(topDocsStats.getTotalHits().relation, topDocsStats2.getTotalHits().relation); assertEquals(topDocsStats.fetchHits, topDocsStats2.fetchHits); } @@ -157,7 +158,7 @@ public class SearchPhaseControllerTests extends ESTestCase { reducedQueryPhase, searchPhaseResultAtomicArray.asList(), searchPhaseResultAtomicArray::get); if (trackTotalHits == false) { - assertThat(mergedResponse.hits.totalHits, equalTo(-1L)); + assertNull(mergedResponse.hits.getTotalHits()); } int suggestSize = 0; for (Suggest.Suggestion s : reducedQueryPhase.suggest) { @@ -283,7 +284,7 @@ public class SearchPhaseControllerTests extends ESTestCase { } } SearchHit[] hits = searchHits.toArray(new SearchHit[searchHits.size()]); - fetchSearchResult.hits(new SearchHits(hits, hits.length, maxScore)); + fetchSearchResult.hits(new SearchHits(hits, new TotalHits(hits.length, Relation.EQUAL_TO), maxScore)); fetchResults.set(shardIndex, fetchSearchResult); } return fetchResults; @@ -375,7 +376,7 @@ public class SearchPhaseControllerTests extends ESTestCase { assertEquals(max.get(), internalMax.getValue(), 0.0D); assertEquals(1, reduce.scoreDocs.length); assertEquals(max.get(), reduce.maxScore, 0.0f); - assertEquals(expectedNumResults, reduce.totalHits); + assertEquals(expectedNumResults, reduce.totalHits.value); assertEquals(max.get(), reduce.scoreDocs[0].score, 0.0f); } @@ -407,7 +408,7 @@ public class SearchPhaseControllerTests extends ESTestCase { assertEquals(max.get(), internalMax.getValue(), 0.0D); assertEquals(0, reduce.scoreDocs.length); assertEquals(max.get(), reduce.maxScore, 0.0f); - assertEquals(expectedNumResults, reduce.totalHits); + assertEquals(expectedNumResults, reduce.totalHits.value); } @@ -436,7 +437,7 @@ public class SearchPhaseControllerTests extends ESTestCase { SearchPhaseController.ReducedQueryPhase reduce = consumer.reduce(); assertEquals(1, reduce.scoreDocs.length); assertEquals(max.get(), reduce.maxScore, 0.0f); - assertEquals(expectedNumResults, reduce.totalHits); + assertEquals(expectedNumResults, reduce.totalHits.value); assertEquals(max.get(), reduce.scoreDocs[0].score, 0.0f); } @@ -500,7 +501,7 @@ public class SearchPhaseControllerTests extends ESTestCase { SearchPhaseController.ReducedQueryPhase reduce = consumer.reduce(); assertEquals(5, reduce.scoreDocs.length); assertEquals(100.f, reduce.maxScore, 0.0f); - assertEquals(12, reduce.totalHits); + assertEquals(12, reduce.totalHits.value); assertEquals(95.0f, reduce.scoreDocs[0].score, 0.0f); assertEquals(94.0f, reduce.scoreDocs[1].score, 0.0f); assertEquals(93.0f, reduce.scoreDocs[2].score, 0.0f); diff --git a/server/src/test/java/org/elasticsearch/action/search/SearchResponseTests.java b/server/src/test/java/org/elasticsearch/action/search/SearchResponseTests.java index d6fbf59d941..2feac5d53d9 100644 --- a/server/src/test/java/org/elasticsearch/action/search/SearchResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/SearchResponseTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.search; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -213,7 +214,10 @@ public class SearchResponseTests extends ESTestCase { SearchHit[] hits = new SearchHit[] { hit }; { SearchResponse response = new SearchResponse( - new InternalSearchResponse(new SearchHits(hits, 100, 1.5f), null, null, null, false, null, 1), null, 0, 0, 0, 0, + new InternalSearchResponse(new SearchHits(hits, new TotalHits(100, TotalHits.Relation.EQUAL_TO), 1.5f), null, null, + null, false, null, 1), + null, 0 + , 0, 0, 0, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY); StringBuilder expectedString = new StringBuilder(); expectedString.append("{"); @@ -229,7 +233,7 @@ public class SearchResponseTests extends ESTestCase { } expectedString.append("\"hits\":"); { - expectedString.append("{\"total\":100,"); + expectedString.append("{\"total\":{\"value\":100,\"relation\":\"eq\"},"); expectedString.append("\"max_score\":1.5,"); expectedString.append("\"hits\":[{\"_type\":\"type\",\"_id\":\"id1\",\"_score\":2.0}]}"); } @@ -239,8 +243,10 @@ public class SearchResponseTests extends ESTestCase { } { SearchResponse response = new SearchResponse( - new InternalSearchResponse(new SearchHits(hits, 100, 1.5f), null, null, null, false, null, 1), null, 0, 0, 0, 0, - ShardSearchFailure.EMPTY_ARRAY, new SearchResponse.Clusters(5, 3, 2)); + new InternalSearchResponse( + new SearchHits(hits, new TotalHits(100, TotalHits.Relation.EQUAL_TO), 1.5f), null, null, null, false, null, 1 + ), + null, 0, 0, 0, 0, ShardSearchFailure.EMPTY_ARRAY, new SearchResponse.Clusters(5, 3, 2)); StringBuilder expectedString = new StringBuilder(); expectedString.append("{"); { @@ -261,7 +267,7 @@ public class SearchResponseTests extends ESTestCase { } expectedString.append("\"hits\":"); { - expectedString.append("{\"total\":100,"); + expectedString.append("{\"total\":{\"value\":100,\"relation\":\"eq\"},"); expectedString.append("\"max_score\":1.5,"); expectedString.append("\"hits\":[{\"_type\":\"type\",\"_id\":\"id1\",\"_score\":2.0}]}"); } @@ -279,7 +285,12 @@ public class SearchResponseTests extends ESTestCase { StreamInput.wrap(bytesStreamOutput.bytes().toBytesRef().bytes), namedWriteableRegistry)) { SearchResponse serialized = new SearchResponse(); serialized.readFrom(in); - assertEquals(searchResponse.getHits().totalHits, serialized.getHits().totalHits); + if (searchResponse.getHits().getTotalHits() == null) { + assertNull(serialized.getHits().getTotalHits()); + } else { + assertEquals(searchResponse.getHits().getTotalHits().value, serialized.getHits().getTotalHits().value); + assertEquals(searchResponse.getHits().getTotalHits().relation, serialized.getHits().getTotalHits().relation); + } assertEquals(searchResponse.getHits().getHits().length, serialized.getHits().getHits().length); assertEquals(searchResponse.getNumReducePhases(), serialized.getNumReducePhases()); assertEquals(searchResponse.getFailedShards(), serialized.getFailedShards()); diff --git a/server/src/test/java/org/elasticsearch/action/support/master/IndexingMasterFailoverIT.java b/server/src/test/java/org/elasticsearch/action/support/master/IndexingMasterFailoverIT.java index c6fb7c49802..2865201f0f9 100644 --- a/server/src/test/java/org/elasticsearch/action/support/master/IndexingMasterFailoverIT.java +++ b/server/src/test/java/org/elasticsearch/action/support/master/IndexingMasterFailoverIT.java @@ -141,6 +141,6 @@ public class IndexingMasterFailoverIT extends ESIntegTestCase { ensureGreen("myindex"); refresh(); - assertThat(client().prepareSearch("myindex").get().getHits().getTotalHits(), equalTo(10L)); + assertThat(client().prepareSearch("myindex").get().getHits().getTotalHits().value, equalTo(10L)); } } diff --git a/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java b/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java index e8c152abdc2..122b305df97 100644 --- a/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java +++ b/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java @@ -321,32 +321,32 @@ public class IndexAliasesIT extends ESIntegTestCase { logger.info("--> checking filtering alias for two indices"); SearchResponse searchResponse = client().prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).get(); assertHits(searchResponse.getHits(), "1", "5"); - assertThat(client().prepareSearch("foos").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch("foos").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(2L)); logger.info("--> checking filtering alias for one index"); searchResponse = client().prepareSearch("bars").setQuery(QueryBuilders.matchAllQuery()).get(); assertHits(searchResponse.getHits(), "2"); - assertThat(client().prepareSearch("bars").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch("bars").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(1L)); logger.info("--> checking filtering alias for two indices and one complete index"); searchResponse = client().prepareSearch("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).get(); assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5"); - assertThat(client().prepareSearch("foos", "test1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(5L)); + assertThat(client().prepareSearch("foos", "test1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L)); logger.info("--> checking filtering alias for two indices and non-filtering alias for one index"); searchResponse = client().prepareSearch("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).get(); assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5"); - assertThat(client().prepareSearch("foos", "aliasToTest1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(5L)); + assertThat(client().prepareSearch("foos", "aliasToTest1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L)); logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices"); searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(8L)); - assertThat(client().prepareSearch("foos", "aliasToTests").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(8L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(8L)); + assertThat(client().prepareSearch("foos", "aliasToTests").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(8L)); logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices"); searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.termQuery("name", "something")).get(); assertHits(searchResponse.getHits(), "4", "8"); - assertThat(client().prepareSearch("foos", "aliasToTests").setSize(0).setQuery(QueryBuilders.termQuery("name", "something")).get().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch("foos", "aliasToTests").setSize(0).setQuery(QueryBuilders.termQuery("name", "something")).get().getHits().getTotalHits().value, equalTo(2L)); } public void testSearchingFilteringAliasesMultipleIndices() throws Exception { @@ -390,27 +390,27 @@ public class IndexAliasesIT extends ESIntegTestCase { logger.info("--> checking filtering alias for multiple indices"); SearchResponse searchResponse = client().prepareSearch("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).get(); assertHits(searchResponse.getHits(), "21", "31", "13", "33"); - assertThat(client().prepareSearch("filter23", "filter13").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(4L)); + assertThat(client().prepareSearch("filter23", "filter13").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(4L)); searchResponse = client().prepareSearch("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).get(); assertHits(searchResponse.getHits(), "21", "31", "11", "12", "13"); - assertThat(client().prepareSearch("filter23", "filter1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(5L)); + assertThat(client().prepareSearch("filter23", "filter1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L)); searchResponse = client().prepareSearch("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).get(); assertHits(searchResponse.getHits(), "11", "12", "13", "33"); - assertThat(client().prepareSearch("filter13", "filter1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(4L)); + assertThat(client().prepareSearch("filter13", "filter1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(4L)); searchResponse = client().prepareSearch("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).get(); assertHits(searchResponse.getHits(), "11", "12", "13", "21", "31", "33"); - assertThat(client().prepareSearch("filter13", "filter1", "filter23").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(6L)); + assertThat(client().prepareSearch("filter13", "filter1", "filter23").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(6L)); searchResponse = client().prepareSearch("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).get(); assertHits(searchResponse.getHits(), "21", "22", "23", "31", "13", "33"); - assertThat(client().prepareSearch("filter23", "filter13", "test2").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(6L)); + assertThat(client().prepareSearch("filter23", "filter13", "test2").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(6L)); searchResponse = client().prepareSearch("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).get(); assertHits(searchResponse.getHits(), "11", "12", "13", "21", "22", "23", "31", "33"); - assertThat(client().prepareSearch("filter23", "filter13", "test1", "test2").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(8L)); + assertThat(client().prepareSearch("filter23", "filter13", "test1", "test2").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(8L)); } public void testDeletingByQueryFilteringAliases() throws Exception { @@ -447,7 +447,7 @@ public class IndexAliasesIT extends ESIntegTestCase { refresh(); logger.info("--> checking counts before delete"); - assertThat(client().prepareSearch("bars").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch("bars").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(1L)); } public void testDeleteAliases() throws Exception { @@ -1020,7 +1020,7 @@ public class IndexAliasesIT extends ESIntegTestCase { } private void assertHits(SearchHits hits, String... ids) { - assertThat(hits.getTotalHits(), equalTo((long) ids.length)); + assertThat(hits.getTotalHits().value, equalTo((long) ids.length)); Set hitIds = new HashSet<>(); for (SearchHit hit : hits.getHits()) { hitIds.add(hit.getId()); diff --git a/server/src/test/java/org/elasticsearch/broadcast/BroadcastActionsIT.java b/server/src/test/java/org/elasticsearch/broadcast/BroadcastActionsIT.java index d6f716adce5..ab9ac6075cf 100644 --- a/server/src/test/java/org/elasticsearch/broadcast/BroadcastActionsIT.java +++ b/server/src/test/java/org/elasticsearch/broadcast/BroadcastActionsIT.java @@ -56,7 +56,7 @@ public class BroadcastActionsIT extends ESIntegTestCase { SearchResponse countResponse = client().prepareSearch("test").setSize(0) .setQuery(termQuery("_type", "type1")) .get(); - assertThat(countResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(countResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(countResponse.getTotalShards(), equalTo(numShards.numPrimaries)); assertThat(countResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries)); assertThat(countResponse.getFailedShards(), equalTo(0)); diff --git a/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java b/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java index 72b92074904..cec4e9b36fa 100644 --- a/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java @@ -125,7 +125,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase { logger.info("--> verify we the data back"); for (int i = 0; i < 10; i++) { assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()) - .execute().actionGet().getHits().getTotalHits(), equalTo(100L)); + .execute().actionGet().getHits().getTotalHits().value, equalTo(100L)); } internalCluster().stopCurrentMasterNode(); diff --git a/server/src/test/java/org/elasticsearch/cluster/allocation/FilteringAllocationIT.java b/server/src/test/java/org/elasticsearch/cluster/allocation/FilteringAllocationIT.java index 90ba6cbf890..6e5af59c2ae 100644 --- a/server/src/test/java/org/elasticsearch/cluster/allocation/FilteringAllocationIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/allocation/FilteringAllocationIT.java @@ -66,7 +66,7 @@ public class FilteringAllocationIT extends ESIntegTestCase { } client().admin().indices().prepareRefresh().execute().actionGet(); assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet() - .getHits().getTotalHits(), equalTo(100L)); + .getHits().getTotalHits().value, equalTo(100L)); logger.info("--> decommission the second node"); client().admin().cluster().prepareUpdateSettings() @@ -86,7 +86,7 @@ public class FilteringAllocationIT extends ESIntegTestCase { client().admin().indices().prepareRefresh().execute().actionGet(); assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()) - .execute().actionGet().getHits().getTotalHits(), equalTo(100L)); + .execute().actionGet().getHits().getTotalHits().value, equalTo(100L)); } public void testDisablingAllocationFiltering() throws Exception { @@ -109,7 +109,7 @@ public class FilteringAllocationIT extends ESIntegTestCase { } client().admin().indices().prepareRefresh().execute().actionGet(); assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()) - .execute().actionGet().getHits().getTotalHits(), equalTo(100L)); + .execute().actionGet().getHits().getTotalHits().value, equalTo(100L)); ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); IndexRoutingTable indexRoutingTable = clusterState.routingTable().index("test"); int numShardsOnNode1 = 0; diff --git a/server/src/test/java/org/elasticsearch/discovery/ClusterDisruptionCleanSettingsIT.java b/server/src/test/java/org/elasticsearch/discovery/ClusterDisruptionCleanSettingsIT.java index 2d0604d8d28..2ad951312fa 100644 --- a/server/src/test/java/org/elasticsearch/discovery/ClusterDisruptionCleanSettingsIT.java +++ b/server/src/test/java/org/elasticsearch/discovery/ClusterDisruptionCleanSettingsIT.java @@ -71,6 +71,6 @@ public class ClusterDisruptionCleanSettingsIT extends ESIntegTestCase { IndicesStoreIntegrationIT.relocateAndBlockCompletion(logger, "test", 0, node_1, node_2); // now search for the documents and see if we get a reply - assertThat(client().prepareSearch().setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client().prepareSearch().setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); } } diff --git a/server/src/test/java/org/elasticsearch/document/DocumentActionsIT.java b/server/src/test/java/org/elasticsearch/document/DocumentActionsIT.java index cfcb48f4a48..c2cff5a326c 100644 --- a/server/src/test/java/org/elasticsearch/document/DocumentActionsIT.java +++ b/server/src/test/java/org/elasticsearch/document/DocumentActionsIT.java @@ -165,7 +165,7 @@ public class DocumentActionsIT extends ESIntegTestCase { SearchResponse countResponse = client().prepareSearch("test").setSize(0).setQuery(termQuery("_type", "type1")) .execute().actionGet(); assertNoFailures(countResponse); - assertThat(countResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(countResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(countResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries)); assertThat(countResponse.getFailedShards(), equalTo(0)); @@ -173,7 +173,7 @@ public class DocumentActionsIT extends ESIntegTestCase { countResponse = client().prepareSearch("test").setSize(0).execute().actionGet(); assertThat("Failures " + countResponse.getShardFailures(), countResponse.getShardFailures() == null ? 0 : countResponse.getShardFailures().length, equalTo(0)); - assertThat(countResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(countResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(countResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries)); assertThat(countResponse.getFailedShards(), equalTo(0)); } diff --git a/server/src/test/java/org/elasticsearch/index/fieldstats/FieldStatsProviderRefreshTests.java b/server/src/test/java/org/elasticsearch/index/fieldstats/FieldStatsProviderRefreshTests.java index e742afb6141..c8ced3981d1 100644 --- a/server/src/test/java/org/elasticsearch/index/fieldstats/FieldStatsProviderRefreshTests.java +++ b/server/src/test/java/org/elasticsearch/index/fieldstats/FieldStatsProviderRefreshTests.java @@ -57,14 +57,14 @@ public class FieldStatsProviderRefreshTests extends ESSingleNodeTestCase { final SearchResponse r1 = client().prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("s").gte("a").lte("g")).get(); assertSearchResponse(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(3L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(3L)); assertRequestCacheStats(0, 1); // Search again and check it hits the cache final SearchResponse r2 = client().prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("s").gte("a").lte("g")).get(); assertSearchResponse(r2); - assertThat(r2.getHits().getTotalHits(), equalTo(3L)); + assertThat(r2.getHits().getTotalHits().value, equalTo(3L)); assertRequestCacheStats(1, 1); // Index some more documents in the query range and refresh @@ -76,7 +76,7 @@ public class FieldStatsProviderRefreshTests extends ESSingleNodeTestCase { final SearchResponse r3 = client().prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("s").gte("a").lte("g")).get(); assertSearchResponse(r3); - assertThat(r3.getHits().getTotalHits(), equalTo(5L)); + assertThat(r3.getHits().getTotalHits().value, equalTo(5L)); assertRequestCacheStats(1, 2); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperIntegrationIT.java b/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperIntegrationIT.java index 0015919b674..28adee6782d 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperIntegrationIT.java @@ -62,7 +62,7 @@ public class CopyToMapperIntegrationIT extends ESIntegTestCase { .collectMode(aggCollectionMode)) .execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo((long) recordCount)); + assertThat(response.getHits().getTotalHits().value, equalTo((long) recordCount)); assertThat(((Terms) response.getAggregations().get("test")).getBuckets().size(), equalTo(recordCount + 1)); assertThat(((Terms) response.getAggregations().get("test_raw")).getBuckets().size(), equalTo(recordCount)); @@ -86,7 +86,7 @@ public class CopyToMapperIntegrationIT extends ESIntegTestCase { client().admin().indices().prepareRefresh("test-idx").execute().actionGet(); SearchResponse response = client().prepareSearch("test-idx") .setQuery(QueryBuilders.termQuery("root.top.child", "bar")).get(); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); } private XContentBuilder createDynamicTemplateMapping() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ExternalValuesMapperIntegrationIT.java b/server/src/test/java/org/elasticsearch/index/mapper/ExternalValuesMapperIntegrationIT.java index 48f07b6063c..e1158f77bd4 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ExternalValuesMapperIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ExternalValuesMapperIntegrationIT.java @@ -61,7 +61,7 @@ public class ExternalValuesMapperIntegrationIT extends ESIntegTestCase { .highlighter(new HighlightBuilder().field("*")) .execute().actionGet(); assertSearchResponse(response); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getHighlightFields().size(), equalTo(0)); // make sure it is not excluded when we explicitly provide the fieldname @@ -70,7 +70,7 @@ public class ExternalValuesMapperIntegrationIT extends ESIntegTestCase { .highlighter(new HighlightBuilder().field("field")) .execute().actionGet(); assertSearchResponse(response); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getHighlightFields().size(), equalTo(1)); assertThat(response.getHits().getAt(0).getHighlightFields().get("field").fragments()[0].string(), equalTo("Every day is " + "exactly the same")); @@ -81,7 +81,7 @@ public class ExternalValuesMapperIntegrationIT extends ESIntegTestCase { .highlighter(new HighlightBuilder().field("*").field("field")) .execute().actionGet(); assertSearchResponse(response); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getHighlightFields().size(), equalTo(1)); assertThat(response.getHits().getAt(0).getHighlightFields().get("field").fragments()[0].string(), equalTo("Every day is " + "exactly the same")); @@ -109,25 +109,25 @@ public class ExternalValuesMapperIntegrationIT extends ESIntegTestCase { .setPostFilter(QueryBuilders.termQuery("field.bool", "true")) .execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo((long) 1)); + assertThat(response.getHits().getTotalHits().value, equalTo((long) 1)); response = client().prepareSearch("test-idx") .setPostFilter(QueryBuilders.geoDistanceQuery("field.point").point(42.0, 51.0).distance("1km")) .execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo((long) 1)); + assertThat(response.getHits().getTotalHits().value, equalTo((long) 1)); response = client().prepareSearch("test-idx") .setPostFilter(QueryBuilders.geoShapeQuery("field.shape", new PointBuilder(-100, 45)).relation(ShapeRelation.WITHIN)) .execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo((long) 1)); + assertThat(response.getHits().getTotalHits().value, equalTo((long) 1)); response = client().prepareSearch("test-idx") .setPostFilter(QueryBuilders.termQuery("field.field", "foo")) .execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo((long) 1)); + assertThat(response.getHits().getTotalHits().value, equalTo((long) 1)); } public void testExternalValuesWithMultifield() throws Exception { @@ -157,6 +157,6 @@ public class ExternalValuesMapperIntegrationIT extends ESIntegTestCase { .setQuery(QueryBuilders.termQuery("f.g.raw", "FOO BAR")) .execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo((long) 1)); + assertThat(response.getHits().getTotalHits().value, equalTo((long) 1)); } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java index 8d2f0008992..1725f079e0e 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java @@ -344,11 +344,11 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { // query by geohash subfield SearchResponse searchResponse = client().prepareSearch().addStoredField("location.geohash") .setQuery(matchAllQuery()).execute().actionGet(); - assertEquals(numDocs, searchResponse.getHits().getTotalHits()); + assertEquals(numDocs, searchResponse.getHits().getTotalHits().value); // query by latlon subfield searchResponse = client().prepareSearch().addStoredField("location.latlon").setQuery(matchAllQuery()).execute().actionGet(); - assertEquals(numDocs, searchResponse.getHits().getTotalHits()); + assertEquals(numDocs, searchResponse.getHits().getTotalHits().value); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java b/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java index 1db40ac4026..d8066977fed 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java @@ -67,11 +67,11 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch("my-index") .setQuery(matchQuery("title", "multi")) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch("my-index") .setQuery(matchQuery("title.not_analyzed", "Multi fields")) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertAcked( client().admin().indices().preparePutMapping("my-index").setType("my-type") @@ -98,7 +98,7 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase { searchResponse = client().prepareSearch("my-index") .setQuery(matchQuery("title.uncased", "Multi")) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); } @SuppressWarnings("unchecked") @@ -127,9 +127,9 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase { SearchResponse countResponse = client().prepareSearch("my-index").setSize(0) .setQuery(constantScoreQuery(geoDistanceQuery("a").point(51, 19).distance(50, DistanceUnit.KILOMETERS))) .get(); - assertThat(countResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(countResponse.getHits().getTotalHits().value, equalTo(1L)); countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", point.geohash())).get(); - assertThat(countResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(countResponse.getHits().getTotalHits().value, equalTo(1L)); } @SuppressWarnings("unchecked") @@ -154,7 +154,7 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase { client().prepareIndex("my-index", "my-type", "1").setSource("a", "complete me").setRefreshPolicy(IMMEDIATE).get(); SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "complete me")).get(); - assertThat(countResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(countResponse.getHits().getTotalHits().value, equalTo(1L)); } @SuppressWarnings("unchecked") @@ -179,7 +179,7 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase { client().prepareIndex("my-index", "my-type", "1").setSource("a", "127.0.0.1").setRefreshPolicy(IMMEDIATE).get(); SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "127.0.0.1")).get(); - assertThat(countResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(countResponse.getHits().getTotalHits().value, equalTo(1L)); } private XContentBuilder createMappingSource(String fieldType) throws IOException { diff --git a/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java b/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java index 4042d33568d..dd14f5f8544 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java +++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java @@ -297,7 +297,7 @@ public class IndexShardIT extends ESSingleNodeTestCase { client().prepareIndex(INDEX, "bar", "1").setSource("{}", XContentType.JSON).setRefreshPolicy(IMMEDIATE).get(); SearchResponse resp = client().prepareSearch(INDEX).setQuery(matchAllQuery()).get(); - assertThat("found the hit", resp.getHits().getTotalHits(), equalTo(1L)); + assertThat("found the hit", resp.getHits().getTotalHits().value, equalTo(1L)); logger.info("--> closing the index [{}]", INDEX); client().admin().indices().prepareClose(INDEX).get(); @@ -307,7 +307,7 @@ public class IndexShardIT extends ESSingleNodeTestCase { ensureGreen(INDEX); resp = client().prepareSearch(INDEX).setQuery(matchAllQuery()).get(); - assertThat("found the hit", resp.getHits().getTotalHits(), equalTo(1L)); + assertThat("found the hit", resp.getHits().getTotalHits().value, equalTo(1L)); // Now, try closing and changing the settings @@ -332,7 +332,7 @@ public class IndexShardIT extends ESSingleNodeTestCase { ensureGreen(INDEX); resp = client().prepareSearch(INDEX).setQuery(matchAllQuery()).get(); - assertThat("found the hit", resp.getHits().getTotalHits(), equalTo(1L)); + assertThat("found the hit", resp.getHits().getTotalHits().value, equalTo(1L)); assertAcked(client().admin().indices().prepareDelete(INDEX)); assertAllIndicesRemovedAndDeletionCompleted(Collections.singleton(getInstanceFromNode(IndicesService.class))); @@ -689,7 +689,7 @@ public class IndexShardIT extends ESSingleNodeTestCase { started.countDown(); do { searchResponse = client().prepareSearch().get(); - } while (searchResponse.getHits().totalHits != totalNumDocs.get()); + } while (searchResponse.getHits().getTotalHits().value != totalNumDocs.get()); }); t.start(); started.await(); @@ -842,7 +842,7 @@ public class IndexShardIT extends ESSingleNodeTestCase { } } shard.refresh("test"); - assertThat(client().search(countRequest).actionGet().getHits().totalHits, equalTo(numDocs)); + assertThat(client().search(countRequest).actionGet().getHits().getTotalHits().value, equalTo(numDocs)); assertThat(shard.getLocalCheckpoint(), equalTo(shard.seqNoStats().getMaxSeqNo())); shard.resetEngineToGlobalCheckpoint(); final long moreDocs = between(10, 20); @@ -858,7 +858,7 @@ public class IndexShardIT extends ESSingleNodeTestCase { (long) searcher.reader().numDocs(), equalTo(numDocs + moreDocs)); } assertThat("numDocs=" + numDocs + " moreDocs=" + moreDocs, - client().search(countRequest).actionGet().getHits().totalHits, equalTo(numDocs + moreDocs)); + client().search(countRequest).actionGet().getHits().getTotalHits().value, equalTo(numDocs + moreDocs)); } } diff --git a/server/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java b/server/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java index 017fb360de5..91e73e53ebc 100644 --- a/server/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java +++ b/server/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java @@ -130,7 +130,7 @@ public class ExceptionRetryIT extends ESIntegTestCase { if (!found_duplicate_already) { SearchResponse dupIdResponse = client().prepareSearch("index").setQuery(termQuery("_id", searchResponse.getHits().getHits()[i].getId())).setExplain(true).get(); - assertThat(dupIdResponse.getHits().getTotalHits(), greaterThan(1L)); + assertThat(dupIdResponse.getHits().getTotalHits().value, greaterThan(1L)); logger.info("found a duplicate id:"); for (SearchHit hit : dupIdResponse.getHits()) { logger.info("Doc {} was found on shard {}", hit.getId(), hit.getShard().getShardId()); diff --git a/server/src/test/java/org/elasticsearch/indexing/IndexActionIT.java b/server/src/test/java/org/elasticsearch/indexing/IndexActionIT.java index ea2bf3f7199..0bf8fa698f4 100644 --- a/server/src/test/java/org/elasticsearch/indexing/IndexActionIT.java +++ b/server/src/test/java/org/elasticsearch/indexing/IndexActionIT.java @@ -69,8 +69,8 @@ public class IndexActionIT extends ESIntegTestCase { try { logger.debug("running search with all types"); SearchResponse response = client().prepareSearch("test").get(); - if (response.getHits().getTotalHits() != numOfDocs) { - final String message = "Count is " + response.getHits().getTotalHits() + " but " + numOfDocs + " was expected. " + if (response.getHits().getTotalHits().value != numOfDocs) { + final String message = "Count is " + response.getHits().getTotalHits().value + " but " + numOfDocs + " was expected. " + ElasticsearchAssertions.formatShardStatus(response); logger.error("{}. search response: \n{}", message, response); fail(message); @@ -84,8 +84,8 @@ public class IndexActionIT extends ESIntegTestCase { try { logger.debug("running search with a specific type"); SearchResponse response = client().prepareSearch("test").setTypes("type").get(); - if (response.getHits().getTotalHits() != numOfDocs) { - final String message = "Count is " + response.getHits().getTotalHits() + " but " + numOfDocs + " was expected. " + if (response.getHits().getTotalHits().value != numOfDocs) { + final String message = "Count is " + response.getHits().getTotalHits().value + " but " + numOfDocs + " was expected. " + ElasticsearchAssertions.formatShardStatus(response); logger.error("{}. search response: \n{}", message, response); fail(message); diff --git a/server/src/test/java/org/elasticsearch/indices/IndicesRequestCacheIT.java b/server/src/test/java/org/elasticsearch/indices/IndicesRequestCacheIT.java index 809d6475274..6d1db852a85 100644 --- a/server/src/test/java/org/elasticsearch/indices/IndicesRequestCacheIT.java +++ b/server/src/test/java/org/elasticsearch/indices/IndicesRequestCacheIT.java @@ -126,21 +126,21 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { final SearchResponse r1 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-19").lte("2016-03-25")).setPreFilterShardSize(Integer.MAX_VALUE).get(); ElasticsearchAssertions.assertAllSuccessful(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(7L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(7L)); assertCacheState(client, "index", 0, 5); final SearchResponse r2 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-20").lte("2016-03-26")) .setPreFilterShardSize(Integer.MAX_VALUE).get(); ElasticsearchAssertions.assertAllSuccessful(r2); - assertThat(r2.getHits().getTotalHits(), equalTo(7L)); + assertThat(r2.getHits().getTotalHits().value, equalTo(7L)); assertCacheState(client, "index", 3, 7); final SearchResponse r3 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-21").lte("2016-03-27")).setPreFilterShardSize(Integer.MAX_VALUE) .get(); ElasticsearchAssertions.assertAllSuccessful(r3); - assertThat(r3.getHits().getTotalHits(), equalTo(7L)); + assertThat(r3.getHits().getTotalHits().value, equalTo(7L)); assertCacheState(client, "index", 6, 9); } @@ -172,19 +172,19 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { final SearchResponse r1 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-19").lte("2016-03-28")).get(); ElasticsearchAssertions.assertAllSuccessful(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(8L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(8L)); assertCacheState(client, "index", 0, 1); final SearchResponse r2 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-19").lte("2016-03-28")).get(); ElasticsearchAssertions.assertAllSuccessful(r2); - assertThat(r2.getHits().getTotalHits(), equalTo(8L)); + assertThat(r2.getHits().getTotalHits().value, equalTo(8L)); assertCacheState(client, "index", 1, 1); final SearchResponse r3 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-19").lte("2016-03-28")).get(); ElasticsearchAssertions.assertAllSuccessful(r3); - assertThat(r3.getHits().getTotalHits(), equalTo(8L)); + assertThat(r3.getHits().getTotalHits().value, equalTo(8L)); assertCacheState(client, "index", 2, 1); } @@ -217,21 +217,21 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { .setQuery(QueryBuilders.rangeQuery("d").gte("2013-01-01T00:00:00").lte("now")) .get(); ElasticsearchAssertions.assertAllSuccessful(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(9L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(9L)); assertCacheState(client, "index", 0, 1); final SearchResponse r2 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("d").gte("2013-01-01T00:00:00").lte("now")) .get(); ElasticsearchAssertions.assertAllSuccessful(r2); - assertThat(r2.getHits().getTotalHits(), equalTo(9L)); + assertThat(r2.getHits().getTotalHits().value, equalTo(9L)); assertCacheState(client, "index", 1, 1); final SearchResponse r3 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("d").gte("2013-01-01T00:00:00").lte("now")) .get(); ElasticsearchAssertions.assertAllSuccessful(r3); - assertThat(r3.getHits().getTotalHits(), equalTo(9L)); + assertThat(r3.getHits().getTotalHits().value, equalTo(9L)); assertCacheState(client, "index", 2, 1); } @@ -274,7 +274,7 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { final SearchResponse r1 = client.prepareSearch("index-*").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("d").gte("now-7d/d").lte("now")).get(); ElasticsearchAssertions.assertAllSuccessful(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(8L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(8L)); assertCacheState(client, "index-1", 0, 1); assertCacheState(client, "index-2", 0, 1); // Because the query will INTERSECT with the 3rd index it will not be @@ -285,7 +285,7 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { final SearchResponse r2 = client.prepareSearch("index-*").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("d").gte("now-7d/d").lte("now")).get(); ElasticsearchAssertions.assertAllSuccessful(r2); - assertThat(r2.getHits().getTotalHits(), equalTo(8L)); + assertThat(r2.getHits().getTotalHits().value, equalTo(8L)); assertCacheState(client, "index-1", 1, 1); assertCacheState(client, "index-2", 1, 1); assertCacheState(client, "index-3", 0, 0); @@ -293,7 +293,7 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { final SearchResponse r3 = client.prepareSearch("index-*").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("d").gte("now-7d/d").lte("now")).get(); ElasticsearchAssertions.assertAllSuccessful(r3); - assertThat(r3.getHits().getTotalHits(), equalTo(8L)); + assertThat(r3.getHits().getTotalHits().value, equalTo(8L)); assertCacheState(client, "index-1", 2, 1); assertCacheState(client, "index-2", 2, 1); assertCacheState(client, "index-3", 0, 0); @@ -331,14 +331,14 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { final SearchResponse r1 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(1) .setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-19").lte("2016-03-25")).get(); ElasticsearchAssertions.assertAllSuccessful(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(7L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(7L)); assertCacheState(client, "index", 0, 0); // If search type is DFS_QUERY_THEN_FETCH we should not cache final SearchResponse r2 = client.prepareSearch("index").setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-20").lte("2016-03-26")).get(); ElasticsearchAssertions.assertAllSuccessful(r2); - assertThat(r2.getHits().getTotalHits(), equalTo(7L)); + assertThat(r2.getHits().getTotalHits().value, equalTo(7L)); assertCacheState(client, "index", 0, 0); // If search type is DFS_QUERY_THEN_FETCH we should not cache even if @@ -346,7 +346,7 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { final SearchResponse r3 = client.prepareSearch("index").setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setSize(0) .setRequestCache(true).setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-20").lte("2016-03-26")).get(); ElasticsearchAssertions.assertAllSuccessful(r3); - assertThat(r3.getHits().getTotalHits(), equalTo(7L)); + assertThat(r3.getHits().getTotalHits().value, equalTo(7L)); assertCacheState(client, "index", 0, 0); // If the request has an non-filter aggregation containing now we should not cache @@ -354,14 +354,14 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { .setRequestCache(true).setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-20").lte("2016-03-26")) .addAggregation(dateRange("foo").field("s").addRange("now-10y", "now")).get(); ElasticsearchAssertions.assertAllSuccessful(r5); - assertThat(r5.getHits().getTotalHits(), equalTo(7L)); + assertThat(r5.getHits().getTotalHits().value, equalTo(7L)); assertCacheState(client, "index", 0, 0); // If size > 1 and cache flag is set on the request we should cache final SearchResponse r6 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(1) .setRequestCache(true).setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-21").lte("2016-03-27")).get(); ElasticsearchAssertions.assertAllSuccessful(r6); - assertThat(r6.getHits().getTotalHits(), equalTo(7L)); + assertThat(r6.getHits().getTotalHits().value, equalTo(7L)); assertCacheState(client, "index", 0, 2); // If the request has a filter aggregation containing now we should cache since it gets rewritten @@ -369,7 +369,7 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { .setRequestCache(true).setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-20").lte("2016-03-26")) .addAggregation(filter("foo", QueryBuilders.rangeQuery("s").from("now-10y").to("now"))).get(); ElasticsearchAssertions.assertAllSuccessful(r4); - assertThat(r4.getHits().getTotalHits(), equalTo(7L)); + assertThat(r4.getHits().getTotalHits().value, equalTo(7L)); assertCacheState(client, "index", 0, 4); } @@ -394,23 +394,23 @@ public class IndicesRequestCacheIT extends ESIntegTestCase { SearchResponse r1 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("created_at").gte("now-7d/d")).get(); ElasticsearchAssertions.assertAllSuccessful(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(1L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(1L)); assertCacheState(client, "index", 0, 1); r1 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0) .setQuery(QueryBuilders.rangeQuery("created_at").gte("now-7d/d")).get(); ElasticsearchAssertions.assertAllSuccessful(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(1L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(1L)); assertCacheState(client, "index", 1, 1); r1 = client.prepareSearch("last_week").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).get(); ElasticsearchAssertions.assertAllSuccessful(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(1L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(1L)); assertCacheState(client, "index", 1, 2); r1 = client.prepareSearch("last_week").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).get(); ElasticsearchAssertions.assertAllSuccessful(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(1L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(1L)); assertCacheState(client, "index", 2, 2); } diff --git a/server/src/test/java/org/elasticsearch/indices/flush/FlushIT.java b/server/src/test/java/org/elasticsearch/indices/flush/FlushIT.java index 774c50097d8..fc044e19150 100644 --- a/server/src/test/java/org/elasticsearch/indices/flush/FlushIT.java +++ b/server/src/test/java/org/elasticsearch/indices/flush/FlushIT.java @@ -204,12 +204,12 @@ public class FlushIT extends ESIntegTestCase { indexStats = client().admin().indices().prepareStats("test").get().getIndex("test"); assertFlushResponseEqualsShardStats(indexStats.getShards(), syncedFlushResult.getShardsResultPerIndex().get("test")); refresh(); - assertThat(client().prepareSearch().setSize(0).get().getHits().getTotalHits(), equalTo((long) numDocs.get())); - logger.info("indexed {} docs", client().prepareSearch().setSize(0).get().getHits().getTotalHits()); + assertThat(client().prepareSearch().setSize(0).get().getHits().getTotalHits().value, equalTo((long) numDocs.get())); + logger.info("indexed {} docs", client().prepareSearch().setSize(0).get().getHits().getTotalHits().value); logClusterState(); internalCluster().fullRestart(); ensureGreen(); - assertThat(client().prepareSearch().setSize(0).get().getHits().getTotalHits(), equalTo((long) numDocs.get())); + assertThat(client().prepareSearch().setSize(0).get().getHits().getTotalHits().value, equalTo((long) numDocs.get())); } private void assertFlushResponseEqualsShardStats(ShardStats[] shardsStats, List syncedFlushResults) { diff --git a/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java b/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java index c6dd9ec7c8f..7ac2ff659df 100644 --- a/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java @@ -86,7 +86,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase { RefreshResponse refreshResponse = client().admin().indices().prepareRefresh().execute().actionGet(); assertThat(refreshResponse.getFailedShards(), equalTo(0)); SearchResponse response = client().prepareSearch("test").setSize(0).execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo((long) recCount)); + assertThat(response.getHits().getTotalHits().value, equalTo((long) recCount)); logger.info("checking all the fields are in the mappings"); diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java b/server/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java index e3c9aaafc60..97207f28df4 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java @@ -538,7 +538,7 @@ public class IndexRecoveryIT extends ESIntegTestCase { indexRandom(true, docs); flush(); - assertThat(client().prepareSearch(name).setSize(0).get().getHits().getTotalHits(), equalTo((long) numDocs)); + assertThat(client().prepareSearch(name).setSize(0).get().getHits().getTotalHits().value, equalTo((long) numDocs)); return client().admin().indices().prepareStats(name).execute().actionGet(); } diff --git a/server/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java b/server/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java index 0a475242364..152429ae435 100644 --- a/server/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java +++ b/server/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java @@ -293,8 +293,8 @@ public class IndexStatsIT extends ESIntegTestCase { assertThat(client().admin().indices().prepareStats("idx").setRequestCache(true).get().getTotal().getRequestCache() .getMissCount(), equalTo(0L)); for (int i = 0; i < 10; i++) { - assertThat(client().prepareSearch("idx").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).get().getHits().getTotalHits(), - equalTo((long) numDocs)); + assertThat(client().prepareSearch("idx").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).get() + .getHits().getTotalHits().value, equalTo((long) numDocs)); assertThat(client().admin().indices().prepareStats("idx").setRequestCache(true).get().getTotal().getRequestCache(). getMemorySizeInBytes(), greaterThan(0L)); } @@ -320,8 +320,8 @@ public class IndexStatsIT extends ESIntegTestCase { }); for (int i = 0; i < 10; i++) { - assertThat(client().prepareSearch("idx").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).get().getHits().getTotalHits(), - equalTo((long) numDocs)); + assertThat(client().prepareSearch("idx").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).get() + .getHits().getTotalHits().value, equalTo((long) numDocs)); assertThat(client().admin().indices().prepareStats("idx").setRequestCache(true).get().getTotal().getRequestCache() .getMemorySizeInBytes(), greaterThan(0L)); } @@ -333,12 +333,12 @@ public class IndexStatsIT extends ESIntegTestCase { // test explicit request parameter assertThat(client().prepareSearch("idx").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setRequestCache(false).get() - .getHits().getTotalHits(), equalTo((long) numDocs)); + .getHits().getTotalHits().value, equalTo((long) numDocs)); assertThat(client().admin().indices().prepareStats("idx").setRequestCache(true).get().getTotal().getRequestCache() .getMemorySizeInBytes(), equalTo(0L)); assertThat(client().prepareSearch("idx").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setRequestCache(true).get() - .getHits().getTotalHits(), equalTo((long) numDocs)); + .getHits().getTotalHits().value, equalTo((long) numDocs)); assertThat(client().admin().indices().prepareStats("idx").setRequestCache(true).get().getTotal().getRequestCache() .getMemorySizeInBytes(), greaterThan(0L)); @@ -349,12 +349,12 @@ public class IndexStatsIT extends ESIntegTestCase { .setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), false))); assertThat(client().prepareSearch("idx").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).get() - .getHits().getTotalHits(), equalTo((long) numDocs)); + .getHits().getTotalHits().value, equalTo((long) numDocs)); assertThat(client().admin().indices().prepareStats("idx").setRequestCache(true).get().getTotal().getRequestCache() .getMemorySizeInBytes(), equalTo(0L)); assertThat(client().prepareSearch("idx").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setRequestCache(true).get() - .getHits().getTotalHits(), equalTo((long) numDocs)); + .getHits().getTotalHits().value, equalTo((long) numDocs)); assertThat(client().admin().indices().prepareStats("idx").setRequestCache(true).get().getTotal().getRequestCache() .getMemorySizeInBytes(), greaterThan(0L)); } diff --git a/server/src/test/java/org/elasticsearch/recovery/RecoveryWhileUnderLoadIT.java b/server/src/test/java/org/elasticsearch/recovery/RecoveryWhileUnderLoadIT.java index 720fd0acdf0..0d2235c30a4 100644 --- a/server/src/test/java/org/elasticsearch/recovery/RecoveryWhileUnderLoadIT.java +++ b/server/src/test/java/org/elasticsearch/recovery/RecoveryWhileUnderLoadIT.java @@ -276,7 +276,7 @@ public class RecoveryWhileUnderLoadIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch().setSize((int) numberOfDocs).setQuery(matchAllQuery()).addSort("id", SortOrder.ASC).get(); logSearchResponse(numberOfShards, numberOfDocs, i, searchResponse); iterationResults[i] = searchResponse; - if (searchResponse.getHits().getTotalHits() != numberOfDocs) { + if (searchResponse.getHits().getTotalHits().value != numberOfDocs) { error = true; } } @@ -312,7 +312,7 @@ public class RecoveryWhileUnderLoadIT extends ESIntegTestCase { boolean errorOccurred = false; for (int i = 0; i < iterations; i++) { SearchResponse searchResponse = client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(); - if (searchResponse.getHits().getTotalHits() != numberOfDocs) { + if (searchResponse.getHits().getTotalHits().value != numberOfDocs) { errorOccurred = true; } } @@ -337,7 +337,7 @@ public class RecoveryWhileUnderLoadIT extends ESIntegTestCase { if (searchResponse.getShardFailures() != null && searchResponse.getShardFailures().length > 0) { logger.info("iteration [{}] - shard failures: {}", iteration, Arrays.toString(searchResponse.getShardFailures())); } - logger.info("iteration [{}] - returned documents: {} (expected {})", iteration, searchResponse.getHits().getTotalHits(), numberOfDocs); + logger.info("iteration [{}] - returned documents: {} (expected {})", iteration, searchResponse.getHits().getTotalHits().value, numberOfDocs); } private void refreshAndAssert() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/recovery/RelocationIT.java b/server/src/test/java/org/elasticsearch/recovery/RelocationIT.java index df097b38a3d..b27e4fd229a 100644 --- a/server/src/test/java/org/elasticsearch/recovery/RelocationIT.java +++ b/server/src/test/java/org/elasticsearch/recovery/RelocationIT.java @@ -129,7 +129,7 @@ public class RelocationIT extends ESIntegTestCase { logger.info("--> verifying count"); client().admin().indices().prepareRefresh().execute().actionGet(); - assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().getTotalHits(), equalTo(20L)); + assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().getTotalHits().value, equalTo(20L)); logger.info("--> start another node"); final String node_2 = internalCluster().startNode(); @@ -146,7 +146,7 @@ public class RelocationIT extends ESIntegTestCase { logger.info("--> verifying count again..."); client().admin().indices().prepareRefresh().execute().actionGet(); - assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().getTotalHits(), equalTo(20L)); + assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().getTotalHits().value, equalTo(20L)); } @TestLogging("org.elasticsearch.action.bulk:TRACE,org.elasticsearch.action.search:TRACE") @@ -220,7 +220,7 @@ public class RelocationIT extends ESIntegTestCase { logger.info("--> START search test round {}", i + 1); SearchHits hits = client().prepareSearch("test").setQuery(matchAllQuery()).setSize((int) indexer.totalIndexedDocs()).storedFields().execute().actionGet().getHits(); ranOnce = true; - if (hits.getTotalHits() != indexer.totalIndexedDocs()) { + if (hits.getTotalHits().value != indexer.totalIndexedDocs()) { int[] hitIds = new int[(int) indexer.totalIndexedDocs()]; for (int hit = 0; hit < indexer.totalIndexedDocs(); hit++) { hitIds[hit] = hit + 1; @@ -236,7 +236,7 @@ public class RelocationIT extends ESIntegTestCase { logger.error("Missing id [{}]", value); }); } - assertThat(hits.getTotalHits(), equalTo(indexer.totalIndexedDocs())); + assertThat(hits.getTotalHits().value, equalTo(indexer.totalIndexedDocs())); logger.info("--> DONE search test round {}", i + 1); } @@ -336,9 +336,9 @@ public class RelocationIT extends ESIntegTestCase { SearchResponse response = client.prepareSearch("test").setPreference("_local").setSize(0).get(); assertNoFailures(response); if (expectedCount < 0) { - expectedCount = response.getHits().getTotalHits(); + expectedCount = response.getHits().getTotalHits().value; } else { - assertEquals(expectedCount, response.getHits().getTotalHits()); + assertEquals(expectedCount, response.getHits().getTotalHits().value); } } diff --git a/server/src/test/java/org/elasticsearch/routing/AliasRoutingIT.java b/server/src/test/java/org/elasticsearch/routing/AliasRoutingIT.java index 6b3b6a67a97..eceef54ccac 100644 --- a/server/src/test/java/org/elasticsearch/routing/AliasRoutingIT.java +++ b/server/src/test/java/org/elasticsearch/routing/AliasRoutingIT.java @@ -126,23 +126,23 @@ public class AliasRoutingIT extends ESIntegTestCase { logger.info("--> search with no routing, should fine one"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); } logger.info("--> search with wrong routing, should not find"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); - assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); - assertThat(client().prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); - assertThat(client().prepareSearch("alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); + assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); + assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); + assertThat(client().prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); + assertThat(client().prepareSearch("alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); } logger.info("--> search with correct routing, should find"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch().setSize(0).setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch("alias0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch("alias0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch().setSize(0).setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch("alias0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch("alias0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); } logger.info("--> indexing with id [2], and routing [1] using alias"); @@ -150,50 +150,50 @@ public class AliasRoutingIT extends ESIntegTestCase { logger.info("--> search with no routing, should fine two"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } logger.info("--> search with 0 routing, should find one"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch().setSize(0).setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch("alias0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch("alias0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch().setSize(0).setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch("alias0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch("alias0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); } logger.info("--> search with 1 routing, should find one"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch("alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch("alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); } logger.info("--> search with 0,1 indexRoutings , should find two"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch().setSize(0).setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch("alias01").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch("alias01").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch().setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch().setSize(0).setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch("alias01").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch("alias01").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } logger.info("--> search with two routing aliases , should find two"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch("alias0", "alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch("alias0", "alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch("alias0", "alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch("alias0", "alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } logger.info("--> search with alias0, alias1 and alias01, should find two"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch("alias0", "alias1", "alias01").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch("alias0", "alias1", "alias01").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch("alias0", "alias1", "alias01").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch("alias0", "alias1", "alias01").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } logger.info("--> search with test, alias0 and alias1, should find two"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch("test", "alias0", "alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch("test", "alias0", "alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch("test", "alias0", "alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch("test", "alias0", "alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } } @@ -242,20 +242,20 @@ public class AliasRoutingIT extends ESIntegTestCase { logger.info("--> search with alias-a1,alias-b0, should not find"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch("alias-a1", "alias-b0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); - assertThat(client().prepareSearch("alias-a1", "alias-b0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); + assertThat(client().prepareSearch("alias-a1", "alias-b0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); + assertThat(client().prepareSearch("alias-a1", "alias-b0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); } logger.info("--> search with alias-ab, should find two"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch("alias-ab").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch("alias-ab").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch("alias-ab").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch("alias-ab").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } logger.info("--> search with alias-a0,alias-b1 should find two"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch("alias-a0", "alias-b1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch("alias-a0", "alias-b1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch("alias-a0", "alias-b1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch("alias-a0", "alias-b1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } } @@ -279,7 +279,7 @@ public class AliasRoutingIT extends ESIntegTestCase { logger.info("--> search all on index_* should find two"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch("index_*").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch("index_*").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } } @@ -304,7 +304,7 @@ public class AliasRoutingIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch("index_*").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(1).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); logger.info("--> search all on index_* should find two"); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); //Let's make sure that, even though 2 docs are available, only one is returned according to the size we set in the request //Therefore the reduce phase has taken place, which proves that the QUERY_AND_FETCH search type wasn't erroneously forced. assertThat(searchResponse.getHits().getHits().length, equalTo(1)); @@ -324,8 +324,8 @@ public class AliasRoutingIT extends ESIntegTestCase { logger.info("--> verifying get and search with routing, should find"); for (int i = 0; i < 5; i++) { assertThat(client().prepareGet("test", "type1", "0").setRouting("3").execute().actionGet().isExists(), equalTo(true)); - assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); } logger.info("--> creating alias with routing [4]"); @@ -334,8 +334,8 @@ public class AliasRoutingIT extends ESIntegTestCase { logger.info("--> verifying search with wrong routing should not find"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); - assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); + assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); + assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); } logger.info("--> creating alias with search routing [3,4] and index routing 4"); @@ -350,8 +350,8 @@ public class AliasRoutingIT extends ESIntegTestCase { for (int i = 0; i < 5; i++) { assertThat(client().prepareGet("test", "type1", "0").setRouting("3").execute().actionGet().isExists(), equalTo(true)); assertThat(client().prepareGet("test", "type1", "1").setRouting("4").execute().actionGet().isExists(), equalTo(true)); - assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } } diff --git a/server/src/test/java/org/elasticsearch/routing/PartitionedRoutingIT.java b/server/src/test/java/org/elasticsearch/routing/PartitionedRoutingIT.java index 606745bedf5..248ced106b3 100644 --- a/server/src/test/java/org/elasticsearch/routing/PartitionedRoutingIT.java +++ b/server/src/test/java/org/elasticsearch/routing/PartitionedRoutingIT.java @@ -133,11 +133,11 @@ public class PartitionedRoutingIT extends ESIntegTestCase { .execute().actionGet(); logger.info("--> routed search on index [" + index + "] visited [" + response.getTotalShards() - + "] shards for routing [" + routing + "] and got hits [" + response.getHits().getTotalHits() + "]"); + + "] shards for routing [" + routing + "] and got hits [" + response.getHits().getTotalHits().value + "]"); assertTrue(response.getTotalShards() + " was not in " + expectedShards + " for " + index, expectedShards.contains(response.getTotalShards())); - assertEquals(expectedDocuments, response.getHits().getTotalHits()); + assertEquals(expectedDocuments, response.getHits().getTotalHits().value); Set found = new HashSet<>(); response.getHits().forEach(h -> found.add(h.getId())); @@ -158,7 +158,7 @@ public class PartitionedRoutingIT extends ESIntegTestCase { .execute().actionGet(); assertEquals(expectedShards, response.getTotalShards()); - assertEquals(expectedDocuments, response.getHits().getTotalHits()); + assertEquals(expectedDocuments, response.getHits().getTotalHits().value); Set found = new HashSet<>(); response.getHits().forEach(h -> found.add(h.getId())); diff --git a/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java b/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java index 6e812733904..ad8024e76b4 100644 --- a/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java +++ b/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java @@ -135,19 +135,19 @@ public class SimpleRoutingIT extends ESIntegTestCase { logger.info("--> search with no routing, should fine one"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); } logger.info("--> search with wrong routing, should not find"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); - assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); + assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); + assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); } logger.info("--> search with correct routing, should find"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch().setSize(0).setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch().setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch().setSize(0).setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); } String secondRoutingValue = "1"; @@ -156,32 +156,32 @@ public class SimpleRoutingIT extends ESIntegTestCase { logger.info("--> search with no routing, should fine two"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } logger.info("--> search with {} routing, should find one", routingValue); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch().setSize(0).setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch().setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch().setSize(0).setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); } logger.info("--> search with {} routing, should find one", secondRoutingValue); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); - assertThat(client().prepareSearch().setSize(0).setRouting(secondRoutingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(1L)); + assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); + assertThat(client().prepareSearch().setSize(0).setRouting(secondRoutingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L)); } logger.info("--> search with {},{} indexRoutings , should find two", routingValue, "1"); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting(routingValue, secondRoutingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch().setSize(0).setRouting(routingValue, secondRoutingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch().setRouting(routingValue, secondRoutingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch().setSize(0).setRouting(routingValue, secondRoutingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } logger.info("--> search with {},{},{} indexRoutings , should find two", routingValue, secondRoutingValue, routingValue); for (int i = 0; i < 5; i++) { - assertThat(client().prepareSearch().setRouting(routingValue, secondRoutingValue, routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); - assertThat(client().prepareSearch().setSize(0).setRouting(routingValue, secondRoutingValue,routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L)); + assertThat(client().prepareSearch().setRouting(routingValue, secondRoutingValue, routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); + assertThat(client().prepareSearch().setSize(0).setRouting(routingValue, secondRoutingValue,routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L)); } } diff --git a/server/src/test/java/org/elasticsearch/search/SearchHitTests.java b/server/src/test/java/org/elasticsearch/search/SearchHitTests.java index 996faf03ffb..0db71bb44f6 100644 --- a/server/src/test/java/org/elasticsearch/search/SearchHitTests.java +++ b/server/src/test/java/org/elasticsearch/search/SearchHitTests.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.function.Predicate; import org.apache.lucene.search.Explanation; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; @@ -48,7 +49,7 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.search.SearchHit.NestedIdentity; import org.elasticsearch.search.fetch.subphase.highlight.HighlightField; import org.elasticsearch.search.fetch.subphase.highlight.HighlightFieldTests; -import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.test.RandomObjects; import static org.elasticsearch.common.xcontent.XContentHelper.toXContent; @@ -59,8 +60,7 @@ import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -public class SearchHitTests extends ESTestCase { - +public class SearchHitTests extends AbstractStreamableTestCase { public static SearchHit createTestItem(boolean withOptionalInnerHits) { int internalId = randomInt(); String uid = randomAlphaOfLength(10); @@ -112,11 +112,13 @@ public class SearchHitTests extends ESTestCase { } if (withOptionalInnerHits) { int innerHitsSize = randomIntBetween(0, 3); - Map innerHits = new HashMap<>(innerHitsSize); - for (int i = 0; i < innerHitsSize; i++) { - innerHits.put(randomAlphaOfLength(5), SearchHitsTests.createTestItem()); + if (innerHitsSize > 0) { + Map innerHits = new HashMap<>(innerHitsSize); + for (int i = 0; i < innerHitsSize; i++) { + innerHits.put(randomAlphaOfLength(5), SearchHitsTests.createTestItem()); + } + hit.setInnerHits(innerHits); } - hit.setInnerHits(innerHits); } if (randomBoolean()) { String index = randomAlphaOfLengthBetween(5, 10); @@ -127,6 +129,16 @@ public class SearchHitTests extends ESTestCase { return hit; } + @Override + protected SearchHit createBlankInstance() { + return new SearchHit(); + } + + @Override + protected SearchHit createTestInstance() { + return createTestItem(randomBoolean()); + } + public void testFromXContent() throws IOException { SearchHit searchHit = createTestItem(true); boolean humanReadable = randomBoolean(); @@ -204,7 +216,7 @@ public class SearchHitTests extends ESTestCase { innerHit1.shard(target); SearchHit innerInnerHit2 = new SearchHit(0, "_id", new Text("_type"), null); innerInnerHit2.shard(target); - innerHits.put("1", new SearchHits(new SearchHit[]{innerInnerHit2}, 1, 1f)); + innerHits.put("1", new SearchHits(new SearchHit[]{innerInnerHit2}, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1f)); innerHit1.setInnerHits(innerHits); SearchHit innerHit2 = new SearchHit(0, "_id", new Text("_type"), null); innerHit2.shard(target); @@ -213,15 +225,15 @@ public class SearchHitTests extends ESTestCase { innerHits = new HashMap<>(); SearchHit hit1 = new SearchHit(0, "_id", new Text("_type"), null); - innerHits.put("1", new SearchHits(new SearchHit[]{innerHit1, innerHit2}, 1, 1f)); - innerHits.put("2", new SearchHits(new SearchHit[]{innerHit3}, 1, 1f)); + innerHits.put("1", new SearchHits(new SearchHit[]{innerHit1, innerHit2}, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1f)); + innerHits.put("2", new SearchHits(new SearchHit[]{innerHit3}, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1f)); hit1.shard(target); hit1.setInnerHits(innerHits); SearchHit hit2 = new SearchHit(0, "_id", new Text("_type"), null); hit2.shard(target); - SearchHits hits = new SearchHits(new SearchHit[]{hit1, hit2}, 2, 1f); + SearchHits hits = new SearchHits(new SearchHit[]{hit1, hit2}, new TotalHits(2, TotalHits.Relation.EQUAL_TO), 1f); BytesStreamOutput output = new BytesStreamOutput(); diff --git a/server/src/test/java/org/elasticsearch/search/SearchHitsTests.java b/server/src/test/java/org/elasticsearch/search/SearchHitsTests.java index a42804692fb..a848944b26a 100644 --- a/server/src/test/java/org/elasticsearch/search/SearchHitsTests.java +++ b/server/src/test/java/org/elasticsearch/search/SearchHitsTests.java @@ -19,36 +19,43 @@ package org.elasticsearch.search; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.util.TestUtil; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.text.Text; import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.AbstractStreamableTestCase; import java.io.IOException; -import java.util.Collections; import java.util.function.Predicate; import static org.elasticsearch.common.xcontent.XContentHelper.toXContent; import static org.elasticsearch.test.XContentTestUtils.insertRandomFields; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent; -public class SearchHitsTests extends ESTestCase { - +public class SearchHitsTests extends AbstractStreamableTestCase { public static SearchHits createTestItem() { int searchHits = randomIntBetween(0, 5); SearchHit[] hits = new SearchHit[searchHits]; for (int i = 0; i < searchHits; i++) { hits[i] = SearchHitTests.createTestItem(false); // creating random innerHits could create loops } - long totalHits = frequently() ? TestUtil.nextLong(random(), 0, Long.MAX_VALUE) : -1; + long totalHits = TestUtil.nextLong(random(), 0, Long.MAX_VALUE); + TotalHits.Relation relation = randomFrom(TotalHits.Relation.values()); float maxScore = frequently() ? randomFloat() : Float.NaN; - return new SearchHits(hits, totalHits, maxScore); + + return new SearchHits(hits, frequently() ? new TotalHits(totalHits, relation) : null, maxScore); + } + + @Override + protected SearchHits createBlankInstance() { + return new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), Float.NaN); + } + + @Override + protected SearchHits createTestInstance() { + return createTestItem(); } public void testFromXContent() throws IOException { @@ -98,22 +105,4 @@ public class SearchHitsTests extends ESTestCase { } assertToXContentEquivalent(originalBytes, toXContent(parsed, xcontentType, true), xcontentType); } - - public void testToXContent() throws IOException { - SearchHit[] hits = new SearchHit[] { - new SearchHit(1, "id1", new Text("type"), Collections.emptyMap()), - new SearchHit(2, "id2", new Text("type"), Collections.emptyMap()) }; - - long totalHits = 1000; - float maxScore = 1.5f; - SearchHits searchHits = new SearchHits(hits, totalHits, maxScore); - XContentBuilder builder = JsonXContent.contentBuilder(); - builder.startObject(); - searchHits.toXContent(builder, ToXContent.EMPTY_PARAMS); - builder.endObject(); - assertEquals("{\"hits\":{\"total\":1000,\"max_score\":1.5," + - "\"hits\":[{\"_type\":\"type\",\"_id\":\"id1\",\"_score\":null},"+ - "{\"_type\":\"type\",\"_id\":\"id2\",\"_score\":null}]}}", Strings.toString(builder)); - } - } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/CombiIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/CombiIT.java index c38552ae254..0992fcdfae1 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/CombiIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/CombiIT.java @@ -128,7 +128,7 @@ public class CombiIT extends ESIntegTestCase { .collectMode(aggCollectionMode ))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), Matchers.equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, Matchers.equalTo(0L)); Histogram values = searchResponse.getAggregations().get("values"); assertThat(values, notNullValue()); assertThat(values.getBuckets().isEmpty(), is(true)); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/EquivalenceIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/EquivalenceIT.java index 28e77e0b9db..2a70646a401 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/EquivalenceIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/EquivalenceIT.java @@ -319,7 +319,7 @@ public class EquivalenceIT extends ESIntegTestCase { .subAggregation(extendedStats("stats").field("num"))) .execute().actionGet(); assertAllSuccessful(resp); - assertEquals(numDocs, resp.getHits().getTotalHits()); + assertEquals(numDocs, resp.getHits().getTotalHits().value); final Terms longTerms = resp.getAggregations().get("long"); final Terms doubleTerms = resp.getAggregations().get("double"); @@ -449,7 +449,7 @@ public class EquivalenceIT extends ESIntegTestCase { .subAggregation(percentiles("pcts").field("double_value"))) .execute().actionGet(); assertAllSuccessful(response); - assertEquals(numDocs, response.getHits().getTotalHits()); + assertEquals(numDocs, response.getHits().getTotalHits().value); } // https://github.com/elastic/elasticsearch/issues/6435 diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/FiltersAggsRewriteIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/FiltersAggsRewriteIT.java index 679941437f0..1c3c8fce5e1 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/FiltersAggsRewriteIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/FiltersAggsRewriteIT.java @@ -64,7 +64,7 @@ public class FiltersAggsRewriteIT extends ESSingleNodeTestCase { metadata.put(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20)); builder.setMetaData(metadata); SearchResponse searchResponse = client().prepareSearch("test").setSize(0).addAggregation(builder).get(); - assertEquals(3, searchResponse.getHits().getTotalHits()); + assertEquals(3, searchResponse.getHits().getTotalHits().value); InternalFilters filters = searchResponse.getAggregations().get("titles"); assertEquals(1, filters.getBuckets().size()); assertEquals(2, filters.getBuckets().get(0).getDocCount()); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/AdjacencyMatrixIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/AdjacencyMatrixIT.java index b86fd279b31..47ce018ddfd 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/AdjacencyMatrixIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/AdjacencyMatrixIT.java @@ -358,7 +358,7 @@ public class AdjacencyMatrixIT extends ESIntegTestCase { .minDocCount(0).subAggregation(adjacencyMatrix("matrix", newMap("all", matchAllQuery())))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java index 0b4659d7e70..73983a7ca09 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java @@ -946,7 +946,7 @@ public class DateHistogramIT extends ESIntegTestCase { .subAggregation(dateHistogram("date_histo").field("value").interval(1))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); List buckets = histo.getBuckets(); @@ -982,7 +982,7 @@ public class DateHistogramIT extends ESIntegTestCase { .format("yyyy-MM-dd:HH-mm-ssZZ")) .execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo(5L)); + assertThat(response.getHits().getTotalHits().value, equalTo(5L)); Histogram histo = response.getAggregations().get("date_histo"); List buckets = histo.getBuckets(); @@ -1145,7 +1145,7 @@ public class DateHistogramIT extends ESIntegTestCase { ).execute().actionGet(); assertSearchResponse(response); - assertThat("Expected 24 buckets for one day aggregation with hourly interval", response.getHits().getTotalHits(), equalTo(2L)); + assertThat("Expected 24 buckets for one day aggregation with hourly interval", response.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = response.getAggregations().get("histo"); assertThat(histo, notNullValue()); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramOffsetIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramOffsetIT.java index f6ad9b17a45..c8e94d2dd64 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramOffsetIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramOffsetIT.java @@ -85,7 +85,7 @@ public class DateHistogramOffsetIT extends ESIntegTestCase { .dateHistogramInterval(DateHistogramInterval.DAY)) .execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo(5L)); + assertThat(response.getHits().getTotalHits().value, equalTo(5L)); Histogram histo = response.getAggregations().get("date_histo"); List buckets = histo.getBuckets(); @@ -107,7 +107,7 @@ public class DateHistogramOffsetIT extends ESIntegTestCase { .dateHistogramInterval(DateHistogramInterval.DAY)) .execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo(5L)); + assertThat(response.getHits().getTotalHits().value, equalTo(5L)); Histogram histo = response.getAggregations().get("date_histo"); List buckets = histo.getBuckets(); @@ -134,7 +134,7 @@ public class DateHistogramOffsetIT extends ESIntegTestCase { .dateHistogramInterval(DateHistogramInterval.DAY)) .execute().actionGet(); - assertThat(response.getHits().getTotalHits(), equalTo(24L)); + assertThat(response.getHits().getTotalHits().value, equalTo(24L)); Histogram histo = response.getAggregations().get("date_histo"); List buckets = histo.getBuckets(); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java index c076fa827d0..fe3ee0d6b72 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java @@ -848,7 +848,7 @@ public class DateRangeIT extends ESIntegTestCase { .subAggregation(dateRange("date_range").field("value").addRange("0-1", 0, 1))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); @@ -943,7 +943,7 @@ public class DateRangeIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch(indexName).setSize(0) .addAggregation(dateRange("date_range").field("date").addRange("00:16:40", "00:50:00").addRange("00:50:00", "01:06:40")) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); List buckets = checkBuckets(searchResponse.getAggregations().get("date_range"), "date_range", 2); assertBucket(buckets.get(0), 2L, "00:16:40-00:50:00", 1000000L, 3000000L); assertBucket(buckets.get(1), 1L, "00:50:00-01:06:40", 3000000L, 4000000L); @@ -953,7 +953,7 @@ public class DateRangeIT extends ESIntegTestCase { searchResponse = client().prepareSearch(indexName).setSize(0).addAggregation( dateRange("date_range").field("date").addRange("00.16.40", "00.50.00").addRange("00.50.00", "01.06.40").format("HH.mm.ss")) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); buckets = checkBuckets(searchResponse.getAggregations().get("date_range"), "date_range", 2); assertBucket(buckets.get(0), 2L, "00.16.40-00.50.00", 1000000L, 3000000L); assertBucket(buckets.get(1), 1L, "00.50.00-01.06.40", 3000000L, 4000000L); @@ -964,7 +964,7 @@ public class DateRangeIT extends ESIntegTestCase { .addAggregation( dateRange("date_range").field("date").addRange(1000000, 3000000).addRange(3000000, 4000000).format("epoch_millis")) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); buckets = checkBuckets(searchResponse.getAggregations().get("date_range"), "date_range", 2); assertBucket(buckets.get(0), 2L, "1000000-3000000", 1000000L, 3000000L); assertBucket(buckets.get(1), 1L, "3000000-4000000", 3000000L, 4000000L); @@ -993,7 +993,7 @@ public class DateRangeIT extends ESIntegTestCase { // mapping SearchResponse searchResponse = client().prepareSearch(indexName).setSize(0) .addAggregation(dateRange("date_range").field("date").addRange(1000, 3000).addRange(3000, 4000)).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); List buckets = checkBuckets(searchResponse.getAggregations().get("date_range"), "date_range", 2); assertBucket(buckets.get(0), 2L, "1000-3000", 1000000L, 3000000L); assertBucket(buckets.get(1), 1L, "3000-4000", 3000000L, 4000000L); @@ -1001,7 +1001,7 @@ public class DateRangeIT extends ESIntegTestCase { // using no format should also work when and to/from are string values searchResponse = client().prepareSearch(indexName).setSize(0) .addAggregation(dateRange("date_range").field("date").addRange("1000", "3000").addRange("3000", "4000")).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); buckets = checkBuckets(searchResponse.getAggregations().get("date_range"), "date_range", 2); assertBucket(buckets.get(0), 2L, "1000-3000", 1000000L, 3000000L); assertBucket(buckets.get(1), 1L, "3000-4000", 3000000L, 4000000L); @@ -1009,7 +1009,7 @@ public class DateRangeIT extends ESIntegTestCase { // also e-notation should work, fractional parts should be truncated searchResponse = client().prepareSearch(indexName).setSize(0) .addAggregation(dateRange("date_range").field("date").addRange(1.0e3, 3000.8123).addRange(3000.8123, 4.0e3)).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); buckets = checkBuckets(searchResponse.getAggregations().get("date_range"), "date_range", 2); assertBucket(buckets.get(0), 2L, "1000-3000", 1000000L, 3000000L); assertBucket(buckets.get(1), 1L, "3000-4000", 3000000L, 4000000L); @@ -1017,14 +1017,14 @@ public class DateRangeIT extends ESIntegTestCase { // also e-notation and floats provided as string also be truncated (see: #14641) searchResponse = client().prepareSearch(indexName).setSize(0) .addAggregation(dateRange("date_range").field("date").addRange("1.0e3", "3.0e3").addRange("3.0e3", "4.0e3")).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); buckets = checkBuckets(searchResponse.getAggregations().get("date_range"), "date_range", 2); assertBucket(buckets.get(0), 2L, "1000-3000", 1000000L, 3000000L); assertBucket(buckets.get(1), 1L, "3000-4000", 3000000L, 4000000L); searchResponse = client().prepareSearch(indexName).setSize(0) .addAggregation(dateRange("date_range").field("date").addRange("1000.123", "3000.8").addRange("3000.8", "4000.3")).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); buckets = checkBuckets(searchResponse.getAggregations().get("date_range"), "date_range", 2); assertBucket(buckets.get(0), 2L, "1000-3000", 1000000L, 3000000L); assertBucket(buckets.get(1), 1L, "3000-4000", 3000000L, 4000000L); @@ -1034,7 +1034,7 @@ public class DateRangeIT extends ESIntegTestCase { searchResponse = client().prepareSearch(indexName).setSize(0).addAggregation( dateRange("date_range").field("date").addRange("00.16.40", "00.50.00").addRange("00.50.00", "01.06.40").format("HH.mm.ss")) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); buckets = checkBuckets(searchResponse.getAggregations().get("date_range"), "date_range", 2); assertBucket(buckets.get(0), 2L, "00.16.40-00.50.00", 1000000L, 3000000L); assertBucket(buckets.get(1), 1L, "00.50.00-01.06.40", 3000000L, 4000000L); @@ -1045,7 +1045,7 @@ public class DateRangeIT extends ESIntegTestCase { .addAggregation( dateRange("date_range").field("date").addRange(1000000, 3000000).addRange(3000000, 4000000).format("epoch_millis")) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); buckets = checkBuckets(searchResponse.getAggregations().get("date_range"), "date_range", 2); assertBucket(buckets.get(0), 2L, "1000000-3000000", 1000000L, 3000000L); assertBucket(buckets.get(1), 1L, "3000000-4000000", 3000000L, 4000000L); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/FilterIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/FilterIT.java index bcc14f09ed8..bda9d4dd9e2 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/FilterIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/FilterIT.java @@ -184,7 +184,7 @@ public class FilterIT extends ESIntegTestCase { .subAggregation(filter("filter", matchAllQuery()))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/FiltersIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/FiltersIT.java index 860a2d662b8..0b786c54d0f 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/FiltersIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/FiltersIT.java @@ -250,7 +250,7 @@ public class FiltersIT extends ESIntegTestCase { .subAggregation(filters("filters", new KeyedFilter("all", matchAllQuery())))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); @@ -447,7 +447,7 @@ public class FiltersIT extends ESIntegTestCase { .otherBucket(true).otherBucketKey("bar"))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoDistanceIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoDistanceIT.java index ef0651a21c7..cb0e29f6c53 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoDistanceIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoDistanceIT.java @@ -417,7 +417,7 @@ public class GeoDistanceIT extends ESIntegTestCase { .subAggregation(geoDistance("geo_dist", new GeoPoint(52.3760, 4.894)).field("location").addRange("0-100", 0.0, 100.0))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java index 38f373f131a..b3b105bf366 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java @@ -901,7 +901,7 @@ public class HistogramIT extends ESIntegTestCase { .subAggregation(histogram("sub_histo").field(SINGLE_VALUED_FIELD_NAME).interval(1L))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); List buckets = histo.getBuckets(); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/MissingIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/MissingIT.java index d51a4a59ff3..4788aac5bf9 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/MissingIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/MissingIT.java @@ -167,7 +167,7 @@ public class MissingIT extends ESIntegTestCase { .subAggregation(missing("missing").field("value"))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/NestedIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/NestedIT.java index 10fa2231807..beebb6dda91 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/NestedIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/NestedIT.java @@ -337,7 +337,7 @@ public class NestedIT extends ESIntegTestCase { .subAggregation(nested("nested", "nested"))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeIT.java index 7508cd4e839..ec2b9e8d380 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeIT.java @@ -923,7 +923,7 @@ public class RangeIT extends ESIntegTestCase { .addRange("0-2", 0.0, 2.0))) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, Matchers.notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTestCase.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTestCase.java index b30dca1c9a0..7dc2385e838 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTestCase.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTestCase.java @@ -92,11 +92,11 @@ public abstract class ShardSizeTestCase extends ESIntegTestCase { SearchResponse resp = client().prepareSearch("idx").setTypes("type").setRouting(routing1).setQuery(matchAllQuery()).execute().actionGet(); assertSearchResponse(resp); - long totalOnOne = resp.getHits().getTotalHits(); + long totalOnOne = resp.getHits().getTotalHits().value; assertThat(totalOnOne, is(15L)); resp = client().prepareSearch("idx").setTypes("type").setRouting(routing2).setQuery(matchAllQuery()).execute().actionGet(); assertSearchResponse(resp); - long totalOnTwo = resp.getHits().getTotalHits(); + long totalOnTwo = resp.getHits().getTotalHits().value; assertThat(totalOnTwo, is(12L)); } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregatorTests.java index f2cb91673ce..9940a4eacf7 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregatorTests.java @@ -1508,19 +1508,19 @@ public class CompositeAggregatorTests extends AggregatorTestCase { TopHits topHits = result.getBuckets().get(0).getAggregations().get("top_hits"); assertNotNull(topHits); assertEquals(topHits.getHits().getHits().length, 2); - assertEquals(topHits.getHits().getTotalHits(), 2L); + assertEquals(topHits.getHits().getTotalHits().value, 2L); assertEquals("{keyword=c}", result.getBuckets().get(1).getKeyAsString()); assertEquals(2L, result.getBuckets().get(1).getDocCount()); topHits = result.getBuckets().get(1).getAggregations().get("top_hits"); assertNotNull(topHits); assertEquals(topHits.getHits().getHits().length, 2); - assertEquals(topHits.getHits().getTotalHits(), 2L); + assertEquals(topHits.getHits().getTotalHits().value, 2L); assertEquals("{keyword=d}", result.getBuckets().get(2).getKeyAsString()); assertEquals(1L, result.getBuckets().get(2).getDocCount()); topHits = result.getBuckets().get(2).getAggregations().get("top_hits"); assertNotNull(topHits); assertEquals(topHits.getHits().getHits().length, 1); - assertEquals(topHits.getHits().getTotalHits(), 1L); + assertEquals(topHits.getHits().getTotalHits().value, 1L); } ); @@ -1538,13 +1538,13 @@ public class CompositeAggregatorTests extends AggregatorTestCase { TopHits topHits = result.getBuckets().get(0).getAggregations().get("top_hits"); assertNotNull(topHits); assertEquals(topHits.getHits().getHits().length, 2); - assertEquals(topHits.getHits().getTotalHits(), 2L); + assertEquals(topHits.getHits().getTotalHits().value, 2L); assertEquals("{keyword=d}", result.getBuckets().get(1).getKeyAsString()); assertEquals(1L, result.getBuckets().get(1).getDocCount()); topHits = result.getBuckets().get(1).getAggregations().get("top_hits"); assertNotNull(topHits); assertEquals(topHits.getHits().getHits().length, 1); - assertEquals(topHits.getHits().getTotalHits(), 1L); + assertEquals(topHits.getHits().getTotalHits().value, 1L); } ); } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java index 951f639665c..d8948c10613 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java @@ -33,6 +33,7 @@ import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.NumericUtils; @@ -1080,7 +1081,8 @@ public class TermsAggregatorTests extends AggregatorTestCase { int ptr = 9; for (MultiBucketsAggregation.Bucket bucket : terms.getBuckets()) { InternalTopHits topHits = bucket.getAggregations().get("top_hits"); - assertThat(topHits.getHits().totalHits, equalTo((long) ptr)); + assertThat(topHits.getHits().getTotalHits().value, equalTo((long) ptr)); + assertEquals(TotalHits.Relation.EQUAL_TO, topHits.getHits().getTotalHits().relation); if (withScore) { assertThat(topHits.getHits().getMaxScore(), equalTo(1f)); } else { diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java index 49442e3fbc0..3c60ad52b7b 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java @@ -198,7 +198,7 @@ public abstract class AbstractGeoTestCase extends ESIntegTestCase { SearchResponse response = client().prepareSearch(HIGH_CARD_IDX_NAME).addStoredField(NUMBER_FIELD_NAME) .addSort(SortBuilders.fieldSort(NUMBER_FIELD_NAME).order(SortOrder.ASC)).setSize(5000).get(); assertSearchResponse(response); - long totalHits = response.getHits().getTotalHits(); + long totalHits = response.getHits().getTotalHits().value; XContentBuilder builder = XContentFactory.jsonBuilder(); response.toXContent(builder, ToXContent.EMPTY_PARAMS); logger.info("Full high_card_idx Response Content:\n{ {} }", Strings.toString(builder)); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java index e18bfd7fcc8..bff289e59eb 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java @@ -70,7 +70,7 @@ public class AvgIT extends AbstractNumericTestCase { .addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0).subAggregation(avg("avg").field("value"))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); @@ -89,7 +89,7 @@ public class AvgIT extends AbstractNumericTestCase { .addAggregation(avg("avg").field("value")) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); Avg avg = searchResponse.getAggregations().get("avg"); assertThat(avg, notNullValue()); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsIT.java index 2f70c5ef19b..7325ae877aa 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsIT.java @@ -84,7 +84,7 @@ public class ExtendedStatsIT extends AbstractNumericTestCase { histogram("histo").field("value").interval(1L).minDocCount(0).subAggregation(extendedStats("stats").field("value"))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); @@ -111,7 +111,7 @@ public class ExtendedStatsIT extends AbstractNumericTestCase { .addAggregation(extendedStats("stats").field("value")) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); ExtendedStats stats = searchResponse.getAggregations().get("stats"); assertThat(stats, notNullValue()); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsIT.java index 483cd9f7068..63fb41b16df 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsIT.java @@ -164,7 +164,7 @@ public class GeoBoundsIT extends AbstractGeoTestCase { .wrapLongitude(false)) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); GeoBounds geoBounds = searchResponse.getAggregations().get(aggName); assertThat(geoBounds, notNullValue()); assertThat(geoBounds.getName(), equalTo(aggName)); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidIT.java index f06e5510aed..7806364119f 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidIT.java @@ -53,7 +53,7 @@ public class GeoCentroidIT extends AbstractGeoTestCase { assertSearchResponse(response); GeoCentroid geoCentroid = response.getAggregations().get(aggName); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); assertThat(geoCentroid, notNullValue()); assertThat(geoCentroid.getName(), equalTo(aggName)); GeoPoint centroid = geoCentroid.centroid(); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksIT.java index b866992fe7a..c6d1ebb63aa 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksIT.java @@ -130,7 +130,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase { .numberOfSignificantValueDigits(sigDigits))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); @@ -156,7 +156,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase { .field("value")) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); PercentileRanks reversePercentiles = searchResponse.getAggregations().get("percentile_ranks"); assertThat(reversePercentiles, notNullValue()); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesIT.java index 085eea565a2..0104f7647f7 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesIT.java @@ -132,7 +132,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase { .percentiles(10, 15))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); Histogram histo = searchResponse.getAggregations().get("histo"); assertThat(histo, notNullValue()); Histogram.Bucket bucket = histo.getBuckets().get(1); @@ -155,7 +155,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase { percentiles("percentiles").numberOfSignificantValueDigits(sigDigits).method(PercentilesMethod.HDR).field("value") .percentiles(0, 10, 15, 100)).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); Percentiles percentiles = searchResponse.getAggregations().get("percentiles"); assertThat(percentiles, notNullValue()); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalTopHitsTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalTopHitsTests.java index c5c99a5b136..c098e911c35 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalTopHitsTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalTopHitsTests.java @@ -36,8 +36,6 @@ import org.elasticsearch.common.text.Text; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.ParsedAggregation; -import org.elasticsearch.search.aggregations.metrics.InternalTopHits; -import org.elasticsearch.search.aggregations.metrics.ParsedTopHits; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.test.InternalAggregationTestCase; @@ -103,7 +101,7 @@ public class InternalTopHitsTests extends InternalAggregationTestCase expectedHits = Arrays.asList(expectedSearchHits.getHits()); @@ -180,9 +179,13 @@ public class InternalTopHitsTests extends InternalAggregationTestCase> allHits = new ArrayList<>(); float maxScore = Float.NEGATIVE_INFINITY; long totalHits = 0; + TotalHits.Relation relation = TotalHits.Relation.EQUAL_TO; for (int input = 0; input < inputs.size(); input++) { SearchHits internalHits = inputs.get(input).getHits(); - totalHits += internalHits.getTotalHits(); + totalHits += internalHits.getTotalHits().value; + if (internalHits.getTotalHits().relation == TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO) { + relation = TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO; + } maxScore = max(maxScore, internalHits.getMaxScore()); for (int i = 0; i < internalHits.getHits().length; i++) { ScoreDoc doc = inputs.get(input).getTopDocs().topDocs.scoreDocs[i]; @@ -200,7 +203,9 @@ public class InternalTopHitsTests extends InternalAggregationTestCase 2 * Integer.MAX_VALUE); + final double[] quantiles = new double[] { 0, 0.1, 0.5, 0.9, 1, randomDouble()}; + Arrays.sort(quantiles); + double prev = Double.NEGATIVE_INFINITY; + for (double q : quantiles) { + final double v = digest.quantile(q); + logger.trace("q=" + q + ", v=" + v); + assertTrue(v >= prev); + assertTrue("Unexpectedly low value: " + v, v >= 0.0); + assertTrue("Unexpectedly high value: " + v, v <= 1.0); + prev = v; + } + } +} diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsAggregatorTests.java index c888dbf8d2e..921f29c915f 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsAggregatorTests.java @@ -67,7 +67,7 @@ public class TopHitsAggregatorTests extends AggregatorTestCase { result = testCase(query, topHits("_name")); } SearchHits searchHits = ((TopHits) result).getHits(); - assertEquals(3L, searchHits.getTotalHits()); + assertEquals(3L, searchHits.getTotalHits().value); assertEquals("3", searchHits.getAt(0).getId()); assertEquals("type", searchHits.getAt(0).getType()); assertEquals("2", searchHits.getAt(1).getId()); @@ -79,7 +79,7 @@ public class TopHitsAggregatorTests extends AggregatorTestCase { public void testNoResults() throws Exception { TopHits result = (TopHits) testCase(new MatchNoDocsQuery(), topHits("_name").sort("string", SortOrder.DESC)); SearchHits searchHits = ((TopHits) result).getHits(); - assertEquals(0L, searchHits.getTotalHits()); + assertEquals(0L, searchHits.getTotalHits().value); } /** @@ -103,24 +103,24 @@ public class TopHitsAggregatorTests extends AggregatorTestCase { // The "a" bucket TopHits hits = (TopHits) terms.getBucketByKey("a").getAggregations().get("top"); SearchHits searchHits = (hits).getHits(); - assertEquals(2L, searchHits.getTotalHits()); + assertEquals(2L, searchHits.getTotalHits().value); assertEquals("2", searchHits.getAt(0).getId()); assertEquals("1", searchHits.getAt(1).getId()); // The "b" bucket searchHits = ((TopHits) terms.getBucketByKey("b").getAggregations().get("top")).getHits(); - assertEquals(2L, searchHits.getTotalHits()); + assertEquals(2L, searchHits.getTotalHits().value); assertEquals("3", searchHits.getAt(0).getId()); assertEquals("1", searchHits.getAt(1).getId()); // The "c" bucket searchHits = ((TopHits) terms.getBucketByKey("c").getAggregations().get("top")).getHits(); - assertEquals(1L, searchHits.getTotalHits()); + assertEquals(1L, searchHits.getTotalHits().value); assertEquals("2", searchHits.getAt(0).getId()); // The "d" bucket searchHits = ((TopHits) terms.getBucketByKey("d").getAggregations().get("top")).getHits(); - assertEquals(1L, searchHits.getTotalHits()); + assertEquals(1L, searchHits.getTotalHits().value); assertEquals("3", searchHits.getAt(0).getId()); } @@ -196,7 +196,7 @@ public class TopHitsAggregatorTests extends AggregatorTestCase { .build(); AggregationBuilder agg = AggregationBuilders.topHits("top_hits"); TopHits result = searchAndReduce(searcher, query, agg, STRING_FIELD_TYPE); - assertEquals(3, result.getHits().totalHits); + assertEquals(3, result.getHits().getTotalHits().value); reader.close(); directory.close(); } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java index aec8a36b2ca..c5a9096620e 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java @@ -301,7 +301,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(10L)); TopHits topHits = bucket.getAggregations().get("hits"); SearchHits hits = topHits.getHits(); - assertThat(hits.getTotalHits(), equalTo(10L)); + assertThat(hits.getTotalHits().value, equalTo(10L)); assertThat(hits.getHits().length, equalTo(3)); higestSortValue += 10; assertThat((Long) hits.getAt(0).getSortValues()[0], equalTo(higestSortValue)); @@ -324,7 +324,7 @@ public class TopHitsIT extends ESIntegTestCase { assertSearchResponse(response); - assertThat(response.getHits().getTotalHits(), equalTo(8L)); + assertThat(response.getHits().getTotalHits().value, equalTo(8L)); assertThat(response.getHits().getHits().length, equalTo(0)); assertThat(response.getHits().getMaxScore(), equalTo(Float.NaN)); Terms terms = response.getAggregations().get("terms"); @@ -359,7 +359,7 @@ public class TopHitsIT extends ESIntegTestCase { assertSearchResponse(response); - assertThat(response.getHits().getTotalHits(), equalTo(8L)); + assertThat(response.getHits().getTotalHits().value, equalTo(8L)); assertThat(response.getHits().getHits().length, equalTo(0)); assertThat(response.getHits().getMaxScore(), equalTo(Float.NaN)); terms = response.getAggregations().get("terms"); @@ -392,7 +392,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(10L)); TopHits topHits = bucket.getAggregations().get("hits"); SearchHits hits = topHits.getHits(); - assertThat(hits.getTotalHits(), equalTo(10L)); + assertThat(hits.getTotalHits().value, equalTo(10L)); assertThat(hits.getHits().length, equalTo(3)); assertThat(hits.getAt(0).getSourceAsMap().size(), equalTo(4)); @@ -423,7 +423,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(10L)); TopHits topHits = bucket.getAggregations().get("hits"); SearchHits hits = topHits.getHits(); - assertThat(hits.getTotalHits(), equalTo(10L)); + assertThat(hits.getTotalHits().value, equalTo(10L)); assertThat(hits.getHits().length, equalTo(3)); assertThat(hits.getAt(0).getSourceAsMap().size(), equalTo(4)); @@ -486,7 +486,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(10L)); TopHits topHits = bucket.getAggregations().get("hits"); SearchHits hits = topHits.getHits(); - assertThat(hits.getTotalHits(), equalTo(controlHits.getTotalHits())); + assertThat(hits.getTotalHits().value, equalTo(controlHits.getTotalHits().value)); assertThat(hits.getHits().length, equalTo(controlHits.getHits().length)); for (int i = 0; i < hits.getHits().length; i++) { logger.info("{}: top_hits: [{}][{}] control: [{}][{}]", i, hits.getAt(i).getId(), hits.getAt(i).getSortValues()[0], @@ -524,7 +524,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(10L)); TopHits topHits = bucket.getAggregations().get("hits"); SearchHits hits = topHits.getHits(); - assertThat(hits.getTotalHits(), equalTo(10L)); + assertThat(hits.getTotalHits().value, equalTo(10L)); assertThat(hits.getHits().length, equalTo(3)); assertThat(hits.getAt(0).getSortValues()[0], equalTo(higestSortValue)); assertThat(hits.getAt(1).getSortValues()[0], equalTo(higestSortValue - 1)); @@ -556,7 +556,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(key(bucket), equalTo("b")); TopHits topHits = bucket.getAggregations().get("hits"); SearchHits hits = topHits.getHits(); - assertThat(hits.getTotalHits(), equalTo(4L)); + assertThat(hits.getTotalHits().value, equalTo(4L)); assertThat(hits.getHits().length, equalTo(1)); assertThat(hits.getAt(0).getId(), equalTo("6")); @@ -564,7 +564,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(key(bucket), equalTo("c")); topHits = bucket.getAggregations().get("hits"); hits = topHits.getHits(); - assertThat(hits.getTotalHits(), equalTo(3L)); + assertThat(hits.getTotalHits().value, equalTo(3L)); assertThat(hits.getHits().length, equalTo(1)); assertThat(hits.getAt(0).getId(), equalTo("9")); @@ -572,7 +572,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(key(bucket), equalTo("a")); topHits = bucket.getAggregations().get("hits"); hits = topHits.getHits(); - assertThat(hits.getTotalHits(), equalTo(2L)); + assertThat(hits.getTotalHits().value, equalTo(2L)); assertThat(hits.getHits().length, equalTo(1)); assertThat(hits.getAt(0).getId(), equalTo("2")); } @@ -606,7 +606,7 @@ public class TopHitsIT extends ESIntegTestCase { for (Terms.Bucket bucket : terms.getBuckets()) { TopHits topHits = bucket.getAggregations().get("hits"); SearchHits hits = topHits.getHits(); - assertThat(hits.getTotalHits(), equalTo(10L)); + assertThat(hits.getTotalHits().value, equalTo(10L)); assertThat(hits.getHits().length, equalTo(1)); SearchHit hit = hits.getAt(0); @@ -660,7 +660,7 @@ public class TopHitsIT extends ESIntegTestCase { TopHits hits = response.getAggregations().get("hits"); assertThat(hits, notNullValue()); assertThat(hits.getName(), equalTo("hits")); - assertThat(hits.getHits().getTotalHits(), equalTo(0L)); + assertThat(hits.getHits().getTotalHits().value, equalTo(0L)); } public void testTrackScores() throws Exception { @@ -732,7 +732,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(1L)); TopHits topHits = bucket.getAggregations().get("top-comments"); SearchHits searchHits = topHits.getHits(); - assertThat(searchHits.getTotalHits(), equalTo(1L)); + assertThat(searchHits.getTotalHits().value, equalTo(1L)); assertThat(searchHits.getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); assertThat(searchHits.getAt(0).getNestedIdentity().getOffset(), equalTo(0)); assertThat(extractValue("date", searchHits.getAt(0).getSourceAsMap()), equalTo(1)); @@ -741,7 +741,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(2L)); topHits = bucket.getAggregations().get("top-comments"); searchHits = topHits.getHits(); - assertThat(searchHits.getTotalHits(), equalTo(2L)); + assertThat(searchHits.getTotalHits().value, equalTo(2L)); assertThat(searchHits.getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); assertThat(searchHits.getAt(0).getNestedIdentity().getOffset(), equalTo(1)); assertThat(extractValue("date", searchHits.getAt(0).getSourceAsMap()), equalTo(2)); @@ -753,7 +753,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(1L)); topHits = bucket.getAggregations().get("top-comments"); searchHits = topHits.getHits(); - assertThat(searchHits.getTotalHits(), equalTo(1L)); + assertThat(searchHits.getTotalHits().value, equalTo(1L)); assertThat(searchHits.getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); assertThat(searchHits.getAt(0).getNestedIdentity().getOffset(), equalTo(1)); assertThat(extractValue("date", searchHits.getAt(0).getSourceAsMap()), equalTo(4)); @@ -779,7 +779,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(toComments.getDocCount(), equalTo(4L)); TopHits topComments = toComments.getAggregations().get("top-comments"); - assertThat(topComments.getHits().getTotalHits(), equalTo(4L)); + assertThat(topComments.getHits().getTotalHits().value, equalTo(4L)); assertThat(topComments.getHits().getHits().length, equalTo(4)); assertThat(topComments.getHits().getAt(0).getId(), equalTo("2")); @@ -806,7 +806,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(toReviewers.getDocCount(), equalTo(7L)); TopHits topReviewers = toReviewers.getAggregations().get("top-reviewers"); - assertThat(topReviewers.getHits().getTotalHits(), equalTo(7L)); + assertThat(topReviewers.getHits().getTotalHits().value, equalTo(7L)); assertThat(topReviewers.getHits().getHits().length, equalTo(7)); assertThat(topReviewers.getHits().getAt(0).getId(), equalTo("1")); @@ -882,7 +882,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(nested.getDocCount(), equalTo(4L)); SearchHits hits = ((TopHits) nested.getAggregations().get("top-comments")).getHits(); - assertThat(hits.getTotalHits(), equalTo(4L)); + assertThat(hits.getTotalHits().value, equalTo(4L)); SearchHit searchHit = hits.getAt(0); assertThat(searchHit.getId(), equalTo("1")); assertThat(searchHit.getNestedIdentity().getField().string(), equalTo("comments")); @@ -946,7 +946,7 @@ public class TopHitsIT extends ESIntegTestCase { TopHits hits = nested.getAggregations().get("comments"); SearchHits searchHits = hits.getHits(); - assertThat(searchHits.getTotalHits(), equalTo(numNestedDocs)); + assertThat(searchHits.getTotalHits().value, equalTo(numNestedDocs)); for (int j = 0; j < 3; j++) { assertThat(searchHits.getAt(j).getNestedIdentity().getField().string(), equalTo("comments")); assertThat(searchHits.getAt(j).getNestedIdentity().getOffset(), equalTo(0)); @@ -1064,7 +1064,7 @@ public class TopHitsIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(10L)); TopHits topHits = bucket.getAggregations().get("hits"); SearchHits hits = topHits.getHits(); - assertThat(hits.getTotalHits(), equalTo(10L)); + assertThat(hits.getTotalHits().value, equalTo(10L)); assertThat(hits.getHits().length, equalTo(3)); for (SearchHit hit : hits) { assertThat(hit.getSourceAsMap(), nullValue()); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java index 357c5a94a7a..2161ce71f90 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java @@ -82,7 +82,7 @@ public class ValueCountIT extends ESIntegTestCase { .addAggregation(count("count").field("value")) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); ValueCount valueCount = searchResponse.getAggregations().get("count"); assertThat(valueCount, notNullValue()); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeIT.java index 7222bc19b59..33a581c63cb 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeIT.java @@ -388,7 +388,7 @@ public class DerivativeIT extends ESIntegTestCase { histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(1) .subAggregation(derivative("deriv", "_count"))).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(numDocsEmptyIdx)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(numDocsEmptyIdx)); Histogram deriv = searchResponse.getAggregations().get("histo"); assertThat(deriv, Matchers.notNullValue()); @@ -418,7 +418,7 @@ public class DerivativeIT extends ESIntegTestCase { .subAggregation(derivative("deriv", "_count").gapPolicy(randomFrom(GapPolicy.values())))) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(numDocsEmptyIdx_rnd)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(numDocsEmptyIdx_rnd)); Histogram deriv = searchResponse.getAggregations().get("histo"); assertThat(deriv, Matchers.notNullValue()); @@ -447,7 +447,7 @@ public class DerivativeIT extends ESIntegTestCase { .subAggregation(derivative("deriv", "_count").gapPolicy(GapPolicy.INSERT_ZEROS))).execute() .actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(numDocsEmptyIdx)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(numDocsEmptyIdx)); Histogram deriv = searchResponse.getAggregations().get("histo"); assertThat(deriv, Matchers.notNullValue()); @@ -476,7 +476,7 @@ public class DerivativeIT extends ESIntegTestCase { .subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)) .subAggregation(derivative("deriv", "sum"))).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(numDocsEmptyIdx)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(numDocsEmptyIdx)); Histogram deriv = searchResponse.getAggregations().get("histo"); assertThat(deriv, Matchers.notNullValue()); @@ -518,7 +518,7 @@ public class DerivativeIT extends ESIntegTestCase { .subAggregation(derivative("deriv", "sum").gapPolicy(GapPolicy.INSERT_ZEROS))).execute() .actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(numDocsEmptyIdx)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(numDocsEmptyIdx)); Histogram deriv = searchResponse.getAggregations().get("histo"); assertThat(deriv, Matchers.notNullValue()); @@ -557,7 +557,7 @@ public class DerivativeIT extends ESIntegTestCase { .subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)) .subAggregation(derivative("deriv", "sum").gapPolicy(gapPolicy))).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(numDocsEmptyIdx_rnd)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(numDocsEmptyIdx_rnd)); Histogram deriv = searchResponse.getAggregations().get("histo"); assertThat(deriv, Matchers.notNullValue()); diff --git a/server/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java b/server/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java index 23d18562b28..af384fe2e56 100644 --- a/server/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java +++ b/server/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java @@ -80,13 +80,13 @@ public class SearchWhileCreatingIndexIT extends ESIntegTestCase { assertHitCount(searchResponse, 1); Client client = client(); searchResponse = client.prepareSearch("test").setPreference(preference + Integer.toString(counter++)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet(); - if (searchResponse.getHits().getTotalHits() != 1) { + if (searchResponse.getHits().getTotalHits().value != 1) { refresh(); SearchResponse searchResponseAfterRefresh = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet(); - logger.info("hits count mismatch on any shard search failed, post explicit refresh hits are {}", searchResponseAfterRefresh.getHits().getTotalHits()); + logger.info("hits count mismatch on any shard search failed, post explicit refresh hits are {}", searchResponseAfterRefresh.getHits().getTotalHits().value); ensureGreen(); SearchResponse searchResponseAfterGreen = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet(); - logger.info("hits count mismatch on any shard search failed, post explicit wait for green hits are {}", searchResponseAfterGreen.getHits().getTotalHits()); + logger.info("hits count mismatch on any shard search failed, post explicit wait for green hits are {}", searchResponseAfterGreen.getHits().getTotalHits().value); assertHitCount(searchResponse, 1); } assertHitCount(searchResponse, 1); diff --git a/server/src/test/java/org/elasticsearch/search/basic/SearchWhileRelocatingIT.java b/server/src/test/java/org/elasticsearch/search/basic/SearchWhileRelocatingIT.java index 5908dac2feb..e745a505da0 100644 --- a/server/src/test/java/org/elasticsearch/search/basic/SearchWhileRelocatingIT.java +++ b/server/src/test/java/org/elasticsearch/search/basic/SearchWhileRelocatingIT.java @@ -75,12 +75,12 @@ public class SearchWhileRelocatingIT extends ESIntegTestCase { try { while (!stop.get()) { SearchResponse sr = client().prepareSearch().setSize(numDocs).get(); - if (sr.getHits().getTotalHits() != numDocs) { + if (sr.getHits().getTotalHits().value != numDocs) { // if we did not search all shards but had no failures that is potentially fine // if only the hit-count is wrong. this can happen if the cluster-state is behind when the // request comes in. It's a small window but a known limitation. if (sr.getTotalShards() != sr.getSuccessfulShards() && sr.getFailedShards() == 0) { - nonCriticalExceptions.add("Count is " + sr.getHits().getTotalHits() + " but " + numDocs + + nonCriticalExceptions.add("Count is " + sr.getHits().getTotalHits().value + " but " + numDocs + " was expected. " + formatShardStatus(sr)); } else { assertHitCount(sr, numDocs); @@ -88,7 +88,7 @@ public class SearchWhileRelocatingIT extends ESIntegTestCase { } final SearchHits sh = sr.getHits(); - assertThat("Expected hits to be the same size the actual hits array", sh.getTotalHits(), + assertThat("Expected hits to be the same size the actual hits array", sh.getTotalHits().value, equalTo((long) (sh.getHits().length))); // this is the more critical but that we hit the actual hit array has a different size than the // actual number of hits. diff --git a/server/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java b/server/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java index d5ceec9d7c2..be3679157a2 100644 --- a/server/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java +++ b/server/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java @@ -138,7 +138,7 @@ public class TransportTwoNodesSearchIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch("test").setSearchType(DFS_QUERY_THEN_FETCH).setQuery(termQuery("multi", "test")).setSize(60).setExplain(true).setScroll(TimeValue.timeValueSeconds(30)).get(); while (true) { assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); SearchHit[] hits = searchResponse.getHits().getHits(); if (hits.length == 0) { break; // finished @@ -173,7 +173,7 @@ public class TransportTwoNodesSearchIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch("test").setSearchType(DFS_QUERY_THEN_FETCH).setQuery(termQuery("multi", "test")).setSize(60).setExplain(true).addSort("age", SortOrder.ASC).setScroll(TimeValue.timeValueSeconds(30)).get(); while (true) { assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); SearchHit[] hits = searchResponse.getHits().getHits(); if (hits.length == 0) { break; // finished @@ -208,7 +208,7 @@ public class TransportTwoNodesSearchIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch("test").setSearchType(QUERY_THEN_FETCH).setQuery(termQuery("multi", "test")).setSize(60).setExplain(true).addSort("nid", SortOrder.DESC).setScroll(TimeValue.timeValueSeconds(30)).get(); while (true) { assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); SearchHit[] hits = searchResponse.getHits().getHits(); if (hits.length == 0) { break; // finished @@ -236,7 +236,7 @@ public class TransportTwoNodesSearchIT extends ESIntegTestCase { SearchResponse searchResponse = client().search(searchRequest("test").source(source.from(0).size(60)).searchType(QUERY_THEN_FETCH)).actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(60)); for (int i = 0; i < 60; i++) { SearchHit hit = searchResponse.getHits().getHits()[i]; @@ -244,7 +244,7 @@ public class TransportTwoNodesSearchIT extends ESIntegTestCase { } searchResponse = client().search(searchRequest("test").source(source.from(60).size(60)).searchType(QUERY_THEN_FETCH)).actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(40)); for (int i = 0; i < 40; i++) { SearchHit hit = searchResponse.getHits().getHits()[i]; @@ -260,7 +260,7 @@ public class TransportTwoNodesSearchIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch("test").setQuery(termQuery("multi", "test")).setSize(60).setExplain(true).addSort("age", SortOrder.ASC).setScroll(TimeValue.timeValueSeconds(30)).get(); while (true) { assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); SearchHit[] hits = searchResponse.getHits().getHits(); if (hits.length == 0) { break; // finished @@ -289,7 +289,7 @@ public class TransportTwoNodesSearchIT extends ESIntegTestCase { SearchResponse searchResponse = client().search(searchRequest("test").source(sourceBuilder)).actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); Global global = searchResponse.getAggregations().get("global"); Filter all = global.getAggregations().get("all"); diff --git a/server/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java b/server/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java index ea4f1133a2b..52a02bcae17 100644 --- a/server/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java +++ b/server/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java @@ -130,7 +130,7 @@ public class InnerHitsIT extends ESIntegTestCase { assertSearchHit(response, 1, hasId("1")); assertThat(response.getHits().getAt(0).getInnerHits().size(), equalTo(1)); SearchHits innerHits = response.getHits().getAt(0).getInnerHits().get("comment"); - assertThat(innerHits.getTotalHits(), equalTo(2L)); + assertThat(innerHits.getTotalHits().value, equalTo(2L)); assertThat(innerHits.getHits().length, equalTo(2)); assertThat(innerHits.getAt(0).getId(), equalTo("1")); assertThat(innerHits.getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); @@ -149,7 +149,7 @@ public class InnerHitsIT extends ESIntegTestCase { assertThat(response.getHits().getAt(0).getShard(), notNullValue()); assertThat(response.getHits().getAt(0).getInnerHits().size(), equalTo(1)); innerHits = response.getHits().getAt(0).getInnerHits().get("comment"); - assertThat(innerHits.getTotalHits(), equalTo(3L)); + assertThat(innerHits.getTotalHits().value, equalTo(3L)); assertThat(innerHits.getHits().length, equalTo(3)); assertThat(innerHits.getAt(0).getId(), equalTo("2")); assertThat(innerHits.getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); @@ -171,7 +171,7 @@ public class InnerHitsIT extends ESIntegTestCase { .setSize(1))).get(); assertNoFailures(response); innerHits = response.getHits().getAt(0).getInnerHits().get("comments"); - assertThat(innerHits.getTotalHits(), equalTo(2L)); + assertThat(innerHits.getTotalHits().value, equalTo(2L)); assertThat(innerHits.getHits().length, equalTo(1)); assertThat(innerHits.getAt(0).getHighlightFields().get("comments.message").getFragments()[0].string(), equalTo("fox eat quick")); @@ -224,7 +224,7 @@ public class InnerHitsIT extends ESIntegTestCase { SearchHit searchHit = searchResponse.getHits().getAt(i); assertThat(searchHit.getShard(), notNullValue()); SearchHits inner = searchHit.getInnerHits().get("a"); - assertThat(inner.getTotalHits(), equalTo((long) field1InnerObjects[i])); + assertThat(inner.getTotalHits().value, equalTo((long) field1InnerObjects[i])); for (int j = 0; j < field1InnerObjects[i] && j < size; j++) { SearchHit innerHit = inner.getAt(j); assertThat(innerHit.getNestedIdentity().getField().string(), equalTo("field1")); @@ -233,7 +233,7 @@ public class InnerHitsIT extends ESIntegTestCase { } inner = searchHit.getInnerHits().get("b"); - assertThat(inner.getTotalHits(), equalTo((long) field2InnerObjects[i])); + assertThat(inner.getTotalHits().value, equalTo((long) field2InnerObjects[i])); for (int j = 0; j < field2InnerObjects[i] && j < size; j++) { SearchHit innerHit = inner.getAt(j); assertThat(innerHit.getNestedIdentity().getField().string(), equalTo("field2")); @@ -298,13 +298,13 @@ public class InnerHitsIT extends ESIntegTestCase { assertSearchHit(response, 1, hasId("1")); assertThat(response.getHits().getAt(0).getInnerHits().size(), equalTo(1)); SearchHits innerHits = response.getHits().getAt(0).getInnerHits().get("comments"); - assertThat(innerHits.getTotalHits(), equalTo(1L)); + assertThat(innerHits.getTotalHits().value, equalTo(1L)); assertThat(innerHits.getHits().length, equalTo(1)); assertThat(innerHits.getAt(0).getId(), equalTo("1")); assertThat(innerHits.getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); assertThat(innerHits.getAt(0).getNestedIdentity().getOffset(), equalTo(0)); innerHits = innerHits.getAt(0).getInnerHits().get("remark"); - assertThat(innerHits.getTotalHits(), equalTo(1L)); + assertThat(innerHits.getTotalHits().value, equalTo(1L)); assertThat(innerHits.getHits().length, equalTo(1)); assertThat(innerHits.getAt(0).getId(), equalTo("1")); assertThat(innerHits.getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); @@ -321,7 +321,7 @@ public class InnerHitsIT extends ESIntegTestCase { assertSearchHit(response, 1, hasId("2")); assertThat(response.getHits().getAt(0).getInnerHits().size(), equalTo(1)); innerHits = response.getHits().getAt(0).getInnerHits().get("comments.remarks"); - assertThat(innerHits.getTotalHits(), equalTo(1L)); + assertThat(innerHits.getTotalHits().value, equalTo(1L)); assertThat(innerHits.getHits().length, equalTo(1)); assertThat(innerHits.getAt(0).getId(), equalTo("2")); assertThat(innerHits.getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); @@ -341,13 +341,13 @@ public class InnerHitsIT extends ESIntegTestCase { assertSearchHit(response, 1, hasId("2")); assertThat(response.getHits().getAt(0).getInnerHits().size(), equalTo(1)); innerHits = response.getHits().getAt(0).getInnerHits().get("comments"); - assertThat(innerHits.getTotalHits(), equalTo(1L)); + assertThat(innerHits.getTotalHits().value, equalTo(1L)); assertThat(innerHits.getHits().length, equalTo(1)); assertThat(innerHits.getAt(0).getId(), equalTo("2")); assertThat(innerHits.getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); assertThat(innerHits.getAt(0).getNestedIdentity().getOffset(), equalTo(0)); innerHits = innerHits.getAt(0).getInnerHits().get("remark"); - assertThat(innerHits.getTotalHits(), equalTo(1L)); + assertThat(innerHits.getTotalHits().value, equalTo(1L)); assertThat(innerHits.getHits().length, equalTo(1)); assertThat(innerHits.getAt(0).getId(), equalTo("2")); assertThat(innerHits.getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); @@ -374,7 +374,7 @@ public class InnerHitsIT extends ESIntegTestCase { assertNoFailures(response); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); - assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getId(), equalTo("1")); assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getNestedIdentity().getField().string(), equalTo("comments")); @@ -438,7 +438,7 @@ public class InnerHitsIT extends ESIntegTestCase { SearchHit hit = response.getHits().getAt(0); assertThat(hit.getId(), equalTo("1")); SearchHits messages = hit.getInnerHits().get("comments.messages"); - assertThat(messages.getTotalHits(), equalTo(2L)); + assertThat(messages.getTotalHits().value, equalTo(2L)); assertThat(messages.getAt(0).getId(), equalTo("1")); assertThat(messages.getAt(0).getNestedIdentity().getField().string(), equalTo("comments.messages")); assertThat(messages.getAt(0).getNestedIdentity().getOffset(), equalTo(2)); @@ -456,7 +456,7 @@ public class InnerHitsIT extends ESIntegTestCase { hit = response.getHits().getAt(0); assertThat(hit.getId(), equalTo("1")); messages = hit.getInnerHits().get("comments.messages"); - assertThat(messages.getTotalHits(), equalTo(1L)); + assertThat(messages.getTotalHits().value, equalTo(1L)); assertThat(messages.getAt(0).getId(), equalTo("1")); assertThat(messages.getAt(0).getNestedIdentity().getField().string(), equalTo("comments.messages")); assertThat(messages.getAt(0).getNestedIdentity().getOffset(), equalTo(1)); @@ -477,7 +477,7 @@ public class InnerHitsIT extends ESIntegTestCase { hit = response.getHits().getAt(0); assertThat(hit.getId(), equalTo("1")); messages = hit.getInnerHits().get("comments.messages"); - assertThat(messages.getTotalHits(), equalTo(1L)); + assertThat(messages.getTotalHits().value, equalTo(1L)); assertThat(messages.getAt(0).getId(), equalTo("1")); assertThat(messages.getAt(0).getNestedIdentity().getField().string(), equalTo("comments.messages")); assertThat(messages.getAt(0).getNestedIdentity().getOffset(), equalTo(0)); @@ -566,9 +566,9 @@ public class InnerHitsIT extends ESIntegTestCase { .get(); assertNoFailures(searchResponse); assertAllSuccessful(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo((long) numDocs)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo((long) numDocs)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("0")); - assertThat(searchResponse.getHits().getAt(0).getInnerHits().get("nested1").getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getAt(0).getInnerHits().get("nested1").getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getAt(0).getInnerHits().get("nested1").getAt(0).getMatchedQueries().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getInnerHits().get("nested1").getAt(0).getMatchedQueries()[0], equalTo("test1")); assertThat(searchResponse.getHits().getAt(0).getInnerHits().get("nested1").getAt(1).getMatchedQueries().length, equalTo(1)); @@ -576,13 +576,13 @@ public class InnerHitsIT extends ESIntegTestCase { assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("1")); - assertThat(searchResponse.getHits().getAt(1).getInnerHits().get("nested1").getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getAt(1).getInnerHits().get("nested1").getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(1).getInnerHits().get("nested1").getAt(0).getMatchedQueries().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(1).getInnerHits().get("nested1").getAt(0).getMatchedQueries()[0], equalTo("test2")); for (int i = 2; i < numDocs; i++) { assertThat(searchResponse.getHits().getAt(i).getId(), equalTo(String.valueOf(i))); - assertThat(searchResponse.getHits().getAt(i).getInnerHits().get("nested1").getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getAt(i).getInnerHits().get("nested1").getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(i).getInnerHits().get("nested1").getAt(0).getMatchedQueries().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(i).getInnerHits().get("nested1").getAt(0).getMatchedQueries()[0], equalTo("test3")); } @@ -610,7 +610,7 @@ public class InnerHitsIT extends ESIntegTestCase { assertNoFailures(response); assertHitCount(response, 1); - assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getSourceAsMap().size(), equalTo(1)); assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getSourceAsMap().get("message"), equalTo("fox eat quick")); @@ -625,7 +625,7 @@ public class InnerHitsIT extends ESIntegTestCase { assertNoFailures(response); assertHitCount(response, 1); - assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getSourceAsMap().size(), equalTo(2)); assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getSourceAsMap().get("message"), equalTo("fox eat quick")); @@ -642,7 +642,7 @@ public class InnerHitsIT extends ESIntegTestCase { .get(); assertNoFailures(response); assertHitCount(response, 1); - assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getSourceAsMap().size(), equalTo(0)); } diff --git a/server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java b/server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java index b609889674f..87a7a5ba927 100644 --- a/server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java +++ b/server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java @@ -2662,7 +2662,7 @@ public class HighlighterSearchIT extends ESIntegTestCase { new SearchSourceBuilder().query(query) .highlighter(new HighlightBuilder().field("*").highlighterType(highlighterType))).get(); assertNoFailures(search); - assertThat(search.getHits().getTotalHits(), equalTo(1L)); + assertThat(search.getHits().getTotalHits().value, equalTo(1L)); assertThat(search.getHits().getAt(0).getHighlightFields().get("text").fragments().length, equalTo(1)); } @@ -2698,7 +2698,7 @@ public class HighlighterSearchIT extends ESIntegTestCase { SearchResponse search = client().prepareSearch().setSource( new SearchSourceBuilder().query(query).highlighter(new HighlightBuilder().highlighterType("plain").field("jd"))).get(); assertNoFailures(search); - assertThat(search.getHits().getTotalHits(), equalTo(1L)); + assertThat(search.getHits().getTotalHits().value, equalTo(1L)); } @@ -2725,7 +2725,7 @@ public class HighlighterSearchIT extends ESIntegTestCase { .query(QueryBuilders.matchQuery("keyword_field", "some text")) .highlighter(new HighlightBuilder().field("*"))).get(); assertNoFailures(search); - assertThat(search.getHits().getTotalHits(), equalTo(1L)); + assertThat(search.getHits().getTotalHits().value, equalTo(1L)); assertThat(search.getHits().getAt(0).getHighlightFields().get("keyword_field").getFragments()[0].string(), equalTo("some text")); } @@ -2833,7 +2833,7 @@ public class HighlighterSearchIT extends ESIntegTestCase { .get(); assertSearchResponse(r1); - assertThat(r1.getHits().getTotalHits(), equalTo(1L)); + assertThat(r1.getHits().getTotalHits().value, equalTo(1L)); assertHighlight(r1, 0, "field", 0, 1, equalTo("hello world")); } diff --git a/server/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java b/server/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java index 72ea99df8ff..39222ee7632 100644 --- a/server/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java +++ b/server/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java @@ -181,26 +181,26 @@ public class SearchFieldsIT extends ESIntegTestCase { client().admin().indices().prepareRefresh().execute().actionGet(); SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("field1").execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().size(), equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().get("field1").getValue().toString(), equalTo("value1")); // field2 is not stored, check that it is not extracted from source. searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("field2").execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().size(), equalTo(0)); assertThat(searchResponse.getHits().getAt(0).getFields().get("field2"), nullValue()); searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("field3").execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().size(), equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().get("field3").getValue().toString(), equalTo("value3")); searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("*3").execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().size(), equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().get("field3").getValue().toString(), equalTo("value3")); @@ -212,7 +212,7 @@ public class SearchFieldsIT extends ESIntegTestCase { .addStoredField("field1") .addStoredField("field2") .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().size(), equalTo(2)); assertThat(searchResponse.getHits().getAt(0).getFields().get("field3").getValue().toString(), equalTo("value3")); @@ -220,20 +220,20 @@ public class SearchFieldsIT extends ESIntegTestCase { searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("field*").execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().size(), equalTo(2)); assertThat(searchResponse.getHits().getAt(0).getFields().get("field3").getValue().toString(), equalTo("value3")); assertThat(searchResponse.getHits().getAt(0).getFields().get("field1").getValue().toString(), equalTo("value1")); searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("f*3").execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().size(), equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getFields().get("field3").getValue().toString(), equalTo("value3")); searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("*").execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getSourceAsMap(), nullValue()); assertThat(searchResponse.getHits().getAt(0).getFields().size(), equalTo(2)); @@ -245,7 +245,7 @@ public class SearchFieldsIT extends ESIntegTestCase { .addStoredField("*") .addStoredField("_source") .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getSourceAsMap(), notNullValue()); assertThat(searchResponse.getHits().getAt(0).getFields().size(), equalTo(2)); @@ -301,7 +301,7 @@ public class SearchFieldsIT extends ESIntegTestCase { assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertFalse(response.getHits().getAt(0).hasSource()); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); Set fields = new HashSet<>(response.getHits().getAt(0).getFields().keySet()); @@ -330,7 +330,7 @@ public class SearchFieldsIT extends ESIntegTestCase { .addScriptField("sNum1", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value * factor", params)) .get(); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); fields = new HashSet<>(response.getHits().getAt(0).getFields().keySet()); assertThat(fields, equalTo(singleton("sNum1"))); @@ -365,7 +365,7 @@ public class SearchFieldsIT extends ESIntegTestCase { assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), equalTo((long)numDocs)); + assertThat(response.getHits().getTotalHits().value, equalTo((long)numDocs)); for (int i = 0; i < numDocs; i++) { assertThat(response.getHits().getAt(i).getId(), equalTo(Integer.toString(i))); Set fields = new HashSet<>(response.getHits().getAt(i).getFields().keySet()); @@ -383,7 +383,7 @@ public class SearchFieldsIT extends ESIntegTestCase { assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), equalTo((long)numDocs)); + assertThat(response.getHits().getTotalHits().value, equalTo((long)numDocs)); for (int i = 0; i < numDocs; i++) { assertThat(response.getHits().getAt(i).getId(), equalTo(Integer.toString(i))); Set fields = new HashSet<>(response.getHits().getAt(i).getFields().keySet()); @@ -402,7 +402,7 @@ public class SearchFieldsIT extends ESIntegTestCase { assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), equalTo((long)numDocs)); + assertThat(response.getHits().getTotalHits().value, equalTo((long)numDocs)); for (int i = 0; i < numDocs; i++) { assertThat(response.getHits().getAt(i).getId(), equalTo(Integer.toString(i))); Set fields = new HashSet<>(response.getHits().getAt(i).getFields().keySet()); @@ -575,7 +575,7 @@ public class SearchFieldsIT extends ESIntegTestCase { .addStoredField("binary_field") .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); Set fields = new HashSet<>(searchResponse.getHits().getAt(0).getFields().keySet()); assertThat(fields, equalTo(newHashSet("byte_field", "short_field", "integer_field", "long_field", @@ -606,7 +606,7 @@ public class SearchFieldsIT extends ESIntegTestCase { .addStoredField("field1").addStoredField("_routing") .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).field("field1"), nullValue()); assertThat(searchResponse.getHits().getAt(0).field("_routing").isMetadataField(), equalTo(true)); assertThat(searchResponse.getHits().getAt(0).field("_routing").getValue().toString(), equalTo("1")); @@ -683,7 +683,7 @@ public class SearchFieldsIT extends ESIntegTestCase { String field = "field1.field2.field3.field4"; SearchResponse searchResponse = client().prepareSearch("my-index").addStoredField(field).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).field(field).isMetadataField(), equalTo(false)); assertThat(searchResponse.getHits().getAt(0).field(field).getValues().size(), equalTo(2)); assertThat(searchResponse.getHits().getAt(0).field(field).getValues().get(0).toString(), equalTo("value1")); @@ -791,7 +791,7 @@ public class SearchFieldsIT extends ESIntegTestCase { .addDocValueField("ip_field"); SearchResponse searchResponse = builder.execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); Set fields = new HashSet<>(searchResponse.getHits().getAt(0).getFields().keySet()); assertThat(fields, equalTo(newHashSet("byte_field", "short_field", "integer_field", "long_field", @@ -817,7 +817,7 @@ public class SearchFieldsIT extends ESIntegTestCase { .addDocValueField("*field"); searchResponse = builder.execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); fields = new HashSet<>(searchResponse.getHits().getAt(0).getFields().keySet()); assertThat(fields, equalTo(newHashSet("byte_field", "short_field", "integer_field", "long_field", @@ -854,7 +854,7 @@ public class SearchFieldsIT extends ESIntegTestCase { .addDocValueField("ip_field", "use_field_mapping"); searchResponse = builder.execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); fields = new HashSet<>(searchResponse.getHits().getAt(0).getFields().keySet()); assertThat(fields, equalTo(newHashSet("byte_field", "short_field", "integer_field", "long_field", @@ -885,7 +885,7 @@ public class SearchFieldsIT extends ESIntegTestCase { .addDocValueField("date_field", "epoch_millis"); searchResponse = builder.execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); fields = new HashSet<>(searchResponse.getHits().getAt(0).getFields().keySet()); assertThat(fields, equalTo(newHashSet("byte_field", "short_field", "integer_field", "long_field", diff --git a/server/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java b/server/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java index b9b0aa5b201..794e3baa0d5 100644 --- a/server/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java +++ b/server/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java @@ -123,7 +123,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { searchSource().query(baseQuery))); SearchResponse sr = response.actionGet(); SearchHits sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2))); + assertThat(sh.getTotalHits().value, equalTo((long) (numDummyDocs + 2))); response = client().search( searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( @@ -131,7 +131,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { functionScoreQuery(baseQuery, gaussDecayFunction("loc", lonlat, "1000km"))))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2))); + assertThat(sh.getTotalHits().value, equalTo((long) (numDummyDocs + 2))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat(sh.getAt(1).getId(), equalTo("2")); @@ -142,7 +142,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { searchSource().query(baseQuery))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2))); + assertThat(sh.getTotalHits().value, equalTo((long) (numDummyDocs + 2))); response = client().search( searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( @@ -150,7 +150,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { functionScoreQuery(baseQuery, linearDecayFunction("loc", lonlat, "1000km"))))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2))); + assertThat(sh.getTotalHits().value, equalTo((long) (numDummyDocs + 2))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat(sh.getAt(1).getId(), equalTo("2")); @@ -161,7 +161,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { searchSource().query(baseQuery))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2))); + assertThat(sh.getTotalHits().value, equalTo((long) (numDummyDocs + 2))); response = client().search( searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( @@ -169,7 +169,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { functionScoreQuery(baseQuery, exponentialDecayFunction("loc", lonlat, "1000km"))))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2))); + assertThat(sh.getTotalHits().value, equalTo((long) (numDummyDocs + 2))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat(sh.getAt(1).getId(), equalTo("2")); @@ -207,7 +207,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { .boostMode(CombineFunction.REPLACE)))); SearchResponse sr = response.actionGet(); SearchHits sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2))); + assertThat(sh.getTotalHits().value, equalTo((long) (numDummyDocs + 2))); assertThat(sh.getAt(0).getId(), anyOf(equalTo("1"), equalTo("2"))); assertThat(sh.getAt(1).getId(), anyOf(equalTo("1"), equalTo("2"))); assertThat(sh.getAt(1).getScore(), equalTo(sh.getAt(0).getScore())); @@ -226,7 +226,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { CombineFunction.REPLACE)))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2))); + assertThat(sh.getTotalHits().value, equalTo((long) (numDummyDocs + 2))); assertThat(sh.getAt(0).getId(), anyOf(equalTo("1"), equalTo("2"))); assertThat(sh.getAt(1).getId(), anyOf(equalTo("1"), equalTo("2"))); assertThat(sh.getAt(1).getScore(), equalTo(sh.getAt(0).getScore())); @@ -242,7 +242,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { .boostMode(CombineFunction.REPLACE)))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2))); + assertThat(sh.getTotalHits().value, equalTo((long) (numDummyDocs + 2))); assertThat(sh.getAt(0).getId(), anyOf(equalTo("1"), equalTo("2"))); assertThat(sh.getAt(1).getId(), anyOf(equalTo("1"), equalTo("2"))); assertThat(sh.getAt(1).getScore(), equalTo(sh.getAt(0).getScore())); @@ -292,7 +292,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { CombineFunction.MULTIPLY)))); SearchResponse sr = response.actionGet(); SearchHits sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (2))); + assertThat(sh.getTotalHits().value, equalTo((long) (2))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat(sh.getAt(1).getId(), equalTo("2")); @@ -302,7 +302,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { searchSource().query(termQuery("test", "value")))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (2))); + assertThat(sh.getTotalHits().value, equalTo((long) (2))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat(sh.getAt(1).getId(), equalTo("2")); @@ -313,7 +313,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { CombineFunction.REPLACE)))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (2))); + assertThat(sh.getTotalHits().value, equalTo((long) (2))); assertThat(sh.getAt(0).getId(), equalTo("2")); assertThat(sh.getAt(1).getId(), equalTo("1")); @@ -347,7 +347,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { CombineFunction.REPLACE)))); SearchResponse sr = response.actionGet(); SearchHits sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (1))); + assertThat(sh.getTotalHits().value, equalTo((long) (1))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat((double) sh.getAt(0).getScore(), closeTo(1.0, 1.e-5)); // this is equivalent to new GeoPoint(20, 11); just flipped so scores must be same @@ -359,7 +359,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { CombineFunction.REPLACE)))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (1))); + assertThat(sh.getTotalHits().value, equalTo((long) (1))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat((double) sh.getAt(0).getScore(), closeTo(1.0f, 1.e-5)); } @@ -382,7 +382,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { .boostMode(CombineFunction.MULTIPLY)))); SearchResponse sr = response.actionGet(); SearchHits sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (1))); + assertThat(sh.getTotalHits().value, equalTo((long) (1))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat((double) sh.getAt(0).getScore(), closeTo(1.0, 1.e-5)); @@ -393,7 +393,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { .boostMode(CombineFunction.REPLACE)))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (1))); + assertThat(sh.getTotalHits().value, equalTo((long) (1))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat((double) sh.getAt(0).getScore(), closeTo(0.5, 1.e-5)); @@ -404,7 +404,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { .boostMode(CombineFunction.SUM)))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (1))); + assertThat(sh.getTotalHits().value, equalTo((long) (1))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat((double) sh.getAt(0).getScore(), closeTo(2.0 + 0.5, 1.e-5)); logger.info("--> Hit[0] {} Explanation:\n {}", sr.getHits().getAt(0).getId(), sr.getHits().getAt(0).getExplanation()); @@ -416,7 +416,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { .boostMode(CombineFunction.AVG)))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (1))); + assertThat(sh.getTotalHits().value, equalTo((long) (1))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat((double) sh.getAt(0).getScore(), closeTo((2.0 + 0.5) / 2, 1.e-5)); @@ -427,7 +427,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { .boostMode(CombineFunction.MIN)))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (1))); + assertThat(sh.getTotalHits().value, equalTo((long) (1))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat((double) sh.getAt(0).getScore(), closeTo(0.5, 1.e-5)); @@ -438,7 +438,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { .boostMode(CombineFunction.MAX)))); sr = response.actionGet(); sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (1))); + assertThat(sh.getTotalHits().value, equalTo((long) (1))); assertThat(sh.getAt(0).getId(), equalTo("1")); assertThat((double) sh.getAt(0).getScore(), closeTo(2.0, 1.e-5)); @@ -768,7 +768,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { SearchResponse sr = response.actionGet(); assertSearchHits(sr, "1", "2"); SearchHits sh = sr.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) (2))); + assertThat(sh.getTotalHits().value, equalTo((long) (2))); List lonlat = new ArrayList<>(); lonlat.add(20f); diff --git a/server/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java b/server/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java index c4b085e84cf..dec5663ca70 100644 --- a/server/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java +++ b/server/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java @@ -135,7 +135,7 @@ public class ExplainableScriptIT extends ESIntegTestCase { ElasticsearchAssertions.assertNoFailures(response); SearchHits hits = response.getHits(); - assertThat(hits.getTotalHits(), equalTo(20L)); + assertThat(hits.getTotalHits().value, equalTo(20L)); int idCounter = 19; for (SearchHit hit : hits.getHits()) { assertThat(hit.getId(), equalTo(Integer.toString(idCounter))); diff --git a/server/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreIT.java b/server/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreIT.java index bc590dca822..7b4ec5aa0bf 100644 --- a/server/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreIT.java +++ b/server/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreIT.java @@ -146,9 +146,9 @@ public class FunctionScoreIT extends ESIntegTestCase { searchRequest().source(searchSource().query(functionScoreQuery(scriptFunction(script)).setMinScore(minScore))) ).actionGet(); if (score < minScore) { - assertThat(searchResponse.getHits().getTotalHits(), is(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, is(0L)); } else { - assertThat(searchResponse.getHits().getTotalHits(), is(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, is(1L)); } searchResponse = client().search( @@ -158,9 +158,9 @@ public class FunctionScoreIT extends ESIntegTestCase { }).scoreMode(FunctionScoreQuery.ScoreMode.AVG).setMinScore(minScore))) ).actionGet(); if (score < minScore) { - assertThat(searchResponse.getHits().getTotalHits(), is(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, is(0L)); } else { - assertThat(searchResponse.getHits().getTotalHits(), is(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, is(1L)); } } @@ -197,9 +197,9 @@ public class FunctionScoreIT extends ESIntegTestCase { protected void assertMinScoreSearchResponses(int numDocs, SearchResponse searchResponse, int numMatchingDocs) { assertSearchResponse(searchResponse); - assertThat((int) searchResponse.getHits().getTotalHits(), is(numMatchingDocs)); + assertThat((int) searchResponse.getHits().getTotalHits().value, is(numMatchingDocs)); int pos = 0; - for (int hitId = numDocs - 1; (numDocs - hitId) < searchResponse.getHits().getTotalHits(); hitId--) { + for (int hitId = numDocs - 1; (numDocs - hitId) < searchResponse.getHits().getTotalHits().value; hitId--) { assertThat(searchResponse.getHits().getAt(pos).getId(), equalTo(Integer.toString(hitId))); pos++; } @@ -216,7 +216,7 @@ public class FunctionScoreIT extends ESIntegTestCase { searchSource().explain(true).query( termQuery("text", "text")))).get(); assertSearchResponse(termQuery); - assertThat(termQuery.getHits().getTotalHits(), equalTo(1L)); + assertThat(termQuery.getHits().getTotalHits().value, equalTo(1L)); float termQueryScore = termQuery.getHits().getAt(0).getScore(); for (CombineFunction combineFunction : CombineFunction.values()) { @@ -230,7 +230,7 @@ public class FunctionScoreIT extends ESIntegTestCase { searchSource().explain(true).query( functionScoreQuery(termQuery("text", "text")).boostMode(boostMode).setMinScore(0.1f)))).get(); assertSearchResponse(response); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getScore(), equalTo(expectedScore)); response = client().search( @@ -239,7 +239,7 @@ public class FunctionScoreIT extends ESIntegTestCase { functionScoreQuery(termQuery("text", "text")).boostMode(boostMode).setMinScore(2f)))).get(); assertSearchResponse(response); - assertThat(response.getHits().getTotalHits(), equalTo(0L)); + assertThat(response.getHits().getTotalHits().value, equalTo(0L)); } } diff --git a/server/src/test/java/org/elasticsearch/search/functionscore/QueryRescorerIT.java b/server/src/test/java/org/elasticsearch/search/functionscore/QueryRescorerIT.java index aa9d9c4b87e..e0f549a1c1c 100644 --- a/server/src/test/java/org/elasticsearch/search/functionscore/QueryRescorerIT.java +++ b/server/src/test/java/org/elasticsearch/search/functionscore/QueryRescorerIT.java @@ -126,7 +126,7 @@ public class QueryRescorerIT extends ESIntegTestCase { new QueryRescorerBuilder(matchPhraseQuery("field1", "quick brown").slop(2).boost(4.0f)) .setRescoreQueryWeight(2), 5).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getMaxScore(), equalTo(searchResponse.getHits().getHits()[0].getScore())); assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("1")); assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("3")); @@ -366,7 +366,7 @@ public class QueryRescorerIT extends ESIntegTestCase { assertNoFailures(rescored); SearchHits leftHits = plain.getHits(); SearchHits rightHits = rescored.getHits(); - assertThat(leftHits.getTotalHits(), equalTo(rightHits.getTotalHits())); + assertThat(leftHits.getTotalHits().value, equalTo(rightHits.getTotalHits().value)); assertThat(leftHits.getHits().length, equalTo(rightHits.getHits().length)); SearchHit[] hits = leftHits.getHits(); SearchHit[] rHits = rightHits.getHits(); @@ -730,7 +730,7 @@ public class QueryRescorerIT extends ESIntegTestCase { .setTrackScores(true) .addRescorer(new QueryRescorerBuilder(matchAllQuery()).setRescoreQueryWeight(100.0f), 50) .get(); - assertThat(resp.getHits().totalHits, equalTo(5L)); + assertThat(resp.getHits().getTotalHits().value, equalTo(5L)); assertThat(resp.getHits().getHits().length, equalTo(5)); for (SearchHit hit : resp.getHits().getHits()) { assertThat(hit.getScore(), equalTo(101f)); diff --git a/server/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionIT.java b/server/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionIT.java index 8203dac1a2d..508b9e953cf 100644 --- a/server/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionIT.java +++ b/server/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionIT.java @@ -262,7 +262,7 @@ public class RandomScoreFunctionIT extends ESIntegTestCase { .setExplain(true) .get(); assertNoFailures(resp); - assertEquals(1, resp.getHits().getTotalHits()); + assertEquals(1, resp.getHits().getTotalHits().value); SearchHit firstHit = resp.getHits().getAt(0); assertThat(firstHit.getExplanation().toString(), containsString("" + seed)); } @@ -275,13 +275,13 @@ public class RandomScoreFunctionIT extends ESIntegTestCase { .setQuery(functionScoreQuery(matchAllQuery(), randomFunction().seed(1234).setField(SeqNoFieldMapper.NAME))) .get(); assertNoFailures(resp); - assertEquals(0, resp.getHits().getTotalHits()); + assertEquals(0, resp.getHits().getTotalHits().value); resp = client().prepareSearch("test") .setQuery(functionScoreQuery(matchAllQuery(), randomFunction())) .get(); assertNoFailures(resp); - assertEquals(0, resp.getHits().getTotalHits()); + assertEquals(0, resp.getHits().getTotalHits().value); } public void testScoreRange() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/search/geo/GeoBoundingBoxIT.java b/server/src/test/java/org/elasticsearch/search/geo/GeoBoundingBoxIT.java index 32b80089c20..3290875419a 100644 --- a/server/src/test/java/org/elasticsearch/search/geo/GeoBoundingBoxIT.java +++ b/server/src/test/java/org/elasticsearch/search/geo/GeoBoundingBoxIT.java @@ -102,7 +102,7 @@ public class GeoBoundingBoxIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch() // from NY .setQuery(geoBoundingBoxQuery("location").setCorners(40.73, -74.1, 40.717, -73.99)) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getHits().length, equalTo(2)); for (SearchHit hit : searchResponse.getHits()) { assertThat(hit.getId(), anyOf(equalTo("1"), equalTo("3"), equalTo("5"))); @@ -111,7 +111,7 @@ public class GeoBoundingBoxIT extends ESIntegTestCase { searchResponse = client().prepareSearch() // from NY .setQuery(geoBoundingBoxQuery("location").setCorners(40.73, -74.1, 40.717, -73.99).type("indexed")) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getHits().length, equalTo(2)); for (SearchHit hit : searchResponse.getHits()) { assertThat(hit.getId(), anyOf(equalTo("1"), equalTo("3"), equalTo("5"))); @@ -149,26 +149,26 @@ public class GeoBoundingBoxIT extends ESIntegTestCase { boolQuery().must(termQuery("userid", 880)).filter( geoBoundingBoxQuery("location").setCorners(74.579421999999994, 143.5, -66.668903999999998, 113.96875)) ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch() .setQuery( boolQuery().must(termQuery("userid", 880)).filter( geoBoundingBoxQuery("location").setCorners(74.579421999999994, 143.5, -66.668903999999998, 113.96875).type("indexed")) ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch() .setQuery( boolQuery().must(termQuery("userid", 534)).filter( geoBoundingBoxQuery("location").setCorners(74.579421999999994, 143.5, -66.668903999999998, 113.96875)) ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch() .setQuery( boolQuery().must(termQuery("userid", 534)).filter( geoBoundingBoxQuery("location").setCorners(74.579421999999994, 143.5, -66.668903999999998, 113.96875).type("indexed")) ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); } public void testCompleteLonRange() throws Exception { @@ -201,43 +201,43 @@ public class GeoBoundingBoxIT extends ESIntegTestCase { .setQuery( geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(50, -180, -50, 180) ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch() .setQuery( geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(50, -180, -50, 180).type("indexed") ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch() .setQuery( geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(90, -180, -90, 180) ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); searchResponse = client().prepareSearch() .setQuery( geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(90, -180, -90, 180).type("indexed") ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); searchResponse = client().prepareSearch() .setQuery( geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(50, 0, -50, 360) ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch() .setQuery( geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(50, 0, -50, 360).type("indexed") ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch() .setQuery( geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(90, 0, -90, 360) ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); searchResponse = client().prepareSearch() .setQuery( geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(90, 0, -90, 360).type("indexed") ).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); } } diff --git a/server/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java b/server/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java index 83b79562118..854872730e8 100644 --- a/server/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java @@ -119,7 +119,7 @@ public class GeoShapeIntegrationIT extends ESIntegTestCase { indexRandom(true, client().prepareIndex("test", "geometry", "0").setSource("shape", polygonGeoJson)); SearchResponse searchResponse = client().prepareSearch("test").setQuery(matchAllQuery()).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); } /** @@ -156,7 +156,7 @@ public class GeoShapeIntegrationIT extends ESIntegTestCase { geoShapeQuery("shape", "0", "doc").indexedShapeIndex("test").indexedShapeRouting("ABC") ).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); } private String findNodeName(String index) { diff --git a/server/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java b/server/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java index 9e0f51b9985..9f2d1ea8a57 100644 --- a/server/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java +++ b/server/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java @@ -111,7 +111,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { .execute().actionGet(); assertSearchResponse(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); @@ -120,7 +120,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { .execute().actionGet(); assertSearchResponse(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); } @@ -157,7 +157,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { .execute().actionGet(); assertSearchResponse(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("blakely")); } @@ -190,7 +190,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { .execute().actionGet(); assertSearchResponse(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); @@ -199,7 +199,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { .execute().actionGet(); assertSearchResponse(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); } @@ -370,7 +370,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { .setPostFilter(filter).get(); assertSearchResponse(response); - assertThat(response.getHits().getTotalHits(), greaterThan(0L)); + assertThat(response.getHits().getTotalHits().value, greaterThan(0L)); } public void testShapeFilterWithDefinedGeoCollection() throws Exception { @@ -469,7 +469,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { .setQuery(geoIntersectionQuery("location", shape)) .execute().actionGet(); - assertEquals(1, response.getHits().getTotalHits()); + assertEquals(1, response.getHits().getTotalHits().value); } public void testPointsOnlyExplicit() throws Exception { @@ -503,7 +503,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { .setQuery(matchAllQuery()) .execute().actionGet(); - assertEquals(2, response.getHits().getTotalHits()); + assertEquals(2, response.getHits().getTotalHits().value); } public void testFieldAlias() throws IOException { @@ -532,7 +532,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { SearchResponse response = client().prepareSearch("test") .setQuery(geoShapeQuery("alias", shape)) .execute().actionGet(); - assertEquals(1, response.getHits().getTotalHits()); + assertEquals(1, response.getHits().getTotalHits().value); } // Test for issue #34418 @@ -599,7 +599,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { SearchResponse response = client().prepareSearch("test") .setQuery(querySupplier.get()) .execute().actionGet(); - assertEquals(2, response.getHits().getTotalHits()); + assertEquals(2, response.getHits().getTotalHits().value); assertNotEquals("1", response.getHits().getAt(0).getId()); assertNotEquals("1", response.getHits().getAt(1).getId()); } diff --git a/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java b/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java index 6180f4ec88f..280b1304218 100644 --- a/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java +++ b/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java @@ -673,7 +673,7 @@ public class MoreLikeThisIT extends ESIntegTestCase { moreLikeThisQueryBuilder.minTermFreq(1); moreLikeThisQueryBuilder.minDocFreq(1); SearchResponse searchResponse = client().prepareSearch("index").setQuery(moreLikeThisQueryBuilder).get(); - assertEquals(2, searchResponse.getHits().totalHits); + assertEquals(2, searchResponse.getHits().getTotalHits().value); } //Issue #29678 diff --git a/server/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java b/server/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java index 6d8bcfb6131..7829bcf0c80 100644 --- a/server/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java +++ b/server/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java @@ -64,9 +64,9 @@ public class SimpleNestedIT extends ESIntegTestCase { // check on no data, see it works SearchResponse searchResponse = client().prepareSearch("test").execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); searchResponse = client().prepareSearch("test").setQuery(termQuery("n_field1", "n_value1_1")).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() .field("field1", "value1") @@ -91,22 +91,22 @@ public class SimpleNestedIT extends ESIntegTestCase { assertDocumentCount("test", 3); searchResponse = client().prepareSearch("test").setQuery(termQuery("n_field1", "n_value1_1")).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); // search for something that matches the nested doc, and see that we don't find the nested doc searchResponse = client().prepareSearch("test").setQuery(matchAllQuery()).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch("test").setQuery(termQuery("n_field1", "n_value1_1")).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); // now, do a nested query searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1_1"), ScoreMode.Avg)).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1_1"), ScoreMode.Avg)).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); // add another doc, one that would match if it was not nested... @@ -130,19 +130,19 @@ public class SimpleNestedIT extends ESIntegTestCase { searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", boolQuery().must(termQuery("nested1.n_field1", "n_value1_1")).must(termQuery("nested1.n_field2", "n_value2_1")), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); // filter searchResponse = client().prepareSearch("test").setQuery(boolQuery().must(matchAllQuery()).mustNot(nestedQuery("nested1", boolQuery().must(termQuery("nested1.n_field1", "n_value1_1")).must(termQuery("nested1.n_field2", "n_value2_1")), ScoreMode.Avg))).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); // check with type prefix searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", boolQuery().must(termQuery("nested1.n_field1", "n_value1_1")).must(termQuery("nested1.n_field2", "n_value2_1")), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); // check delete, so all is gone... DeleteResponse deleteResponse = client().prepareDelete("test", "type1", "2").execute().actionGet(); @@ -153,7 +153,7 @@ public class SimpleNestedIT extends ESIntegTestCase { searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1_1"), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); } public void testMultiNested() throws Exception { @@ -186,42 +186,42 @@ public class SimpleNestedIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("nested1.field1", "1"), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1.nested2", termQuery("nested1.nested2.field2", "2"), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", boolQuery().must(termQuery("nested1.field1", "1")).must(nestedQuery("nested1.nested2", termQuery("nested1.nested2.field2", "2"), ScoreMode.Avg)), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", boolQuery().must(termQuery("nested1.field1", "1")).must(nestedQuery("nested1.nested2", termQuery("nested1.nested2.field2", "3"), ScoreMode.Avg)), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", boolQuery().must(termQuery("nested1.field1", "1")).must(nestedQuery("nested1.nested2", termQuery("nested1.nested2.field2", "4"), ScoreMode.Avg)), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", boolQuery().must(termQuery("nested1.field1", "1")).must(nestedQuery("nested1.nested2", termQuery("nested1.nested2.field2", "5"), ScoreMode.Avg)), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", boolQuery().must(termQuery("nested1.field1", "4")).must(nestedQuery("nested1.nested2", termQuery("nested1.nested2.field2", "5"), ScoreMode.Avg)), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", boolQuery().must(termQuery("nested1.field1", "4")).must(nestedQuery("nested1.nested2", termQuery("nested1.nested2.field2", "2"), ScoreMode.Avg)), ScoreMode.Avg)).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); } // When IncludeNestedDocsQuery is wrapped in a FilteredQuery then a in-finite loop occurs b/c of a bug in IncludeNestedDocsQuery#advance() @@ -307,7 +307,7 @@ public class SimpleNestedIT extends ESIntegTestCase { .setExplain(true) .execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); Explanation explanation = searchResponse.getHits().getHits()[0].getExplanation(); assertThat(explanation.getValue(), equalTo(searchResponse.getHits().getHits()[0].getScore())); assertThat(explanation.toString(), startsWith("0.36464313 = Score based on 2 child docs in range from 0 to 1")); @@ -1353,7 +1353,7 @@ public class SimpleNestedIT extends ESIntegTestCase { .setQuery(nestedQuery("array1", termQuery("array1.field1", "value1"), ScoreMode.Avg)) .get(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(5L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(5L)); } clusterStatsResponse = client().admin().cluster().prepareClusterStats().get(); assertThat(clusterStatsResponse.getIndicesStats().getSegments().getBitsetMemoryInBytes(), greaterThan(0L)); diff --git a/server/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java b/server/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java index 8cbb626b677..a531eaed1e9 100644 --- a/server/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java +++ b/server/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java @@ -113,13 +113,13 @@ public class SearchPreferenceIT extends ESIntegTestCase { refresh(); SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch().setQuery(matchAllQuery()).setPreference("_local").execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); searchResponse = client().prepareSearch().setQuery(matchAllQuery()).setPreference("1234").execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); } public void testThatSpecifyingNonExistingNodesReturnsUsefulError() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/search/profile/query/QueryProfilerIT.java b/server/src/test/java/org/elasticsearch/search/profile/query/QueryProfilerIT.java index f5cc517dd47..e3fc1c8e143 100644 --- a/server/src/test/java/org/elasticsearch/search/profile/query/QueryProfilerIT.java +++ b/server/src/test/java/org/elasticsearch/search/profile/query/QueryProfilerIT.java @@ -166,10 +166,10 @@ public class QueryProfilerIT extends ESIntegTestCase { vanillaMaxScore, profileMaxScore, 0.001); } - if (vanillaResponse.getHits().totalHits != profileResponse.getHits().totalHits) { + if (vanillaResponse.getHits().getTotalHits().value != profileResponse.getHits().getTotalHits().value) { Set vanillaSet = new HashSet<>(Arrays.asList(vanillaResponse.getHits().getHits())); Set profileSet = new HashSet<>(Arrays.asList(profileResponse.getHits().getHits())); - if (vanillaResponse.getHits().totalHits > profileResponse.getHits().totalHits) { + if (vanillaResponse.getHits().getTotalHits().value > profileResponse.getHits().getTotalHits().value) { vanillaSet.removeAll(profileSet); fail("Vanilla hits were larger than profile hits. Non-overlapping elements were: " + vanillaSet.toString()); diff --git a/server/src/test/java/org/elasticsearch/search/query/ExistsIT.java b/server/src/test/java/org/elasticsearch/search/query/ExistsIT.java index 45910044d49..6ec9e66ba2a 100644 --- a/server/src/test/java/org/elasticsearch/search/query/ExistsIT.java +++ b/server/src/test/java/org/elasticsearch/search/query/ExistsIT.java @@ -129,7 +129,7 @@ public class ExistsIT extends ESIntegTestCase { SearchResponse resp = client().prepareSearch("idx").setQuery(QueryBuilders.existsQuery(fieldName)).execute().actionGet(); assertSearchResponse(resp); try { - assertEquals(String.format(Locale.ROOT, "exists(%s, %d) mapping: %s response: %s", fieldName, count, Strings.toString(mapping), resp), count, resp.getHits().getTotalHits()); + assertEquals(String.format(Locale.ROOT, "exists(%s, %d) mapping: %s response: %s", fieldName, count, Strings.toString(mapping), resp), count, resp.getHits().getTotalHits().value); } catch (AssertionError e) { for (SearchHit searchHit : allDocs.getHits()) { final String index = searchHit.getIndex(); diff --git a/server/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java b/server/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java index 926839f2af2..806307d0929 100644 --- a/server/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java +++ b/server/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java @@ -236,7 +236,7 @@ public class MultiMatchQueryIT extends ESIntegTestCase { searchResponse = client().prepareSearch("test") .setQuery(randomizeType(multiMatchQuery("Captain", "full_name_phrase", "first_name_phrase", "last_name_phrase", "category_phrase") .operator(Operator.OR).type(MatchQuery.Type.PHRASE))).get(); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(1L)); searchResponse = client().prepareSearch("test") .setQuery(randomizeType(multiMatchQuery("the Ul", "full_name_phrase", "first_name_phrase", "last_name_phrase", "category_phrase") @@ -285,7 +285,7 @@ public class MultiMatchQueryIT extends ESIntegTestCase { .addSort("_score", SortOrder.DESC) .addSort("_id", SortOrder.ASC) .setQuery(matchQueryBuilder).get(); - assertThat("field: " + field + " query: " + builder.toString(), multiMatchResp.getHits().getTotalHits(), equalTo(matchResp.getHits().getTotalHits())); + assertThat("field: " + field + " query: " + builder.toString(), multiMatchResp.getHits().getTotalHits().value, equalTo(matchResp.getHits().getTotalHits().value)); SearchHits hits = multiMatchResp.getHits(); if (field.startsWith("missing")) { assertEquals(0, hits.getHits().length); @@ -300,7 +300,7 @@ public class MultiMatchQueryIT extends ESIntegTestCase { public void testCutoffFreq() throws ExecutionException, InterruptedException { final long numDocs = client().prepareSearch("test").setSize(0) - .setQuery(matchAllQuery()).get().getHits().getTotalHits(); + .setQuery(matchAllQuery()).get().getHits().getTotalHits().value; MatchQuery.Type type = MatchQuery.Type.BOOLEAN; Float cutoffFrequency = randomBoolean() ? Math.min(1, numDocs * 1.f / between(10, 20)) : 1.f / between(10, 20); SearchResponse searchResponse = client().prepareSearch("test") @@ -321,13 +321,13 @@ public class MultiMatchQueryIT extends ESIntegTestCase { .operator(Operator.OR).useDisMax(false).cutoffFrequency(cutoffFrequency).type(type))).get(); assertFirstHit(searchResponse, anyOf(hasId("theone"), hasId("theother"))); assertThat(searchResponse.getHits().getHits()[0].getScore(), greaterThan(searchResponse.getHits().getHits()[1].getScore())); - long size = searchResponse.getHits().getTotalHits(); + long size = searchResponse.getHits().getTotalHits().value; searchResponse = client().prepareSearch("test") .setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category") .operator(Operator.OR).useDisMax(false).type(type))).get(); assertFirstHit(searchResponse, anyOf(hasId("theone"), hasId("theother"))); - assertThat("common terms expected to be a way smaller result set", size, lessThan(searchResponse.getHits().getTotalHits())); + assertThat("common terms expected to be a way smaller result set", size, lessThan(searchResponse.getHits().getTotalHits().value)); cutoffFrequency = randomBoolean() ? Math.min(1, numDocs * 1.f / between(10, 20)) : 1.f / between(10, 20); searchResponse = client().prepareSearch("test") @@ -360,7 +360,7 @@ public class MultiMatchQueryIT extends ESIntegTestCase { public void testEquivalence() { final int numDocs = (int) client().prepareSearch("test").setSize(0) - .setQuery(matchAllQuery()).get().getHits().getTotalHits(); + .setQuery(matchAllQuery()).get().getHits().getTotalHits().value; int numIters = scaledRandomIntBetween(5, 10); for (int i = 0; i < numIters; i++) { { @@ -555,14 +555,14 @@ public class MultiMatchQueryIT extends ESIntegTestCase { .analyzer("category") .operator(Operator.OR))).get(); assertFirstHit(searchResponse, anyOf(hasId("theother"), hasId("theone"))); - long numResults = searchResponse.getHits().getTotalHits(); + long numResults = searchResponse.getHits().getTotalHits().value; searchResponse = client().prepareSearch("test") .setQuery(randomizeType(multiMatchQuery("captain america marvel hero", "first_name", "last_name", "category") .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS) .analyzer("category") .operator(Operator.OR))).get(); - assertThat(numResults, lessThan(searchResponse.getHits().getTotalHits())); + assertThat(numResults, lessThan(searchResponse.getHits().getTotalHits().value)); assertFirstHit(searchResponse, hasId("theone")); @@ -707,7 +707,7 @@ public class MultiMatchQueryIT extends ESIntegTestCase { assertNoFailures(right); SearchHits leftHits = left.getHits(); SearchHits rightHits = right.getHits(); - assertThat(leftHits.getTotalHits(), equalTo(rightHits.getTotalHits())); + assertThat(leftHits.getTotalHits().value, equalTo(rightHits.getTotalHits().value)); assertThat(leftHits.getHits().length, equalTo(rightHits.getHits().length)); SearchHit[] hits = leftHits.getHits(); SearchHit[] rHits = rightHits.getHits(); diff --git a/server/src/test/java/org/elasticsearch/search/query/QueryStringIT.java b/server/src/test/java/org/elasticsearch/search/query/QueryStringIT.java index 00f42b383e5..969e9004e8f 100644 --- a/server/src/test/java/org/elasticsearch/search/query/QueryStringIT.java +++ b/server/src/test/java/org/elasticsearch/search/query/QueryStringIT.java @@ -360,7 +360,7 @@ public class QueryStringIT extends ESIntegTestCase { } private void assertHits(SearchHits hits, String... ids) { - assertThat(hits.getTotalHits(), equalTo((long) ids.length)); + assertThat(hits.getTotalHits().value, equalTo((long) ids.length)); Set hitIds = new HashSet<>(); for (SearchHit hit : hits.getHits()) { hitIds.add(hit.getId()); diff --git a/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java b/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java index 6068f890259..da9c01103b3 100644 --- a/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java +++ b/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java @@ -228,7 +228,7 @@ public class SearchQueryIT extends ESIntegTestCase { for (int i = 0; i < queryRounds; i++) { MatchQueryBuilder matchQuery = matchQuery("f", English.intToEnglish(between(0, num))); searchResponse = client().prepareSearch("test_1").setQuery(constantScoreQuery(matchQuery)).setSize(num).get(); - long totalHits = searchResponse.getHits().getTotalHits(); + long totalHits = searchResponse.getHits().getTotalHits().value; SearchHits hits = searchResponse.getHits(); for (SearchHit searchHit : hits) { assertThat(searchHit, hasScore(1.0f)); @@ -237,7 +237,7 @@ public class SearchQueryIT extends ESIntegTestCase { boolQuery().must(matchAllQuery()).must( constantScoreQuery(matchQuery).boost(1.0f + (random.nextBoolean()? 0.0f : random.nextFloat())))).setSize(num).get(); hits = searchResponse.getHits(); - assertThat(hits.getTotalHits(), equalTo(totalHits)); + assertThat(hits.getTotalHits().value, equalTo(totalHits)); if (totalHits > 1) { float expected = hits.getAt(0).getScore(); for (SearchHit searchHit : hits) { @@ -284,7 +284,7 @@ public class SearchQueryIT extends ESIntegTestCase { assertThirdHit(searchResponse, hasId("3")); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.AND)).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertFirstHit(searchResponse, hasId("1")); assertSecondHit(searchResponse, hasId("2")); @@ -1641,7 +1641,7 @@ public class SearchQueryIT extends ESIntegTestCase { .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setQuery(QueryBuilders.queryStringQuery("xyz").boost(100)) .get(); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); float first = response.getHits().getAt(0).getScore(); @@ -1651,7 +1651,7 @@ public class SearchQueryIT extends ESIntegTestCase { .setQuery(QueryBuilders.queryStringQuery("xyz").boost(100)) .get(); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); float actual = response.getHits().getAt(0).getScore(); assertThat(i + " expected: " + first + " actual: " + actual, Float.compare(first, actual), equalTo(0)); diff --git a/server/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java b/server/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java index 197f34cf879..5451095acf3 100644 --- a/server/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java +++ b/server/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java @@ -665,7 +665,7 @@ public class SimpleQueryStringIT extends ESIntegTestCase { } private void assertHits(SearchHits hits, String... ids) { - assertThat(hits.getTotalHits(), equalTo((long) ids.length)); + assertThat(hits.getTotalHits().value, equalTo((long) ids.length)); Set hitIds = new HashSet<>(); for (SearchHit hit : hits.getHits()) { hitIds.add(hit.getId()); diff --git a/server/src/test/java/org/elasticsearch/search/scriptfilter/ScriptQuerySearchIT.java b/server/src/test/java/org/elasticsearch/search/scriptfilter/ScriptQuerySearchIT.java index 16a9d99b783..fbc135f7cf3 100644 --- a/server/src/test/java/org/elasticsearch/search/scriptfilter/ScriptQuerySearchIT.java +++ b/server/src/test/java/org/elasticsearch/search/scriptfilter/ScriptQuerySearchIT.java @@ -133,7 +133,7 @@ public class ScriptQuerySearchIT extends ESIntegTestCase { new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['binaryData'].get(0).length", emptyMap())) .get(); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getId(), equalTo("2")); assertThat(response.getHits().getAt(0).getFields().get("sbinaryData").getValues().get(0), equalTo(16)); @@ -180,7 +180,7 @@ public class ScriptQuerySearchIT extends ESIntegTestCase { new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value", Collections.emptyMap())) .get(); - assertThat(response.getHits().getTotalHits(), equalTo(2L)); + assertThat(response.getHits().getTotalHits().value, equalTo(2L)); assertThat(response.getHits().getAt(0).getId(), equalTo("2")); assertThat(response.getHits().getAt(0).getFields().get("sNum1").getValues().get(0), equalTo(2.0)); assertThat(response.getHits().getAt(1).getId(), equalTo("3")); @@ -198,7 +198,7 @@ public class ScriptQuerySearchIT extends ESIntegTestCase { new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value", Collections.emptyMap())) .get(); - assertThat(response.getHits().getTotalHits(), equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getId(), equalTo("3")); assertThat(response.getHits().getAt(0).getFields().get("sNum1").getValues().get(0), equalTo(3.0)); @@ -213,7 +213,7 @@ public class ScriptQuerySearchIT extends ESIntegTestCase { new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value", Collections.emptyMap())) .get(); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); assertThat(response.getHits().getAt(0).getFields().get("sNum1").getValues().get(0), equalTo(1.0)); assertThat(response.getHits().getAt(1).getId(), equalTo("2")); diff --git a/server/src/test/java/org/elasticsearch/search/scroll/DuelScrollIT.java b/server/src/test/java/org/elasticsearch/search/scroll/DuelScrollIT.java index 4005f1218a9..04349e846c7 100644 --- a/server/src/test/java/org/elasticsearch/search/scroll/DuelScrollIT.java +++ b/server/src/test/java/org/elasticsearch/search/scroll/DuelScrollIT.java @@ -52,7 +52,7 @@ public class DuelScrollIT extends ESIntegTestCase { .setSize(context.numDocs).get(); assertNoFailures(control); SearchHits sh = control.getHits(); - assertThat(sh.getTotalHits(), equalTo((long) context.numDocs)); + assertThat(sh.getTotalHits().value, equalTo((long) context.numDocs)); assertThat(sh.getHits().length, equalTo(context.numDocs)); SearchResponse searchScrollResponse = client().prepareSearch("index") @@ -62,7 +62,7 @@ public class DuelScrollIT extends ESIntegTestCase { .setScroll("10m").get(); assertNoFailures(searchScrollResponse); - assertThat(searchScrollResponse.getHits().getTotalHits(), equalTo((long) context.numDocs)); + assertThat(searchScrollResponse.getHits().getTotalHits().value, equalTo((long) context.numDocs)); assertThat(searchScrollResponse.getHits().getHits().length, equalTo(context.scrollRequestSize)); int counter = 0; @@ -75,7 +75,7 @@ public class DuelScrollIT extends ESIntegTestCase { while (true) { searchScrollResponse = client().prepareSearchScroll(scrollId).setScroll("10m").get(); assertNoFailures(searchScrollResponse); - assertThat(searchScrollResponse.getHits().getTotalHits(), equalTo((long) context.numDocs)); + assertThat(searchScrollResponse.getHits().getTotalHits().value, equalTo((long) context.numDocs)); if (searchScrollResponse.getHits().getHits().length == 0) { break; } @@ -236,7 +236,7 @@ public class DuelScrollIT extends ESIntegTestCase { try { while (true) { assertNoFailures(scroll); - assertEquals(control.getHits().getTotalHits(), scroll.getHits().getTotalHits()); + assertEquals(control.getHits().getTotalHits().value, scroll.getHits().getTotalHits().value); assertEquals(control.getHits().getMaxScore(), scroll.getHits().getMaxScore(), 0.01f); if (scroll.getHits().getHits().length == 0) { break; @@ -249,7 +249,7 @@ public class DuelScrollIT extends ESIntegTestCase { scrollDocs += scroll.getHits().getHits().length; scroll = client().prepareSearchScroll(scroll.getScrollId()).setScroll("10m").get(); } - assertEquals(control.getHits().getTotalHits(), scrollDocs); + assertEquals(control.getHits().getTotalHits().value, scrollDocs); } catch (AssertionError e) { logger.info("Control:\n{}", control); logger.info("Scroll size={}, from={}:\n{}", size, scrollDocs, scroll); diff --git a/server/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java b/server/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java index f2005905c1e..c6a6246a07e 100644 --- a/server/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java +++ b/server/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java @@ -95,7 +95,7 @@ public class SearchScrollIT extends ESIntegTestCase { try { long counter = 0; - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++)); @@ -105,7 +105,7 @@ public class SearchScrollIT extends ESIntegTestCase { .setScroll(TimeValue.timeValueMinutes(2)) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++)); @@ -115,7 +115,7 @@ public class SearchScrollIT extends ESIntegTestCase { .setScroll(TimeValue.timeValueMinutes(2)) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(30)); for (SearchHit hit : searchResponse.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++)); @@ -153,7 +153,7 @@ public class SearchScrollIT extends ESIntegTestCase { try { long counter = 0; - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); for (SearchHit hit : searchResponse.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++)); @@ -164,7 +164,7 @@ public class SearchScrollIT extends ESIntegTestCase { .setScroll(TimeValue.timeValueMinutes(2)) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); for (SearchHit hit : searchResponse.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++)); @@ -176,7 +176,7 @@ public class SearchScrollIT extends ESIntegTestCase { .setScroll(TimeValue.timeValueMinutes(2)) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); for (SearchHit hit : searchResponse.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++)); @@ -187,7 +187,7 @@ public class SearchScrollIT extends ESIntegTestCase { .setScroll(TimeValue.timeValueMinutes(2)) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(0)); for (SearchHit hit : searchResponse.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++)); @@ -209,11 +209,11 @@ public class SearchScrollIT extends ESIntegTestCase { client().admin().indices().prepareRefresh().execute().actionGet(); - assertThat(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(500L)); - assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits(), equalTo(500L)); - assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits(), equalTo(500L)); - assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); - assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); + assertThat(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(500L)); + assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits().value, equalTo(500L)); + assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits().value, equalTo(500L)); + assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); + assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); SearchResponse searchResponse = client().prepareSearch() .setQuery(queryStringQuery("user:kimchy")) @@ -232,11 +232,11 @@ public class SearchScrollIT extends ESIntegTestCase { } while (searchResponse.getHits().getHits().length > 0); client().admin().indices().prepareRefresh().execute().actionGet(); - assertThat(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(500L)); - assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); - assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits(), equalTo(0L)); - assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits(), equalTo(500L)); - assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits(), equalTo(500L)); + assertThat(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(500L)); + assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); + assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits().value, equalTo(0L)); + assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits().value, equalTo(500L)); + assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits().value, equalTo(500L)); } finally { clearScroll(searchResponse.getScrollId()); } @@ -273,13 +273,13 @@ public class SearchScrollIT extends ESIntegTestCase { long counter1 = 0; long counter2 = 0; - assertThat(searchResponse1.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse1.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse1.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse1.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter1++)); } - assertThat(searchResponse2.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse2.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse2.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse2.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter2++)); @@ -293,13 +293,13 @@ public class SearchScrollIT extends ESIntegTestCase { .setScroll(TimeValue.timeValueMinutes(2)) .execute().actionGet(); - assertThat(searchResponse1.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse1.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse1.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse1.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter1++)); } - assertThat(searchResponse2.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse2.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse2.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse2.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter2++)); @@ -379,13 +379,13 @@ public class SearchScrollIT extends ESIntegTestCase { long counter1 = 0; long counter2 = 0; - assertThat(searchResponse1.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse1.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse1.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse1.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter1++)); } - assertThat(searchResponse2.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse2.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse2.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse2.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter2++)); @@ -399,13 +399,13 @@ public class SearchScrollIT extends ESIntegTestCase { .setScroll(TimeValue.timeValueMinutes(2)) .execute().actionGet(); - assertThat(searchResponse1.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse1.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse1.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse1.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter1++)); } - assertThat(searchResponse2.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse2.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse2.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse2.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter2++)); @@ -515,7 +515,7 @@ public class SearchScrollIT extends ESIntegTestCase { .addSort("field", SortOrder.ASC) .execute().actionGet(); long counter = 0; - assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L)); assertThat(searchResponse.getHits().getHits().length, equalTo(35)); for (SearchHit hit : searchResponse.getHits()) { assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++)); @@ -585,7 +585,7 @@ public class SearchScrollIT extends ESIntegTestCase { .setScroll(TimeValue.timeValueMinutes(5)) .execute().actionGet(); assertNotNull(searchResponse.getScrollId()); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getHits().length, equalTo(1)); exc = expectThrows(Exception.class, diff --git a/server/src/test/java/org/elasticsearch/search/searchafter/SearchAfterIT.java b/server/src/test/java/org/elasticsearch/search/searchafter/SearchAfterIT.java index 76faac73415..84fae003244 100644 --- a/server/src/test/java/org/elasticsearch/search/searchafter/SearchAfterIT.java +++ b/server/src/test/java/org/elasticsearch/search/searchafter/SearchAfterIT.java @@ -164,7 +164,7 @@ public class SearchAfterIT extends ESIntegTestCase { .setQuery(matchAllQuery()) .searchAfter(new Object[]{0, null}) .get(); - assertThat(searchResponse.getHits().getTotalHits(), Matchers.equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, Matchers.equalTo(2L)); assertThat(searchResponse.getHits().getHits().length, Matchers.equalTo(1)); assertThat(searchResponse.getHits().getHits()[0].getSourceAsMap().get("field1"), Matchers.equalTo(100)); assertThat(searchResponse.getHits().getHits()[0].getSourceAsMap().get("field2"), Matchers.equalTo("toto")); diff --git a/server/src/test/java/org/elasticsearch/search/simple/SimpleSearchIT.java b/server/src/test/java/org/elasticsearch/search/simple/SimpleSearchIT.java index c5f7bf2bd53..20c71dd7a0b 100644 --- a/server/src/test/java/org/elasticsearch/search/simple/SimpleSearchIT.java +++ b/server/src/test/java/org/elasticsearch/search/simple/SimpleSearchIT.java @@ -275,8 +275,8 @@ public class SimpleSearchIT extends ESIntegTestCase { .addDocValueField("rank") .setTrackTotalHits(false) .addSort("rank", SortOrder.ASC) - .setSize(i).execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(-1L)); + .setSize(i).get(); + assertNull(searchResponse.getHits().getTotalHits()); for (int j = 0; j < i; j++) { assertThat(searchResponse.getHits().getAt(j).field("rank").getValue(), equalTo((long) j)); diff --git a/server/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java b/server/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java index d609f84e419..568c4c596b4 100644 --- a/server/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java +++ b/server/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java @@ -123,7 +123,7 @@ public class SearchSliceIT extends ESIntegTestCase { .setPreference("_shards:1,4") .setSize(0) .get(); - int numDocs = (int) sr.getHits().getTotalHits(); + int numDocs = (int) sr.getHits().getTotalHits().value; int max = randomIntBetween(2, numShards * 3); int fetchSize = randomIntBetween(10, 100); SearchRequestBuilder request = client().prepareSearch("test") @@ -140,7 +140,7 @@ public class SearchSliceIT extends ESIntegTestCase { .setRouting("foo", "bar") .setSize(0) .get(); - int numDocs = (int) sr.getHits().getTotalHits(); + int numDocs = (int) sr.getHits().getTotalHits().value; int max = randomIntBetween(2, numShards * 3); int fetchSize = randomIntBetween(10, 100); SearchRequestBuilder request = client().prepareSearch("test") @@ -161,7 +161,7 @@ public class SearchSliceIT extends ESIntegTestCase { .setQuery(matchAllQuery()) .setSize(0) .get(); - int numDocs = (int) sr.getHits().getTotalHits(); + int numDocs = (int) sr.getHits().getTotalHits().value; int max = randomIntBetween(2, numShards * 3); int fetchSize = randomIntBetween(10, 100); SearchRequestBuilder request = client().prepareSearch("alias1", "alias3") @@ -217,7 +217,7 @@ public class SearchSliceIT extends ESIntegTestCase { SliceBuilder sliceBuilder = new SliceBuilder(field, id, numSlice); SearchResponse searchResponse = request.slice(sliceBuilder).get(); totalResults += searchResponse.getHits().getHits().length; - int expectedSliceResults = (int) searchResponse.getHits().getTotalHits(); + int expectedSliceResults = (int) searchResponse.getHits().getTotalHits().value; int numSliceResults = searchResponse.getHits().getHits().length; String scrollId = searchResponse.getScrollId(); for (SearchHit hit : searchResponse.getHits().getHits()) { diff --git a/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java b/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java index 352e27e4f4f..ae3100e1231 100644 --- a/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java +++ b/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java @@ -288,7 +288,7 @@ public class FieldSortIT extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch("test").setQuery(matchAllQuery()).setSize(size) .addSort("dense_bytes", SortOrder.ASC).execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo((long) numDocs)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo((long) numDocs)); assertThat(searchResponse.getHits().getHits().length, equalTo(size)); Set> entrySet = denseBytes.entrySet(); Iterator> iterator = entrySet.iterator(); @@ -305,7 +305,7 @@ public class FieldSortIT extends ESIntegTestCase { .setPostFilter(QueryBuilders.existsQuery("sparse_bytes")).setSize(size).addSort("sparse_bytes", SortOrder.ASC).execute() .actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo((long) sparseBytes.size())); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo((long) sparseBytes.size())); assertThat(searchResponse.getHits().getHits().length, equalTo(size)); Set> entrySet = sparseBytes.entrySet(); Iterator> iterator = entrySet.iterator(); @@ -769,7 +769,7 @@ public class FieldSortIT extends ESIntegTestCase { .execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("3")); assertThat(searchResponse.getHits().getAt(2).getId(), equalTo("2")); @@ -781,7 +781,7 @@ public class FieldSortIT extends ESIntegTestCase { .execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("3")); assertThat(searchResponse.getHits().getAt(2).getId(), equalTo("2")); @@ -793,7 +793,7 @@ public class FieldSortIT extends ESIntegTestCase { .execute().actionGet(); assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("2")); assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("1")); assertThat(searchResponse.getHits().getAt(2).getId(), equalTo("3")); @@ -843,7 +843,7 @@ public class FieldSortIT extends ESIntegTestCase { .execute().actionGet(); assertThat(Arrays.toString(searchResponse.getShardFailures()), searchResponse.getFailedShards(), equalTo(0)); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("3")); assertThat(searchResponse.getHits().getAt(2).getId(), equalTo("2")); @@ -855,7 +855,7 @@ public class FieldSortIT extends ESIntegTestCase { .execute().actionGet(); assertThat(Arrays.toString(searchResponse.getShardFailures()), searchResponse.getFailedShards(), equalTo(0)); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("3")); assertThat(searchResponse.getHits().getAt(2).getId(), equalTo("2")); @@ -867,7 +867,7 @@ public class FieldSortIT extends ESIntegTestCase { .execute().actionGet(); assertThat(Arrays.toString(searchResponse.getShardFailures()), searchResponse.getFailedShards(), equalTo(0)); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("2")); assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("1")); assertThat(searchResponse.getHits().getAt(2).getId(), equalTo("3")); @@ -879,7 +879,7 @@ public class FieldSortIT extends ESIntegTestCase { .execute().actionGet(); assertThat(Arrays.toString(searchResponse.getShardFailures()), searchResponse.getFailedShards(), equalTo(0)); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("2")); assertThat(searchResponse.getHits().getAt(2).getId(), equalTo("3")); @@ -963,7 +963,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("long_values", SortOrder.ASC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(3))); @@ -981,7 +981,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("long_values", SortOrder.DESC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(2))); @@ -999,7 +999,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort(SortBuilders.fieldSort("long_values").order(SortOrder.DESC).sortMode(SortMode.SUM)) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(2))); @@ -1017,7 +1017,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort(SortBuilders.fieldSort("long_values").order(SortOrder.DESC).sortMode(SortMode.AVG)) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(2))); @@ -1035,7 +1035,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort(SortBuilders.fieldSort("long_values").order(SortOrder.DESC).sortMode(SortMode.MEDIAN)) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(2))); @@ -1053,7 +1053,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("int_values", SortOrder.ASC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(3))); @@ -1071,7 +1071,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("int_values", SortOrder.DESC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(2))); @@ -1089,7 +1089,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("short_values", SortOrder.ASC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(3))); @@ -1107,7 +1107,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("short_values", SortOrder.DESC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(2))); @@ -1125,7 +1125,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("byte_values", SortOrder.ASC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(3))); @@ -1143,7 +1143,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("byte_values", SortOrder.DESC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(2))); @@ -1161,7 +1161,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("float_values", SortOrder.ASC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(3))); @@ -1179,7 +1179,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("float_values", SortOrder.DESC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(2))); @@ -1197,7 +1197,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("double_values", SortOrder.ASC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(3))); @@ -1215,7 +1215,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("double_values", SortOrder.DESC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(2))); @@ -1233,7 +1233,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("string_values", SortOrder.ASC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(3))); @@ -1251,7 +1251,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort("string_values", SortOrder.DESC) .execute().actionGet(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getHits().length, equalTo(3)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo(Integer.toString(2))); @@ -1505,7 +1505,7 @@ public class FieldSortIT extends ESIntegTestCase { SearchResponse singleShardResponse = client().prepareSearch("test2").setFrom(from).setSize(size).addSort(sortField, order).get(); assertNoFailures(singleShardResponse); - assertThat(multiShardResponse.getHits().getTotalHits(), equalTo(singleShardResponse.getHits().getTotalHits())); + assertThat(multiShardResponse.getHits().getTotalHits().value, equalTo(singleShardResponse.getHits().getTotalHits().value)); assertThat(multiShardResponse.getHits().getHits().length, equalTo(singleShardResponse.getHits().getHits().length)); for (int i = 0; i < multiShardResponse.getHits().getHits().length; i++) { assertThat(multiShardResponse.getHits().getAt(i).getSortValues()[0], @@ -1528,7 +1528,7 @@ public class FieldSortIT extends ESIntegTestCase { .addSort(SortBuilders.fieldSort("ip")) .get(); assertSearchResponse(response); - assertEquals(2, response.getHits().getTotalHits()); + assertEquals(2, response.getHits().getTotalHits().value); assertArrayEquals(new String[] {"192.168.1.7"}, response.getHits().getAt(0).getSortValues()); assertArrayEquals(new String[] {"2001:db8::ff00:42:8329"}, @@ -1539,7 +1539,7 @@ public class FieldSortIT extends ESIntegTestCase { .searchAfter(new Object[] {"192.168.1.7"}) .get(); assertSearchResponse(response); - assertEquals(2, response.getHits().getTotalHits()); + assertEquals(2, response.getHits().getTotalHits().value); assertEquals(1, response.getHits().getHits().length); assertArrayEquals(new String[] {"2001:db8::ff00:42:8329"}, response.getHits().getAt(0).getSortValues()); diff --git a/server/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java b/server/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java index 82b0608046a..26fa4c870c9 100644 --- a/server/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java +++ b/server/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java @@ -392,7 +392,7 @@ public class SimpleSortIT extends ESIntegTestCase { assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getAt(0).field("id").getValue(), equalTo("1")); assertThat(searchResponse.getHits().getAt(1).field("id").getValue(), equalTo("3")); assertThat(searchResponse.getHits().getAt(2).field("id").getValue(), equalTo("2")); @@ -405,7 +405,7 @@ public class SimpleSortIT extends ESIntegTestCase { assertNoFailures(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getAt(0).field("id").getValue(), equalTo("1")); assertThat(searchResponse.getHits().getAt(1).field("id").getValue(), equalTo("3")); assertThat(searchResponse.getHits().getAt(2).field("id").getValue(), equalTo("2")); @@ -424,7 +424,7 @@ public class SimpleSortIT extends ESIntegTestCase { } assertThat(searchResponse.getFailedShards(), equalTo(0)); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(3L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(3L)); assertThat(searchResponse.getHits().getAt(0).field("id").getValue(), equalTo("3")); assertThat(searchResponse.getHits().getAt(1).field("id").getValue(), equalTo("1")); assertThat(searchResponse.getHits().getAt(2).field("id").getValue(), equalTo("2")); @@ -444,7 +444,7 @@ public class SimpleSortIT extends ESIntegTestCase { } assertThat(searchResponse.getFailedShards(), equalTo(0)); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).field("id").getValue(), equalTo("2")); } diff --git a/server/src/test/java/org/elasticsearch/search/source/MetadataFetchingIT.java b/server/src/test/java/org/elasticsearch/search/source/MetadataFetchingIT.java index c64ae840923..d317b0ffa5a 100644 --- a/server/src/test/java/org/elasticsearch/search/source/MetadataFetchingIT.java +++ b/server/src/test/java/org/elasticsearch/search/source/MetadataFetchingIT.java @@ -80,13 +80,13 @@ public class MetadataFetchingIT extends ESIntegTestCase { .setFetchSourceContext(new FetchSourceContext(false))) ) .get(); - assertThat(response.getHits().totalHits, equalTo(1L)); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); assertThat(response.getHits().getAt(0).getId(), nullValue()); assertThat(response.getHits().getAt(0).getType(), equalTo("_doc")); assertThat(response.getHits().getAt(0).getSourceAsString(), nullValue()); assertThat(response.getHits().getAt(0).getInnerHits().size(), equalTo(1)); SearchHits hits = response.getHits().getAt(0).getInnerHits().get("nested"); - assertThat(hits.totalHits, equalTo(1L)); + assertThat(hits.getTotalHits().value, equalTo(1L)); assertThat(hits.getAt(0).getId(), nullValue()); assertThat(hits.getAt(0).getType(), equalTo("_doc")); assertThat(hits.getAt(0).getSourceAsString(), nullValue()); diff --git a/server/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java b/server/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java index 72f8c2d8835..76c11e4f4a6 100644 --- a/server/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java +++ b/server/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java @@ -1041,7 +1041,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase { refresh(); assertSuggestions("b"); - assertThat(2L, equalTo(client().prepareSearch(INDEX).setSize(0).get().getHits().getTotalHits())); + assertThat(2L, equalTo(client().prepareSearch(INDEX).setSize(0).get().getHits().getTotalHits().value)); for (IndexShardSegments seg : client().admin().indices().prepareSegments().get().getIndices().get(INDEX)) { ShardSegments[] shards = seg.getShards(); for (ShardSegments shardSegments : shards) { diff --git a/server/src/test/java/org/elasticsearch/similarity/SimilarityIT.java b/server/src/test/java/org/elasticsearch/similarity/SimilarityIT.java index a6c9388cb65..fe21f53fd6f 100644 --- a/server/src/test/java/org/elasticsearch/similarity/SimilarityIT.java +++ b/server/src/test/java/org/elasticsearch/similarity/SimilarityIT.java @@ -66,12 +66,12 @@ public class SimilarityIT extends ESIntegTestCase { SearchResponse bm25SearchResponse = client().prepareSearch().setQuery(matchQuery("field1", "quick brown fox")) .execute().actionGet(); - assertThat(bm25SearchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(bm25SearchResponse.getHits().getTotalHits().value, equalTo(1L)); float bm25Score = bm25SearchResponse.getHits().getHits()[0].getScore(); SearchResponse booleanSearchResponse = client().prepareSearch().setQuery(matchQuery("field2", "quick brown fox")) .execute().actionGet(); - assertThat(booleanSearchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(booleanSearchResponse.getHits().getTotalHits().value, equalTo(1L)); float defaultScore = booleanSearchResponse.getHits().getHits()[0].getScore(); assertThat(bm25Score, not(equalTo(defaultScore))); diff --git a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index e408a1c7767..ae87a760a65 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -375,7 +375,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> create repository"); logger.info("--> creating repository"); @@ -423,7 +423,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> creating repository"); Path repo = randomRepoPath(); @@ -495,7 +495,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest index("test-idx-some", "doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client().prepareSearch("test-idx-some").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client().prepareSearch("test-idx-some").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> shutdown one of the nodes"); internalCluster().stopRandomDataNode(); @@ -518,7 +518,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest index("test-idx-closed", "doc", Integer.toString(i), "foo", "bar" + i); } refresh("test-idx-closed", "test-idx-all"); // don't refresh test-idx-some it will take 30 sec until it times out... - assertThat(client().prepareSearch("test-idx-all").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client().prepareSearch("test-idx-all").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); assertAcked(client().admin().indices().prepareClose("test-idx-closed")); logger.info("--> create an index that will have no allocated shards"); @@ -609,7 +609,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), equalTo(6)); assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0)); - assertThat(client().prepareSearch("test-idx-all").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client().prepareSearch("test-idx-all").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> restore snapshot for the partial index"); cluster().wipeIndices("test-idx-some"); @@ -620,7 +620,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), allOf(greaterThan(0), lessThan(6))); assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), greaterThan(0)); - assertThat(client().prepareSearch("test-idx-some").setSize(0).get().getHits().getTotalHits(), allOf(greaterThan(0L), + assertThat(client().prepareSearch("test-idx-some").setSize(0).get().getHits().getTotalHits().value, allOf(greaterThan(0L), lessThan(100L))); logger.info("--> restore snapshot for the index that didn't have any shards snapshotted successfully"); @@ -632,7 +632,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), equalTo(0)); assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(6)); - assertThat(client().prepareSearch("test-idx-some").setSize(0).get().getHits().getTotalHits(), allOf(greaterThan(0L), + assertThat(client().prepareSearch("test-idx-some").setSize(0).get().getHits().getTotalHits().value, allOf(greaterThan(0L), lessThan(100L))); } @@ -661,7 +661,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client().prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client().prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> start snapshot"); assertThat(client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1").setIndices("test-idx") @@ -689,7 +689,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest equalTo(6)); ensureGreen("test-idx"); - assertThat(client().prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client().prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); IntSet reusedShards = new IntHashSet(); List recoveryStates = client().admin().indices().prepareRecoveries("test-idx").get() @@ -1161,6 +1161,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest assertThat(anotherStats.getTotalSize(), is(snapshot1FileSize)); } + @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/36283") public void testDataNodeRestartWithBusyMasterDuringSnapshot() throws Exception { logger.info("--> starting a master node and two data nodes"); internalCluster().startMasterOnlyNode(); diff --git a/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index e953cfbe7fa..a65b1c4a77a 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -723,7 +723,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot without global state but with indices"); createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-no-global-state-with-index") @@ -762,7 +762,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas assertIndexTemplateMissing(getIndexTemplatesResponse, "test-template"); assertFalse(client().admin().cluster().prepareGetPipeline("barbaz").get().isFound()); assertNull(client().admin().cluster().prepareGetStoredScript("foobar").get().getSource()); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); } @@ -786,7 +786,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot"); try { @@ -837,7 +837,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") @@ -904,7 +904,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") @@ -965,7 +965,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster() @@ -1073,7 +1073,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index(indexName, "_doc", Integer.toString(i), "foo", "bar" + i); } flushAndRefresh(indexName); - assertThat(client().prepareSearch(indexName).setSize(0).get().getHits().getTotalHits(), equalTo((long) nbDocs)); + assertThat(client().prepareSearch(indexName).setSize(0).get().getHits().getTotalHits().value, equalTo((long) nbDocs)); // create a snapshot final NumShards numShards = getNumShards(indexName); @@ -1147,7 +1147,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas ensureGreen(indexName); refresh(indexName); - assertThat(client().prepareSearch(indexName).setSize(0).get().getHits().getTotalHits(), equalTo((long) nbDocs)); + assertThat(client().prepareSearch(indexName).setSize(0).get().getHits().getTotalHits().value, equalTo((long) nbDocs)); } public void testDeletionOfFailingToRecoverIndexShouldStopRestore() throws Exception { @@ -1165,7 +1165,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") @@ -1213,7 +1213,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0)); SearchResponse countResponse = client.prepareSearch("test-idx").setSize(0).get(); - assertThat(countResponse.getHits().getTotalHits(), equalTo(100L)); + assertThat(countResponse.getHits().getTotalHits().value, equalTo(100L)); } @@ -1269,7 +1269,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas // Store number of files after each snapshot numberOfFiles[i] = numberOfFiles(repo); } - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(10L * numberOfSnapshots)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(10L * numberOfSnapshots)); int numberOfFilesBeforeDeletion = numberOfFiles(repo); logger.info("--> delete all snapshots except the first one and last one"); @@ -1290,7 +1290,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas .setWaitForCompletion(true).execute().actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(10L * numberOfSnapshots)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(10L * numberOfSnapshots)); logger.info("--> delete the last snapshot"); client.admin().cluster().prepareDeleteSnapshot("test-repo", lastSnapshot).get(); @@ -1602,8 +1602,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx-2", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); - assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); + assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") @@ -1617,8 +1617,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas .setRenamePattern("(.+)").setRenameReplacement("$1-copy").setWaitForCompletion(true).execute().actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); - assertThat(client.prepareSearch("test-idx-1-copy").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); - assertThat(client.prepareSearch("test-idx-2-copy").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx-1-copy").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); + assertThat(client.prepareSearch("test-idx-2-copy").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> close just restored indices"); client.admin().indices().prepareClose("test-idx-1-copy", "test-idx-2-copy").get(); @@ -1628,8 +1628,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas .setRenamePattern("(.+)").setRenameReplacement("$1-copy").setWaitForCompletion(true).execute().actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); - assertThat(client.prepareSearch("test-idx-1-copy").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); - assertThat(client.prepareSearch("test-idx-2-copy").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx-1-copy").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); + assertThat(client.prepareSearch("test-idx-2-copy").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> close indices"); @@ -1725,7 +1725,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); // Pick one node and block it String blockedNode = blockNodeWithIndex("test-repo", "test-idx"); @@ -1766,7 +1766,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas .setWaitForCompletion(true).execute().actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); } public void testDeleteRepositoryWhileSnapshotting() throws Exception { @@ -1790,7 +1790,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); // Pick one node and block it String blockedNode = blockNodeWithIndex("test-repo", "test-idx"); @@ -1851,7 +1851,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas .setWaitForCompletion(true).execute().actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); } @TestLogging("_root:DEBUG") // this fails every now and then: https://github.com/elastic/elasticsearch/issues/18121 but without @@ -1900,7 +1900,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas .setWaitForCompletion(true).setIndices("test-idx").execute().actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> list available shapshots"); GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("readonly-repo").get(); @@ -1941,7 +1941,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") @@ -1957,7 +1957,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap") .setWaitForCompletion(true).execute().actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); long snapshotPause = 0L; long restorePause = 0L; @@ -2000,7 +2000,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); // Pick one node and block it String blockedNode = blockNodeWithIndex("test-repo", "test-idx"); @@ -2116,7 +2116,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> start relocations"); allowNodes("test-idx", internalCluster().numDataNodes()); @@ -2457,9 +2457,9 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx-3", "_doc", Integer.toString(i), "foo", "baz" + i); } refresh(); - assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); - assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); - assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); + assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); + assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot allow partial {}", allowPartial); ActionFuture future = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") @@ -2545,8 +2545,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx-2", "_doc", Integer.toString(i), "foo", "baz" + i); } refresh(); - assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); - assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); + assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> snapshot"); assertThat(client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") @@ -2607,7 +2607,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index(indexName, "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch(indexName).setSize(0).get().getHits().getTotalHits(), equalTo(100L)); + assertThat(client.prepareSearch(indexName).setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); logger.info("--> take snapshots"); final String snapshotName = "test-snap"; @@ -3253,7 +3253,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } refresh(); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo((long) numDocs)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo((long) numDocs)); logger.info("--> snapshot with potential I/O failures"); try { @@ -3527,7 +3527,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i), "foo", "bar" + i); } flushAndRefresh("test-idx"); - assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo((long) nbDocs)); + assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo((long) nbDocs)); // Create a snapshot client.admin().cluster().prepareCreateSnapshot("repository", "snap").execute(); diff --git a/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESBlobStoreRepositoryIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESBlobStoreRepositoryIntegTestCase.java index cef44ed17fd..2b8fba34c2f 100644 --- a/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESBlobStoreRepositoryIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESBlobStoreRepositoryIntegTestCase.java @@ -113,7 +113,7 @@ public abstract class ESBlobStoreRepositoryIntegTestCase extends ESIntegTestCase logger.info("--> add random documents to {}", index); addRandomDocuments(index, randomIntBetween(10, 1000)); } else { - int docCount = (int) client().prepareSearch(index).setSize(0).get().getHits().getTotalHits(); + int docCount = (int) client().prepareSearch(index).setSize(0).get().getHits().getTotalHits().value; int deleteCount = randomIntBetween(1, docCount); logger.info("--> delete {} random documents from {}", deleteCount, index); for (int i = 0; i < deleteCount; i++) { @@ -177,7 +177,7 @@ public abstract class ESBlobStoreRepositoryIntegTestCase extends ESIntegTestCase addRandomDocuments(indexName, docCount); } // Check number of documents in this iteration - docCounts[i] = (int) client().prepareSearch(indexName).setSize(0).get().getHits().getTotalHits(); + docCounts[i] = (int) client().prepareSearch(indexName).setSize(0).get().getHits().getTotalHits().value; logger.info("--> create snapshot {}:{} with {} documents", repoName, snapshotName + "-" + i, docCounts[i]); assertSuccessfulSnapshot(client().admin().cluster().prepareCreateSnapshot(repoName, snapshotName + "-" + i) .setWaitForCompletion(true).setIndices(indexName)); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index 20a55c49afc..1dc3c375ad8 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -25,6 +25,7 @@ import com.carrotsearch.randomizedtesting.generators.RandomNumbers; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import org.apache.http.HttpHost; import org.apache.lucene.search.Sort; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; @@ -870,9 +871,12 @@ public abstract class ESIntegTestCase extends ESTestCase { /** Ensures the result counts are as expected, and logs the results if different */ public void assertResultsAndLogOnFailure(long expectedResults, SearchResponse searchResponse) { - if (searchResponse.getHits().getTotalHits() != expectedResults) { + final TotalHits totalHits = searchResponse.getHits().getTotalHits(); + if (totalHits.value != expectedResults || totalHits.relation != TotalHits.Relation.EQUAL_TO) { StringBuilder sb = new StringBuilder("search result contains ["); - sb.append(searchResponse.getHits().getTotalHits()).append("] results. expected [").append(expectedResults).append("]"); + String value = Long.toString(totalHits.value) + + (totalHits.relation == TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO ? "+" : ""); + sb.append(value).append("] results. expected [").append(expectedResults).append("]"); String failMsg = sb.toString(); for (SearchHit hit : searchResponse.getHits().getHits()) { sb.append("\n-> _index: [").append(hit.getIndex()).append("] type [").append(hit.getType()) @@ -1043,7 +1047,14 @@ public abstract class ESIntegTestCase extends ESTestCase { } if (lastKnownCount.get() >= numDocs) { try { - long count = client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get().getHits().getTotalHits(); + + long count = client().prepareSearch() + .setTrackTotalHits(true) + .setSize(0) + .setQuery(matchAllQuery()) + .get() + .getHits().getTotalHits().value; + if (count == lastKnownCount.get()) { // no progress - try to refresh for the next time client().admin().indices().prepareRefresh().get(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index 1a7e1c16f7b..6005e7e6163 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -21,6 +21,7 @@ package org.elasticsearch.test.hamcrest; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.DisjunctionMaxQuery; import org.apache.lucene.search.Query; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ActionFuture; @@ -237,8 +238,9 @@ public class ElasticsearchAssertions { } public static void assertHitCount(SearchResponse countResponse, long expectedHitCount) { - if (countResponse.getHits().getTotalHits() != expectedHitCount) { - fail("Count is " + countResponse.getHits().getTotalHits() + " but " + expectedHitCount + final TotalHits totalHits = countResponse.getHits().getTotalHits(); + if (totalHits.relation != TotalHits.Relation.EQUAL_TO || totalHits.value != expectedHitCount) { + fail("Count is " + totalHits + " but " + expectedHitCount + " was expected. " + formatShardStatus(countResponse)); } } @@ -272,7 +274,7 @@ public class ElasticsearchAssertions { public static void assertSearchHit(SearchResponse searchResponse, int number, Matcher matcher) { assertThat(number, greaterThan(0)); assertThat("SearchHit number must be greater than 0", number, greaterThan(0)); - assertThat(searchResponse.getHits().getTotalHits(), greaterThanOrEqualTo((long) number)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThanOrEqualTo((long) number)); assertThat(searchResponse.getHits().getAt(number - 1), matcher); } diff --git a/x-pack/docs/en/watcher/actions.asciidoc b/x-pack/docs/en/watcher/actions.asciidoc index de2516b0589..08b93c13b53 100644 --- a/x-pack/docs/en/watcher/actions.asciidoc +++ b/x-pack/docs/en/watcher/actions.asciidoc @@ -68,14 +68,14 @@ PUT _xpack/watcher/watch/error_logs_alert } }, "condition" : { - "compare" : { "ctx.payload.hits.total" : { "gt" : 5 }} + "compare" : { "ctx.payload.hits.total.value" : { "gt" : 5 }} }, "actions" : { "email_administrator" : { "throttle_period": "15m", <1> "email" : { <2> "to" : "sys.admino@host.domain", - "subject" : "Encountered {{ctx.payload.hits.total}} errors", + "subject" : "Encountered {{ctx.payload.hits.total.value}} errors", "body" : "Too many error in the system, see attached data", "attachments" : { "attached_data" : { @@ -118,14 +118,14 @@ PUT _xpack/watcher/watch/log_event_watch } }, "condition" : { - "compare" : { "ctx.payload.hits.total" : { "gt" : 5 }} + "compare" : { "ctx.payload.hits.total.value" : { "gt" : 5 }} }, "throttle_period" : "15m", <1> "actions" : { "email_administrator" : { "email" : { "to" : "sys.admino@host.domain", - "subject" : "Encountered {{ctx.payload.hits.total}} errors", + "subject" : "Encountered {{ctx.payload.hits.total.value}} errors", "body" : "Too many error in the system, see attached data", "attachments" : { "attached_data" : { @@ -143,7 +143,7 @@ PUT _xpack/watcher/watch/log_event_watch "host" : "pager.service.domain", "port" : 1234, "path" : "/{{watch_id}}", - "body" : "Encountered {{ctx.payload.hits.total}} errors" + "body" : "Encountered {{ctx.payload.hits.total.value}} errors" } } } @@ -221,13 +221,13 @@ PUT _xpack/watcher/watch/log_event_watch } }, "condition" : { - "compare" : { "ctx.payload.hits.total" : { "gt" : 0 } } + "compare" : { "ctx.payload.hits.total.value" : { "gt" : 0 } } }, "actions" : { "email_administrator" : { "email" : { "to" : "sys.admino@host.domain", - "subject" : "Encountered {{ctx.payload.hits.total}} errors", + "subject" : "Encountered {{ctx.payload.hits.total.value}} errors", "body" : "Too many error in the system, see attached data", "attachments" : { "attached_data" : { @@ -241,14 +241,14 @@ PUT _xpack/watcher/watch/log_event_watch }, "notify_pager" : { "condition": { <1> - "compare" : { "ctx.payload.hits.total" : { "gt" : 5 } } + "compare" : { "ctx.payload.hits.total.value" : { "gt" : 5 } } }, "webhook" : { "method" : "POST", "host" : "pager.service.domain", "port" : 1234, "path" : "/{{watch_id}}", - "body" : "Encountered {{ctx.payload.hits.total}} errors" + "body" : "Encountered {{ctx.payload.hits.total.value}} errors" } } } diff --git a/x-pack/docs/en/watcher/actions/email.asciidoc b/x-pack/docs/en/watcher/actions/email.asciidoc index dd2bdc964af..96839b972be 100644 --- a/x-pack/docs/en/watcher/actions/email.asciidoc +++ b/x-pack/docs/en/watcher/actions/email.asciidoc @@ -30,7 +30,7 @@ the watch payload in the email body: "email" : { <2> "to" : "username@example.org", <3> "subject" : "Watcher Notification", <4> - "body" : "{{ctx.payload.hits.total}} error logs found" <5> + "body" : "{{ctx.payload.hits.total.value}} error logs found" <5> } } } diff --git a/x-pack/docs/en/watcher/actions/hipchat.asciidoc b/x-pack/docs/en/watcher/actions/hipchat.asciidoc index da5b7558c4a..27cd177975a 100644 --- a/x-pack/docs/en/watcher/actions/hipchat.asciidoc +++ b/x-pack/docs/en/watcher/actions/hipchat.asciidoc @@ -28,7 +28,7 @@ attribute is the message itself: "hipchat" : { "account" : "integration-account", <1> "message" : { - "body" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes (facepalm)", <2> + "body" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes (facepalm)", <2> "format" : "text", "color" : "red", "notify" : true @@ -58,7 +58,7 @@ For example, the following action is configured to send messages to the "message" : { "room" : [ "mission-control", "devops" ], "user" : "website-admin@example.com", - "body" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes (facepalm)", + "body" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes (facepalm)", "format" : "text", "color" : "red", "notify" : true @@ -85,7 +85,7 @@ For example, the following action is configured to send messages to the "message" : { "from" : "Watcher", "room" : [ "server-status", "infra-team" ], - "body" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes (facepalm)", + "body" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes (facepalm)", "format" : "text", "color" : "red", "notify" : true diff --git a/x-pack/docs/en/watcher/actions/jira.asciidoc b/x-pack/docs/en/watcher/actions/jira.asciidoc index dc1afdc93b3..fb845cbbfd5 100644 --- a/x-pack/docs/en/watcher/actions/jira.asciidoc +++ b/x-pack/docs/en/watcher/actions/jira.asciidoc @@ -28,8 +28,8 @@ The following snippet shows a simple jira action definition: "issuetype" : { "name": "Bug" <3> }, - "summary" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes", <4> - "description" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes (facepalm)", <5> + "summary" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes", <4> + "description" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes (facepalm)", <5> "labels" : ["auto"], <6> "priority" : { "name" : "High" <7> diff --git a/x-pack/docs/en/watcher/actions/slack.asciidoc b/x-pack/docs/en/watcher/actions/slack.asciidoc index 0d0f77a4a30..ef8b907677b 100644 --- a/x-pack/docs/en/watcher/actions/slack.asciidoc +++ b/x-pack/docs/en/watcher/actions/slack.asciidoc @@ -23,7 +23,7 @@ The following snippet shows a simple slack action definition: "slack" : { "message" : { "to" : [ "#admins", "@chief-admin" ], <1> - "text" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes (facepalm)" <2> + "text" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes (facepalm)" <2> } } } @@ -58,7 +58,7 @@ The following snippet shows a standard message attachment: "attachments" : [ { "title" : "Errors Found", - "text" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes (facepalm)", + "text" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes (facepalm)", "color" : "danger" } ] diff --git a/x-pack/docs/en/watcher/actions/webhook.asciidoc b/x-pack/docs/en/watcher/actions/webhook.asciidoc index aabfb17f3b6..315e2639085 100644 --- a/x-pack/docs/en/watcher/actions/webhook.asciidoc +++ b/x-pack/docs/en/watcher/actions/webhook.asciidoc @@ -25,7 +25,7 @@ The following snippet shows a simple webhook action definition: "host" : "mylisteningserver", <5> "port" : 9200, <6> "path": ":/{{ctx.watch_id}", <7> - "body" : "{{ctx.watch_id}}:{{ctx.payload.hits.total}}" <8> + "body" : "{{ctx.watch_id}}:{{ctx.payload.hits.total.value}}" <8> } } } @@ -50,7 +50,7 @@ For example, the following `webhook` action creates a new issue in GitHub: "actions" : { "create_github_issue" : { "transform": { - "script": "return ['title':'Found errors in \\'contact.html\\'', 'body' : 'Found ' + ctx.payload.hits.total + ' errors in the last 5 minutes', 'assignee' : 'web-admin', 'labels' : ['bug','sev2']]" + "script": "return ['title':'Found errors in \\'contact.html\\'', 'body' : 'Found ' + ctx.payload.hits.total.value + ' errors in the last 5 minutes', 'assignee' : 'web-admin', 'labels' : ['bug','sev2']]" }, "webhook" : { "method" : "POST", @@ -126,7 +126,7 @@ the values serve as the header values: "headers" : { "Content-Type" : "application/yaml" <1> }, - "body" : "count: {{ctx.payload.hits.total}}" + "body" : "count: {{ctx.payload.hits.total.value}}" } } } diff --git a/x-pack/docs/en/watcher/condition/compare.asciidoc b/x-pack/docs/en/watcher/condition/compare.asciidoc index d58638e6fe4..eeb6ae86877 100644 --- a/x-pack/docs/en/watcher/condition/compare.asciidoc +++ b/x-pack/docs/en/watcher/condition/compare.asciidoc @@ -43,7 +43,7 @@ search result>> is greater than or equal to 5: { "condition" : { "compare" : { - "ctx.payload.hits.total" : { <1> + "ctx.payload.hits.total.value" : { <1> "gte" : 5 <2> } } diff --git a/x-pack/docs/en/watcher/customizing-watches.asciidoc b/x-pack/docs/en/watcher/customizing-watches.asciidoc index efef40e646b..ea44b8aa231 100644 --- a/x-pack/docs/en/watcher/customizing-watches.asciidoc +++ b/x-pack/docs/en/watcher/customizing-watches.asciidoc @@ -145,7 +145,7 @@ returned any hits: [source,js] -------------------------------------------------- "condition" : { - "compare" : { "ctx.payload.hits.total" : { "gt" : 0 }} + "compare" : { "ctx.payload.hits.total.value" : { "gt" : 0 }} }, -------------------------------------------------- // NOTCONSOLE @@ -221,7 +221,7 @@ attaches the payload data to the message: "email" : { <2> "to" : "email@example.org", "subject" : "Watcher Notification", - "body" : "{{ctx.payload.hits.total}} error logs found", + "body" : "{{ctx.payload.hits.total.value}} error logs found", "attachments" : { "data_attachment" : { "data" : { @@ -250,7 +250,7 @@ creates a new issue in GitHub "url" : "https://api.github.com/repos///issues", <1> "body" : "{ \"title\": \"Found errors in 'contact.html'\", - \"body\": \"Found {{ctx.payload.hits.total}} errors in this page in the last 5 minutes\", + \"body\": \"Found {{ctx.payload.hits.total.value}} errors in this page in the last 5 minutes\", \"assignee\": \"web-admin\", \"labels\": [ \"bug\", \"sev2\" ] }", diff --git a/x-pack/docs/en/watcher/example-watches/example-watch-meetupdata.asciidoc b/x-pack/docs/en/watcher/example-watches/example-watch-meetupdata.asciidoc index 72eac229ece..e2757847a92 100644 --- a/x-pack/docs/en/watcher/example-watches/example-watch-meetupdata.asciidoc +++ b/x-pack/docs/en/watcher/example-watches/example-watch-meetupdata.asciidoc @@ -158,7 +158,7 @@ To set up the watch: -- [source,js] -------------------------------------------------- -"compare" : { "ctx.payload.hits.total" : { "gt" : 0 }} +"compare" : { "ctx.payload.hits.total.value" : { "gt" : 0 }} -------------------------------------------------- // NOTCONSOLE -- @@ -268,7 +268,7 @@ PUT _xpack/watcher/watch/meetup }, "condition": { "compare": { - "ctx.payload.hits.total": { + "ctx.payload.hits.total.value": { "gt": 0 } } diff --git a/x-pack/docs/en/watcher/example-watches/watching-time-series-data.asciidoc b/x-pack/docs/en/watcher/example-watches/watching-time-series-data.asciidoc index 5daeccce76f..f65cc9d3c77 100644 --- a/x-pack/docs/en/watcher/example-watches/watching-time-series-data.asciidoc +++ b/x-pack/docs/en/watcher/example-watches/watching-time-series-data.asciidoc @@ -106,7 +106,7 @@ You define the condition with the following script: + [source,text] -------------------------------------------------- -return ctx.payload.hits.total > threshold +return ctx.payload.hits.total.value > threshold -------------------------------------------------- + If you store the script in a file at `$ES_HOME/config/scripts/threshold_hits.painless`, @@ -204,7 +204,7 @@ PUT _xpack/watcher/watch/rss_watch } -------------------------------------------------- // CONSOLE -// TEST[s/"id" : "threshold_hits"/"source": "return ctx.payload.hits.total > params.threshold"/] +// TEST[s/"id" : "threshold_hits"/"source": "return ctx.payload.hits.total.value > params.threshold"/] <1> Replace `username@example.org` with your email address to receive notifications. diff --git a/x-pack/docs/en/watcher/getting-started.asciidoc b/x-pack/docs/en/watcher/getting-started.asciidoc index 41eb654bab3..eed7f5e2fed 100644 --- a/x-pack/docs/en/watcher/getting-started.asciidoc +++ b/x-pack/docs/en/watcher/getting-started.asciidoc @@ -102,7 +102,7 @@ PUT _xpack/watcher/watch/log_error_watch } }, "condition" : { - "compare" : { "ctx.payload.hits.total" : { "gt" : 0 }} <1> + "compare" : { "ctx.payload.hits.total.value" : { "gt" : 0 }} <1> } } -------------------------------------------------- @@ -181,12 +181,12 @@ PUT _xpack/watcher/watch/log_error_watch } }, "condition" : { - "compare" : { "ctx.payload.hits.total" : { "gt" : 0 }} + "compare" : { "ctx.payload.hits.total.value" : { "gt" : 0 }} }, "actions" : { "log_error" : { "logging" : { - "text" : "Found {{ctx.payload.hits.total}} errors in the logs" + "text" : "Found {{ctx.payload.hits.total.value}} errors in the logs" } } } diff --git a/x-pack/docs/en/watcher/how-watcher-works.asciidoc b/x-pack/docs/en/watcher/how-watcher-works.asciidoc index 2bd19c1a41e..55829f8d507 100644 --- a/x-pack/docs/en/watcher/how-watcher-works.asciidoc +++ b/x-pack/docs/en/watcher/how-watcher-works.asciidoc @@ -70,7 +70,7 @@ PUT _xpack/watcher/watch/log_errors } }, "condition" : { <4> - "compare" : { "ctx.payload.hits.total" : { "gt" : 5 }} + "compare" : { "ctx.payload.hits.total.value" : { "gt" : 5 }} }, "transform" : { <5> "search" : { @@ -89,13 +89,13 @@ PUT _xpack/watcher/watch/log_errors "host" : "mylisteninghost", "port" : 9200, "path" : "/{{watch_id}}", - "body" : "Encountered {{ctx.payload.hits.total}} errors" + "body" : "Encountered {{ctx.payload.hits.total.value}} errors" } }, "email_administrator" : { "email" : { "to" : "sys.admino@host.domain", - "subject" : "Encountered {{ctx.payload.hits.total}} errors", + "subject" : "Encountered {{ctx.payload.hits.total.value}} errors", "body" : "Too many error in the system, see attached data", "attachments" : { "attached_data" : { diff --git a/x-pack/docs/en/watcher/input/search.asciidoc b/x-pack/docs/en/watcher/input/search.asciidoc index 7ce67bfc1dc..3b50b22081b 100644 --- a/x-pack/docs/en/watcher/input/search.asciidoc +++ b/x-pack/docs/en/watcher/input/search.asciidoc @@ -76,7 +76,7 @@ watch payload: "request": { "indices": [ ".watcher-history*" ] }, - "extract": [ "hits.total" ] + "extract": [ "hits.total.value" ] } }, -------------------------------------------------- @@ -130,7 +130,7 @@ check if the search returned more than five hits: } }, "condition" : { - "compare" : { "ctx.payload.hits.total" : { "gt" : 5 }} + "compare" : { "ctx.payload.hits.total.value" : { "gt" : 5 }} } ... } @@ -143,13 +143,20 @@ Conditions, transforms, and actions can access the search results through the watch execution context. For example: * To load all of the search hits into an email body, use `ctx.payload.hits`. -* To reference the total number of hits, use `ctx.payload.hits.total`. +* To reference the total number of hits, use `ctx.payload.hits.total.value`. * To access a particular hit, use its zero-based array index. For example, to get the third hit, use `ctx.payload.hits.hits.2`. * To get a field value from a particular hit, use `ctx.payload.hits.hits..fields.`. For example, to get the message field from the first hit, use `ctx.payload.hits.hits.0.fields.message`. +NOTE: The total number of hits in the search response is returned as an object +in the response. It contains a `value`, the number of hits, and a `relation` that +indicates if the value is accurate (`"eq"`) or a lower bound of the total hits +that match the query (`"gte"`). You can set `track_total_hits` to true in +the search request to tell Elasticsearch to always track the number of hits +accurately. + [[search-input-attributes]] ==== Search Input Attributes diff --git a/x-pack/docs/en/watcher/java/put-watch.asciidoc b/x-pack/docs/en/watcher/java/put-watch.asciidoc index 2bd81f29a24..17d564bbcb9 100644 --- a/x-pack/docs/en/watcher/java/put-watch.asciidoc +++ b/x-pack/docs/en/watcher/java/put-watch.asciidoc @@ -46,7 +46,7 @@ SearchInput input = new SearchInput(new WatcherSearchTemplateRequest(new String[ watchSourceBuilder.input(input); // Set the condition -watchSourceBuilder.condition(new ScriptCondition(new Script("ctx.payload.hits.total > 1"))); +watchSourceBuilder.condition(new ScriptCondition(new Script("ctx.payload.hits.total.value > 1"))); // Create the email template to use for the action EmailTemplate.Builder emailBuilder = EmailTemplate.builder(); @@ -78,7 +78,7 @@ PutWatchResponse putWatchResponse2 = watcherClient.preparePutWatch("my-watch") .filter(rangeQuery("date").gt("{{ctx.trigger.scheduled_time}}")) .filter(rangeQuery("date").lt("{{ctx.execution_time}}")) ).buildAsBytes()))) - .condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 1L)) + .condition(compareCondition("ctx.payload.hits.total.value", CompareCondition.Op.GT, 1L)) .addAction("email_someone", emailAction(EmailTemplate.builder() .to("someone@domain.host.com") .subject("404 recently encountered")))) diff --git a/x-pack/docs/en/watcher/transform/chain.asciidoc b/x-pack/docs/en/watcher/transform/chain.asciidoc index 9ad27fe48ed..4f7fad37256 100644 --- a/x-pack/docs/en/watcher/transform/chain.asciidoc +++ b/x-pack/docs/en/watcher/transform/chain.asciidoc @@ -28,7 +28,7 @@ following snippet: } }, { - "script" : "return [ error_count : ctx.payload.hits.total ]" <3> + "script" : "return [ error_count : ctx.payload.hits.total.value ]" <3> } ] } diff --git a/x-pack/plugin/ccr/qa/src/main/java/org/elasticsearch/xpack/ccr/ESCCRRestTestCase.java b/x-pack/plugin/ccr/qa/src/main/java/org/elasticsearch/xpack/ccr/ESCCRRestTestCase.java index 14780702fc4..6c3b99d8da3 100644 --- a/x-pack/plugin/ccr/qa/src/main/java/org/elasticsearch/xpack/ccr/ESCCRRestTestCase.java +++ b/x-pack/plugin/ccr/qa/src/main/java/org/elasticsearch/xpack/ccr/ESCCRRestTestCase.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HIT_AS_INT_PARAM; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -98,6 +99,7 @@ public class ESCCRRestTestCase extends ESRestTestCase { request.addParameter("size", Integer.toString(expectedNumDocs)); request.addParameter("sort", "field:asc"); request.addParameter("q", query); + request.addParameter(TOTAL_HIT_AS_INT_PARAM, "true"); Map response = toMap(client.performRequest(request)); int numDocs = (int) XContentMapValues.extractValue("hits.total", response); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java index 3233eaa57aa..3185fc46273 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java @@ -468,7 +468,7 @@ public abstract class CcrIntegTestCase extends ESTestCase { SearchRequest request = new SearchRequest(index); request.source(new SearchSourceBuilder().size(0)); SearchResponse response = client.search(request).actionGet(); - return response.getHits().getTotalHits() >= numDocsReplicated; + return response.getHits().getTotalHits().value >= numDocsReplicated; }, 60, TimeUnit.SECONDS); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index 84062962e37..857445ad88d 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -164,7 +164,8 @@ public class IndexFollowingIT extends CcrIntegTestCase { leaderClient().prepareIndex("index1", "doc", Long.toString(i)).setSource(source, XContentType.JSON).get(); } - assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, equalTo(firstBatchNumDocs))); + assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get() + .getHits().getTotalHits().value, equalTo(firstBatchNumDocs))); MappingMetaData mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() .get("index2").get("doc"); assertThat(XContentMapValues.extractValue("properties.f.type", mappingMetaData.sourceAsMap()), equalTo("integer")); @@ -176,7 +177,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { leaderClient().prepareIndex("index1", "doc", Long.toString(i)).setSource(source, XContentType.JSON).get(); } - assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, + assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(firstBatchNumDocs + secondBatchNumDocs))); mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() .get("index2").get("doc"); @@ -199,7 +200,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); leaderClient().prepareIndex("index1", "doc", "1").setSource("{\"f\":1}", XContentType.JSON).get(); - assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, equalTo(1L))); + assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(1L))); pauseFollow("index2"); MappingMetaData mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() @@ -271,7 +272,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { pauseFollow("index2"); leaderClient().admin().indices().prepareRefresh("index1").get(); assertTotalNumberOfOptimizedIndexing(resolveFollowerIndex("index2"), numberOfShards, - leaderClient().prepareSearch("index1").get().getHits().totalHits); + leaderClient().prepareSearch("index1").get().getHits().getTotalHits().value); assertMaxSeqNoOfUpdatesIsTransferred(resolveLeaderIndex("index1"), resolveFollowerIndex("index2"), numberOfShards); } @@ -408,7 +409,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); leaderClient().prepareIndex("index1", "doc", "1").setSource("{}", XContentType.JSON).get(); - assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, equalTo(1L))); + assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(1L))); leaderClient().admin().indices().close(new CloseIndexRequest("index1")).actionGet(); assertBusy(() -> { @@ -425,7 +426,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { leaderClient().admin().indices().open(new OpenIndexRequest("index1")).actionGet(); leaderClient().prepareIndex("index1", "doc", "2").setSource("{}", XContentType.JSON).get(); - assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, equalTo(2L))); + assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(2L))); pauseFollow("index2"); } @@ -442,7 +443,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); leaderClient().prepareIndex("index1", "doc", "1").setSource("{}", XContentType.JSON).get(); - assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, equalTo(1L))); + assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(1L))); followerClient().admin().indices().close(new CloseIndexRequest("index2")).actionGet(); leaderClient().prepareIndex("index1", "doc", "2").setSource("{}", XContentType.JSON).get(); @@ -454,7 +455,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { assertThat(response.getStatsResponses().get(0).status().failedWriteRequests(), greaterThanOrEqualTo(1L)); }); followerClient().admin().indices().open(new OpenIndexRequest("index2")).actionGet(); - assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, equalTo(2L))); + assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(2L))); pauseFollow("index2"); } @@ -471,7 +472,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); leaderClient().prepareIndex("index1", "doc", "1").setSource("{}", XContentType.JSON).get(); - assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, equalTo(1L))); + assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(1L))); leaderClient().admin().indices().delete(new DeleteIndexRequest("index1")).actionGet(); assertBusy(() -> { @@ -500,7 +501,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); leaderClient().prepareIndex("index1", "doc", "1").setSource("{}", XContentType.JSON).get(); - assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, equalTo(1L))); + assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(1L))); followerClient().admin().indices().delete(new DeleteIndexRequest("index2")).actionGet(); leaderClient().prepareIndex("index1", "doc", "2").setSource("{}", XContentType.JSON).get(); @@ -525,7 +526,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); leaderClient().prepareIndex("index1", "doc").setSource("{}", XContentType.JSON).get(); assertBusy(() -> { - assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits(), equalTo(1L)); + assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(1L)); }); // Indexing directly into index2 would fail now, because index2 is a follow index. @@ -542,7 +543,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { followerClient().prepareIndex("index2", "doc").setSource("{}", XContentType.JSON) .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .get(); - assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits(), equalTo(2L)); + assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(2L)); } public void testUnknownClusterAlias() throws Exception { @@ -607,7 +608,8 @@ public class IndexFollowingIT extends CcrIntegTestCase { for (long i = 0; i < firstBatchNumDocs; i++) { leaderClient().prepareIndex("leader", "doc").setSource("{}", XContentType.JSON).get(); } - assertBusy(() -> assertThat(followerClient().prepareSearch("follower").get().getHits().totalHits, equalTo(firstBatchNumDocs))); + assertBusy(() -> assertThat(followerClient().prepareSearch("follower").get() + .getHits().getTotalHits().value, equalTo(firstBatchNumDocs))); // Sanity check that the setting has not been set in follower index: { @@ -634,7 +636,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { assertThat(getFollowTaskSettingsVersion("follower"), equalTo(2L)); try { - assertThat(followerClient().prepareSearch("follower").get().getHits().totalHits, + assertThat(followerClient().prepareSearch("follower").get().getHits().getTotalHits().value, equalTo(firstBatchNumDocs + secondBatchNumDocs)); } catch (Exception e) { throw new AssertionError("error while searching", e); @@ -660,7 +662,8 @@ public class IndexFollowingIT extends CcrIntegTestCase { for (long i = 0; i < firstBatchNumDocs; i++) { leaderClient().prepareIndex("leader", "doc").setSource("{}", XContentType.JSON).get(); } - assertBusy(() -> assertThat(followerClient().prepareSearch("follower").get().getHits().totalHits, equalTo(firstBatchNumDocs))); + assertBusy(() -> assertThat(followerClient().prepareSearch("follower").get() + .getHits().getTotalHits().value, equalTo(firstBatchNumDocs))); // Sanity check that the setting has not been set in follower index: { @@ -686,7 +689,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { assertThat(getFollowTaskSettingsVersion("follower"), equalTo(2L)); try { - assertThat(followerClient().prepareSearch("follower").get().getHits().totalHits, + assertThat(followerClient().prepareSearch("follower").get().getHits().getTotalHits().value, equalTo(firstBatchNumDocs + secondBatchNumDocs)); } catch (Exception e) { throw new AssertionError("error while searching", e); @@ -710,7 +713,8 @@ public class IndexFollowingIT extends CcrIntegTestCase { leaderClient().prepareIndex("leader", "doc").setSource("{}", XContentType.JSON).get(); } - assertBusy(() -> assertThat(followerClient().prepareSearch("follower").get().getHits().totalHits, equalTo(firstBatchNumDocs))); + assertBusy(() -> assertThat(followerClient().prepareSearch("follower").get() + .getHits().getTotalHits().value, equalTo(firstBatchNumDocs))); assertThat(getFollowTaskSettingsVersion("follower"), equalTo(1L)); assertThat(getFollowTaskMappingVersion("follower"), equalTo(1L)); @@ -758,7 +762,7 @@ public class IndexFollowingIT extends CcrIntegTestCase { equalTo("my_analyzer")); try { - assertThat(followerClient().prepareSearch("follower").get().getHits().totalHits, + assertThat(followerClient().prepareSearch("follower").get().getHits().getTotalHits().value, equalTo(firstBatchNumDocs + secondBatchNumDocs)); } catch (Exception e) { throw new AssertionError("error while searching", e); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java index 363897293a9..8d096fe1f59 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java @@ -40,7 +40,7 @@ public class LocalIndexFollowingIT extends CcrSingleNodeTestCase { } assertBusy(() -> { - assertThat(client().prepareSearch("follower").get().getHits().totalHits, equalTo(firstBatchNumDocs)); + assertThat(client().prepareSearch("follower").get().getHits().getTotalHits().value, equalTo(firstBatchNumDocs)); }); final long secondBatchNumDocs = randomIntBetween(2, 64); @@ -49,7 +49,8 @@ public class LocalIndexFollowingIT extends CcrSingleNodeTestCase { } assertBusy(() -> { - assertThat(client().prepareSearch("follower").get().getHits().totalHits, equalTo(firstBatchNumDocs + secondBatchNumDocs)); + assertThat(client().prepareSearch("follower").get() + .getHits().getTotalHits().value, equalTo(firstBatchNumDocs + secondBatchNumDocs)); }); PauseFollowAction.Request pauseRequest = new PauseFollowAction.Request("follower"); @@ -62,7 +63,7 @@ public class LocalIndexFollowingIT extends CcrSingleNodeTestCase { client().execute(ResumeFollowAction.INSTANCE, getResumeFollowRequest()).get(); assertBusy(() -> { - assertThat(client().prepareSearch("follower").get().getHits().totalHits, + assertThat(client().prepareSearch("follower").get().getHits().getTotalHits().value, equalTo(firstBatchNumDocs + secondBatchNumDocs + thirdBatchNumDocs)); }); ensureEmptyWriteBuffers(); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/RestartIndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/RestartIndexFollowingIT.java index 49fbe15ddab..d72eca17fdb 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/RestartIndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/RestartIndexFollowingIT.java @@ -42,7 +42,7 @@ public class RestartIndexFollowingIT extends CcrIntegTestCase { } assertBusy(() -> { - assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, equalTo(firstBatchNumDocs)); + assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(firstBatchNumDocs)); }); getFollowerCluster().fullRestart(); @@ -54,7 +54,7 @@ public class RestartIndexFollowingIT extends CcrIntegTestCase { } assertBusy(() -> { - assertThat(followerClient().prepareSearch("index2").get().getHits().totalHits, + assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(firstBatchNumDocs + secondBatchNumDocs)); }); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/ScrollHelper.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/ScrollHelper.java index 97f8eb5fa11..e3311c836a7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/ScrollHelper.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/ScrollHelper.java @@ -67,12 +67,12 @@ public final class ScrollHelper { } } - if (results.size() > resp.getHits().getTotalHits()) { + if (results.size() > resp.getHits().getTotalHits().value) { clearScroll.accept(lastResponse); listener.onFailure(new IllegalStateException("scrolling returned more hits [" + results.size() - + "] than expected [" + resp.getHits().getTotalHits() + "] so bailing out to prevent unbounded " + + "] than expected [" + resp.getHits().getTotalHits().value + "] so bailing out to prevent unbounded " + "memory consumption.")); - } else if (results.size() == resp.getHits().getTotalHits()) { + } else if (results.size() == resp.getHits().getTotalHits().value) { clearScroll.accept(resp); // Finally, return the list of the entity listener.onResponse(Collections.unmodifiableList(results)); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/WatcherUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/WatcherUtils.java index 15d56db578b..389d8ef9960 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/WatcherUtils.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/WatcherUtils.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.core.watcher.support; import org.elasticsearch.common.Strings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; @@ -27,8 +28,9 @@ public final class WatcherUtils { private WatcherUtils() { } - public static Map responseToData(ToXContentObject response) throws IOException { - return XContentHelper.convertToMap(XContentHelper.toXContent(response, XContentType.JSON, false), false, XContentType.JSON).v2(); + public static Map responseToData(ToXContentObject response, ToXContent.Params params) throws IOException { + return XContentHelper.convertToMap(XContentHelper.toXContent(response, XContentType.JSON, params, false), false, + XContentType.JSON).v2(); } public static Map flattenModel(Map map) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/watch/Payload.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/watch/Payload.java index 7ef57c37f30..2c9f5647330 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/watch/Payload.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/watch/Payload.java @@ -73,8 +73,8 @@ public interface Payload extends ToXContentObject { } class XContent extends Simple { - public XContent(ToXContentObject response) throws IOException { - super(responseToData(response)); + public XContent(ToXContentObject response, Params params) throws IOException { + super(responseToData(response, params)); } } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java index 737e2e26970..6e35237981c 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java @@ -122,6 +122,7 @@ public class SourceOnlySnapshotIT extends ESIntegTestCase { assertHits(sourceIdx, builders.length, sourceHadDeletions); } + @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/36276") public void testSnapshotAndRestoreWithNested() throws Exception { final String sourceIdx = "test-idx"; boolean requireRouting = randomBoolean(); @@ -191,7 +192,7 @@ public class SourceOnlySnapshotIT extends ESIntegTestCase { } }; assertConsumer.accept(searchResponse, sourceHadDeletions); - assertEquals(numDocsExpected, searchResponse.getHits().totalHits); + assertEquals(numDocsExpected, searchResponse.getHits().getTotalHits().value); searchResponse = client().prepareSearch(index) .addSort(SeqNoFieldMapper.NAME, SortOrder.ASC) .setScroll("1m") diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexing/AsyncTwoPhaseIndexerTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexing/AsyncTwoPhaseIndexerTests.java index 46d09e30eae..a3826bcf7cd 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexing/AsyncTwoPhaseIndexerTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexing/AsyncTwoPhaseIndexerTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.core.indexing; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkResponse; @@ -70,9 +71,9 @@ public class AsyncTwoPhaseIndexerTests extends ESTestCase { protected void doNextSearch(SearchRequest request, ActionListener nextPhase) { assertThat(step, equalTo(2)); ++step; - final SearchResponseSections sections = new SearchResponseSections(new SearchHits(new SearchHit[0], 0, 0), null, null, false, - null, null, 1); - + final SearchResponseSections sections = new SearchResponseSections( + new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0), null, + null, false, null, null, 1); nextPhase.onResponse(new SearchResponse(sections, null, 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, null)); } diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DeleteExpiredDataIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DeleteExpiredDataIT.java index e5aaf5f4fdb..34c0bdda8f2 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DeleteExpiredDataIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DeleteExpiredDataIT.java @@ -165,8 +165,8 @@ public class DeleteExpiredDataIT extends MlNativeAutodetectIntegTestCase { long totalModelSizeStatsBeforeDelete = client().prepareSearch("*") .setQuery(QueryBuilders.termQuery("result_type", "model_size_stats")) - .get().getHits().totalHits; - long totalNotificationsCountBeforeDelete = client().prepareSearch(".ml-notifications").get().getHits().totalHits; + .get().getHits().getTotalHits().value; + long totalNotificationsCountBeforeDelete = client().prepareSearch(".ml-notifications").get().getHits().getTotalHits().value; assertThat(totalModelSizeStatsBeforeDelete, greaterThan(0L)); assertThat(totalNotificationsCountBeforeDelete, greaterThan(0L)); @@ -223,8 +223,8 @@ public class DeleteExpiredDataIT extends MlNativeAutodetectIntegTestCase { long totalModelSizeStatsAfterDelete = client().prepareSearch("*") .setQuery(QueryBuilders.termQuery("result_type", "model_size_stats")) - .get().getHits().totalHits; - long totalNotificationsCountAfterDelete = client().prepareSearch(".ml-notifications").get().getHits().totalHits; + .get().getHits().getTotalHits().value; + long totalNotificationsCountAfterDelete = client().prepareSearch(".ml-notifications").get().getHits().getTotalHits().value; assertThat(totalModelSizeStatsAfterDelete, equalTo(totalModelSizeStatsBeforeDelete)); assertThat(totalNotificationsCountAfterDelete, greaterThanOrEqualTo(totalNotificationsCountBeforeDelete)); @@ -245,7 +245,7 @@ public class DeleteExpiredDataIT extends MlNativeAutodetectIntegTestCase { .setFetchSource(false) .setSize(10000) .get(); - assertThat(stateDocsResponse.getHits().getTotalHits(), lessThan(10000L)); + assertThat(stateDocsResponse.getHits().getTotalHits().value, lessThan(10000L)); for (SearchHit hit : stateDocsResponse.getHits().getHits()) { assertThat(hit.getId().startsWith("non_existing_job"), is(false)); } diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/InterimResultsDeletedAfterReopeningJobIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/InterimResultsDeletedAfterReopeningJobIT.java index add0b9e8a93..2d317c41d97 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/InterimResultsDeletedAfterReopeningJobIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/InterimResultsDeletedAfterReopeningJobIT.java @@ -111,6 +111,6 @@ public class InterimResultsDeletedAfterReopeningJobIT extends MlNativeAutodetect String indexName = AnomalyDetectorsIndex.jobResultsAliasedName(jobId); SearchResponse search = client().prepareSearch(indexName).setTypes("result").setSize(1000) .setQuery(QueryBuilders.termQuery("is_interim", true)).get(); - assertThat(search.getHits().getTotalHits(), equalTo(0L)); + assertThat(search.getHits().getTotalHits().value, equalTo(0L)); } } diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java index 633653714fc..0283c2c29a3 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java @@ -216,7 +216,7 @@ public class MlJobIT extends ESRestTestCase { responseAsString = EntityUtils.toString(client().performRequest( new Request("GET", AnomalyDetectorsIndex.jobResultsAliasedName(jobId1) + "/_search")).getEntity()); - assertThat(responseAsString, containsString("\"total\":2")); + assertThat(responseAsString, containsString("\"value\":2")); } { //create jobId2 docs String id = String.format(Locale.ROOT, "%s_bucket_%s_%s", jobId2, "1234", 300); @@ -241,7 +241,7 @@ public class MlJobIT extends ESRestTestCase { responseAsString = EntityUtils.toString(client().performRequest( new Request("GET", AnomalyDetectorsIndex.jobResultsAliasedName(jobId2) + "/_search")).getEntity()); - assertThat(responseAsString, containsString("\"total\":2")); + assertThat(responseAsString, containsString("\"value\":2")); } client().performRequest(new Request("DELETE", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId1)); diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeAutodetectIntegTestCase.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeAutodetectIntegTestCase.java index 1fd0eddf41c..a22660dca01 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeAutodetectIntegTestCase.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeAutodetectIntegTestCase.java @@ -392,7 +392,7 @@ abstract class MlNativeAutodetectIntegTestCase extends ESIntegTestCase { .filter(QueryBuilders.termQuery(Job.ID.getPreferredName(), jobId)) .filter(QueryBuilders.termQuery(Forecast.FORECAST_ID.getPreferredName(), forecastId))) .execute().actionGet(); - return searchResponse.getHits().getTotalHits(); + return searchResponse.getHits().getTotalHits().value; } protected List getForecasts(String jobId, ForecastRequestStats forecastRequestStats) { diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/RevertModelSnapshotIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/RevertModelSnapshotIT.java index 3400d09ee75..95125227095 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/RevertModelSnapshotIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/RevertModelSnapshotIT.java @@ -161,7 +161,7 @@ public class RevertModelSnapshotIT extends MlNativeAutodetectIntegTestCase { .setSize(1) .get(); SearchHits hits = response.getHits(); - assertThat(hits.getTotalHits(), equalTo(1L)); + assertThat(hits.getTotalHits().value, equalTo(1L)); try { XContentParser parser = JsonXContent.jsonXContent .createParser(null, LoggingDeprecationHandler.INSTANCE, hits.getAt(0).getSourceAsString()); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobAction.java index 4dd2d820c36..32ea8de32a9 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobAction.java @@ -307,7 +307,7 @@ public class TransportDeleteJobAction extends TransportMasterNodeAction customIndexSearchHandler = ActionListener.wrap( searchResponse -> { - if (searchResponse == null || searchResponse.getHits().totalHits > 0) { + if (searchResponse == null || searchResponse.getHits().getTotalHits().value > 0) { deleteByQueryExecutor.onResponse(true); // We need to run DBQ and alias deletion } else { logger.info("Running DELETE Index on [" + indexName + "] for job [" + jobId + "]"); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetOverallBucketsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetOverallBucketsAction.java index 620d665cac9..8bcabf984ad 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetOverallBucketsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetOverallBucketsAction.java @@ -138,7 +138,7 @@ public class TransportGetOverallBucketsAction extends HandledTransportActionwrap(searchResponse -> { - long totalHits = searchResponse.getHits().getTotalHits(); + long totalHits = searchResponse.getHits().getTotalHits().value; if (totalHits > 0) { Aggregations aggregations = searchResponse.getAggregations(); Min min = aggregations.get(EARLIEST_TIME); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/extractor/chunked/ChunkedDataExtractor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/extractor/chunked/ChunkedDataExtractor.java index dea9aca1d48..c0a2c142dcd 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/extractor/chunked/ChunkedDataExtractor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/extractor/chunked/ChunkedDataExtractor.java @@ -201,7 +201,7 @@ public class ChunkedDataExtractor implements DataExtractor { Aggregations aggregations = response.getAggregations(); long earliestTime = 0; long latestTime = 0; - long totalHits = response.getHits().getTotalHits(); + long totalHits = response.getHits().getTotalHits().value; if (totalHits > 0) { Min min = aggregations.get(EARLIEST_TIME); earliestTime = (long) min.getValue(); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BatchedDocumentsIterator.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BatchedDocumentsIterator.java index 371b7e05f63..8284e05018e 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BatchedDocumentsIterator.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BatchedDocumentsIterator.java @@ -101,7 +101,7 @@ public abstract class BatchedDocumentsIterator { .sort(SortBuilders.fieldSort(ElasticsearchMappings.ES_DOC))); SearchResponse searchResponse = client.search(searchRequest).actionGet(); - totalHits = searchResponse.getHits().getTotalHits(); + totalHits = searchResponse.getHits().getTotalHits().value; scrollId = searchResponse.getScrollId(); return searchResponse; } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java index 768d7bd5ec5..72f52fa1c30 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java @@ -545,7 +545,8 @@ public class JobResultsProvider { throw QueryPage.emptyQueryPage(Bucket.RESULTS_FIELD); } - QueryPage buckets = new QueryPage<>(results, searchResponse.getHits().getTotalHits(), Bucket.RESULTS_FIELD); + QueryPage buckets = new QueryPage<>(results, + searchResponse.getHits().getTotalHits().value, Bucket.RESULTS_FIELD); if (query.isExpand()) { Iterator bucketsToExpand = buckets.results().stream() @@ -677,7 +678,7 @@ public class JobResultsProvider { } } QueryPage result = - new QueryPage<>(results, searchResponse.getHits().getTotalHits(), CategoryDefinition.RESULTS_FIELD); + new QueryPage<>(results, searchResponse.getHits().getTotalHits().value, CategoryDefinition.RESULTS_FIELD); handler.accept(result); }, e -> errorHandler.accept(mapAuthFailure(e, jobId, GetCategoriesAction.NAME))), client::search); } @@ -722,7 +723,7 @@ public class JobResultsProvider { } } QueryPage queryPage = - new QueryPage<>(results, searchResponse.getHits().getTotalHits(), AnomalyRecord.RESULTS_FIELD); + new QueryPage<>(results, searchResponse.getHits().getTotalHits().value, AnomalyRecord.RESULTS_FIELD); handler.accept(queryPage); }, e -> errorHandler.accept(mapAuthFailure(e, jobId, GetRecordsAction.NAME))), client::search); } @@ -771,7 +772,7 @@ public class JobResultsProvider { } } QueryPage result = - new QueryPage<>(influencers, response.getHits().getTotalHits(), Influencer.RESULTS_FIELD); + new QueryPage<>(influencers, response.getHits().getTotalHits().value, Influencer.RESULTS_FIELD); handler.accept(result); }, e -> errorHandler.accept(mapAuthFailure(e, jobId, GetInfluencersAction.NAME))), client::search); } @@ -885,7 +886,7 @@ public class JobResultsProvider { } QueryPage result = - new QueryPage<>(results, searchResponse.getHits().getTotalHits(), ModelSnapshot.RESULTS_FIELD); + new QueryPage<>(results, searchResponse.getHits().getTotalHits().value, ModelSnapshot.RESULTS_FIELD); handler.accept(result); }, errorHandler), client::search); } @@ -917,7 +918,7 @@ public class JobResultsProvider { } } - return new QueryPage<>(results, searchResponse.getHits().getTotalHits(), ModelPlot.RESULTS_FIELD); + return new QueryPage<>(results, searchResponse.getHits().getTotalHits().value, ModelPlot.RESULTS_FIELD); } /** @@ -1100,7 +1101,7 @@ public class JobResultsProvider { events.add(event.build()); } - handler.onResponse(new QueryPage<>(events, response.getHits().getTotalHits(), + handler.onResponse(new QueryPage<>(events, response.getHits().getTotalHits().value, ScheduledEvent.RESULTS_FIELD)); }, handler::onFailure), @@ -1142,7 +1143,7 @@ public class JobResultsProvider { executeAsyncWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN, searchRequest, ActionListener.wrap(searchResponse -> { - long totalHits = searchResponse.getHits().getTotalHits(); + long totalHits = searchResponse.getHits().getTotalHits().value; Aggregations aggregations = searchResponse.getAggregations(); if (totalHits == 0 || aggregations == null) { handler.accept(new ForecastStats()); @@ -1221,7 +1222,7 @@ public class JobResultsProvider { calendars.add(parseSearchHit(hit, Calendar.LENIENT_PARSER, listener::onFailure).build()); } - listener.onResponse(new QueryPage(calendars, response.getHits().getTotalHits(), + listener.onResponse(new QueryPage(calendars, response.getHits().getTotalHits().value, Calendar.RESULTS_FIELD)); }, listener::onFailure) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredForecastsRemover.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredForecastsRemover.java index 981d257afa1..c7bc29d8b62 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredForecastsRemover.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredForecastsRemover.java @@ -123,7 +123,7 @@ public class ExpiredForecastsRemover implements MlDataRemover { List forecastsToDelete = new ArrayList<>(); SearchHits hits = searchResponse.getHits(); - if (hits.getTotalHits() > MAX_FORECASTS) { + if (hits.getTotalHits().value > MAX_FORECASTS) { LOGGER.info("More than [{}] forecasts were found. This run will only delete [{}] of them", MAX_FORECASTS, MAX_FORECASTS); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/chunked/ChunkedDataExtractorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/chunked/ChunkedDataExtractorTests.java index 4f0d3ec8e9f..b4ebb6d1800 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/chunked/ChunkedDataExtractorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/chunked/ChunkedDataExtractorTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.ml.datafeed.extractor.chunked; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; @@ -501,7 +502,7 @@ public class ChunkedDataExtractorTests extends ESTestCase { SearchResponse searchResponse = mock(SearchResponse.class); when(searchResponse.status()).thenReturn(RestStatus.OK); SearchHit[] hits = new SearchHit[(int)totalHits]; - SearchHits searchHits = new SearchHits(hits, totalHits, 1); + SearchHits searchHits = new SearchHits(hits, new TotalHits(totalHits, TotalHits.Relation.EQUAL_TO), 1); when(searchResponse.getHits()).thenReturn(searchHits); List aggs = new ArrayList<>(); @@ -522,7 +523,7 @@ public class ChunkedDataExtractorTests extends ESTestCase { SearchResponse searchResponse = mock(SearchResponse.class); when(searchResponse.status()).thenReturn(RestStatus.OK); SearchHit[] hits = new SearchHit[0]; - SearchHits searchHits = new SearchHits(hits, 0, 1); + SearchHits searchHits = new SearchHits(hits, new TotalHits(0, TotalHits.Relation.EQUAL_TO), 1); when(searchResponse.getHits()).thenReturn(searchHits); List aggs = new ArrayList<>(); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ScrollDataExtractorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ScrollDataExtractorTests.java index 93a76c5402b..fbe721b6592 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ScrollDataExtractorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ScrollDataExtractorTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.ml.datafeed.extractor.scroll; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.search.ClearScrollAction; import org.elasticsearch.action.search.ClearScrollRequest; @@ -488,7 +489,8 @@ public class ScrollDataExtractorTests extends ESTestCase { hit.fields(fields); hits.add(hit); } - SearchHits searchHits = new SearchHits(hits.toArray(new SearchHit[0]), hits.size(), 1); + SearchHits searchHits = new SearchHits(hits.toArray(new SearchHit[0]), + new TotalHits(hits.size(), TotalHits.Relation.EQUAL_TO), 1); when(searchResponse.getHits()).thenReturn(searchHits); return searchResponse; } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java index 2e14289da70..8befaf23d6d 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java @@ -242,7 +242,7 @@ public class MlDistributedFailureIT extends BaseMlIntegTestCase { SearchResponse searchResponse = client().prepareSearch() .setQuery(QueryBuilders.idsQuery().addIds(DataCounts.documentId(jobId))) .get(); - if (searchResponse.getHits().getTotalHits() != 1) { + if (searchResponse.getHits().getTotalHits().value != 1) { return new DataCounts(jobId); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/NetworkDisruptionIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/NetworkDisruptionIT.java index 67138cde5bd..4ab369120e0 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/NetworkDisruptionIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/NetworkDisruptionIT.java @@ -96,7 +96,7 @@ public class NetworkDisruptionIT extends BaseMlIntegTestCase { SearchResponse searchResponse = client().prepareSearch(AnomalyDetectorsIndex.jobStateIndexName()) .setQuery(QueryBuilders.idsQuery().addIds(Quantiles.documentId(job.getId()))) .setIndicesOptions(IndicesOptions.lenientExpandOpen()).execute().actionGet(); - assertEquals(0L, searchResponse.getHits().getTotalHits()); + assertEquals(0L, searchResponse.getHits().getTotalHits().value); CloseJobAction.Request closeJobRequest = new CloseJobAction.Request(job.getId()); CloseJobAction.Response closeJobResponse = client().execute(CloseJobAction.INSTANCE, closeJobRequest).actionGet(); @@ -106,6 +106,6 @@ public class NetworkDisruptionIT extends BaseMlIntegTestCase { searchResponse = client().prepareSearch(AnomalyDetectorsIndex.jobStateIndexName()) .setQuery(QueryBuilders.idsQuery().addIds(Quantiles.documentId(job.getId()))) .setIndicesOptions(IndicesOptions.lenientExpandOpen()).execute().actionGet(); - assertEquals(1L, searchResponse.getHits().getTotalHits()); + assertEquals(1L, searchResponse.getHits().getTotalHits().value); } } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/BatchedDocumentsIteratorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/BatchedDocumentsIteratorTests.java index f5a4e34bc67..0e4738141e5 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/BatchedDocumentsIteratorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/BatchedDocumentsIteratorTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.ml.job.persistence; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.search.ClearScrollRequestBuilder; import org.elasticsearch.action.search.SearchRequest; @@ -216,7 +217,7 @@ public class BatchedDocumentsIteratorTests extends ESTestCase { for (String value : values) { hits.add(new SearchHitBuilder(randomInt()).setSource(value).build()); } - return new SearchHits(hits.toArray(new SearchHit[hits.size()]), totalHits, 1.0f); + return new SearchHits(hits.toArray(new SearchHit[hits.size()]), new TotalHits(totalHits, TotalHits.Relation.EQUAL_TO), 1.0f); } } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java index 929961a33fc..c2bda603724 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.ml.job.persistence; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; @@ -856,7 +857,7 @@ public class JobResultsProviderTests extends ESTestCase { list.add(hit); } - SearchHits hits = new SearchHits(list.toArray(new SearchHit[0]), source.size(), 1); + SearchHits hits = new SearchHits(list.toArray(new SearchHit[0]), new TotalHits(source.size(), TotalHits.Relation.EQUAL_TO), 1); when(response.getHits()).thenReturn(hits); return response; diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/retention/ExpiredModelSnapshotsRemoverTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/retention/ExpiredModelSnapshotsRemoverTests.java index 9f056e91854..6e29f298b3f 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/retention/ExpiredModelSnapshotsRemoverTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/retention/ExpiredModelSnapshotsRemoverTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.ml.job.retention; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.search.SearchRequest; @@ -232,7 +233,7 @@ public class ExpiredModelSnapshotsRemoverTests extends ESTestCase { modelSnapshots.get(i).toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS); hitsArray[i].sourceRef(BytesReference.bytes(jsonBuilder)); } - SearchHits hits = new SearchHits(hitsArray, hitsArray.length, 1.0f); + SearchHits hits = new SearchHits(hitsArray, new TotalHits(hitsArray.length, TotalHits.Relation.EQUAL_TO), 1.0f); SearchResponse searchResponse = mock(SearchResponse.class); when(searchResponse.getHits()).thenReturn(hits); return searchResponse; diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java index 2c0ee6379e4..c23ef3c8ee5 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java @@ -115,7 +115,7 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase { ensureYellowAndNoInitializingShards(".monitoring-*"); SearchResponse response = client().prepareSearch(".monitoring-*").get(); - assertThat((long)nbDocs, lessThanOrEqualTo(response.getHits().getTotalHits())); + assertThat((long)nbDocs, lessThanOrEqualTo(response.getHits().getTotalHits().value)); }); checkMonitoringTemplates(); @@ -131,27 +131,27 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase { assertThat(client().prepareSearch(".monitoring-es-*") .setSize(0) .setQuery(QueryBuilders.termQuery("type", "cluster_stats")) - .get().getHits().getTotalHits(), greaterThan(0L)); + .get().getHits().getTotalHits().value, greaterThan(0L)); assertThat(client().prepareSearch(".monitoring-es-*") .setSize(0) .setQuery(QueryBuilders.termQuery("type", "index_recovery")) - .get().getHits().getTotalHits(), greaterThan(0L)); + .get().getHits().getTotalHits().value, greaterThan(0L)); assertThat(client().prepareSearch(".monitoring-es-*") .setSize(0) .setQuery(QueryBuilders.termQuery("type", "index_stats")) - .get().getHits().getTotalHits(), greaterThan(0L)); + .get().getHits().getTotalHits().value, greaterThan(0L)); assertThat(client().prepareSearch(".monitoring-es-*") .setSize(0) .setQuery(QueryBuilders.termQuery("type", "indices_stats")) - .get().getHits().getTotalHits(), greaterThan(0L)); + .get().getHits().getTotalHits().value, greaterThan(0L)); assertThat(client().prepareSearch(".monitoring-es-*") .setSize(0) .setQuery(QueryBuilders.termQuery("type", "shards")) - .get().getHits().getTotalHits(), greaterThan(0L)); + .get().getHits().getTotalHits().value, greaterThan(0L)); SearchResponse response = client().prepareSearch(".monitoring-es-*") .setSize(0) @@ -263,7 +263,7 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase { DateTimeFormatter dateFormatter = DateTimeFormat.forPattern(customTimeFormat).withZoneUTC(); SearchResponse searchResponse = client().prepareSearch(".monitoring-*").setSize(100).get(); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L)); for (SearchHit hit : searchResponse.getHits().getHits()) { final Map source = hit.getSourceAsMap(); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/integration/MonitoringIT.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/integration/MonitoringIT.java index f976eb9727c..dd45c3e06db 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/integration/MonitoringIT.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/integration/MonitoringIT.java @@ -146,7 +146,7 @@ public class MonitoringIT extends ESSingleNodeTestCase { .get(); // exactly 3 results are expected - assertThat("No monitoring documents yet", response.getHits().getTotalHits(), equalTo(3L)); + assertThat("No monitoring documents yet", response.getHits().getTotalHits().value, equalTo(3L)); final List> sources = Arrays.stream(response.getHits().getHits()) @@ -162,7 +162,7 @@ public class MonitoringIT extends ESSingleNodeTestCase { final SearchResponse response = client().prepareSearch(monitoringIndex).get(); final SearchHits hits = response.getHits(); - assertThat(response.getHits().getTotalHits(), equalTo(3L)); + assertThat(response.getHits().getTotalHits().value, equalTo(3L)); assertThat("Monitoring documents must have the same timestamp", Arrays.stream(hits.getHits()) .map(hit -> extractValue("timestamp", hit.getSourceAsMap())) @@ -609,7 +609,7 @@ public class MonitoringIT extends ESSingleNodeTestCase { assertThat("No monitoring documents yet", client().prepareSearch(".monitoring-es-" + TEMPLATE_VERSION + "-*") .setSize(0) - .get().getHits().getTotalHits(), + .get().getHits().getTotalHits().value, greaterThan(0L)); }); } diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerStateTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerStateTests.java index baa35ff2fca..37b3fd84ef1 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerStateTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerStateTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.rollup.job; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.bulk.BulkItemResponse; import org.elasticsearch.action.bulk.BulkRequest; @@ -93,7 +94,8 @@ public class RollupIndexerStateTests extends ESTestCase { return null; } })); - final SearchResponseSections sections = new SearchResponseSections(new SearchHits(new SearchHit[0], 0, 0), + final SearchResponseSections sections = new SearchResponseSections( + new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0), aggs, null, false, null, null, 1); final SearchResponse response = new SearchResponse(sections, null, 1, 1, 0, 0, new ShardSearchFailure[0], null); @@ -410,7 +412,8 @@ public class RollupIndexerStateTests extends ESTestCase { return null; } })); - final SearchResponseSections sections = new SearchResponseSections(new SearchHits(new SearchHit[0], 0, 0), + final SearchResponseSections sections = new SearchResponseSections( + new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0), aggs, null, false, null, null, 1); final SearchResponse response = new SearchResponse(sections, null, 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, null); @@ -615,7 +618,8 @@ public class RollupIndexerStateTests extends ESTestCase { return null; } })); - final SearchResponseSections sections = new SearchResponseSections(new SearchHits(new SearchHit[0], 0, 0), + final SearchResponseSections sections = new SearchResponseSections( + new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0), aggs, null, false, null, null, 1); return new SearchResponse(sections, null, 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, null); @@ -723,7 +727,8 @@ public class RollupIndexerStateTests extends ESTestCase { return null; } })); - final SearchResponseSections sections = new SearchResponseSections(new SearchHits(new SearchHit[0], 0, 0), + final SearchResponseSections sections = new SearchResponseSections( + new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0), aggs, null, false, null, null, 1); return new SearchResponse(sections, null, 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, null); @@ -873,7 +878,8 @@ public class RollupIndexerStateTests extends ESTestCase { return null; } })); - final SearchResponseSections sections = new SearchResponseSections(new SearchHits(new SearchHit[0], 0, 0), + final SearchResponseSections sections = new SearchResponseSections( + new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0), aggs, null, false, null, null, 1); return new SearchResponse(sections, null, 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, null); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStore.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStore.java index f941f560c11..47c32489ae1 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStore.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStore.java @@ -179,7 +179,7 @@ public class NativeUsersStore { new ActionListener() { @Override public void onResponse(SearchResponse response) { - listener.onResponse(response.getHits().getTotalHits()); + listener.onResponse(response.getHits().getTotalHits().value); } @Override @@ -584,7 +584,7 @@ public class NativeUsersStore { @Override public void onResponse(SearchResponse searchResponse) { Map userInfos = new HashMap<>(); - assert searchResponse.getHits().getTotalHits() <= 10 : + assert searchResponse.getHits().getTotalHits().value <= 10 : "there are more than 10 reserved users we need to change this to retrieve them all!"; for (SearchHit searchHit : searchResponse.getHits().getHits()) { Map sourceMap = searchHit.getSourceAsMap(); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStore.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStore.java index 7895aced464..a36f830ceac 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStore.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStore.java @@ -278,18 +278,18 @@ public class NativeRolesStore implements BiConsumer, ActionListener< if (responses[0].isFailure()) { usageStats.put("size", 0); } else { - usageStats.put("size", responses[0].getResponse().getHits().getTotalHits()); + usageStats.put("size", responses[0].getResponse().getHits().getTotalHits().value); } if (responses[1].isFailure()) { usageStats.put("fls", false); } else { - usageStats.put("fls", responses[1].getResponse().getHits().getTotalHits() > 0L); + usageStats.put("fls", responses[1].getResponse().getHits().getTotalHits().value > 0L); } if (responses[2].isFailure()) { usageStats.put("dls", false); } else { - usageStats.put("dls", responses[2].getResponse().getHits().getTotalHits() > 0L); + usageStats.put("dls", responses[2].getResponse().getHits().getTotalHits().value > 0L); } listener.onResponse(usageStats); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java index df36527d7ac..dbdb16b7983 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java @@ -79,12 +79,12 @@ public class DateMathExpressionIntegTests extends SecurityIntegTestCase { SearchResponse searchResponse = client.prepareSearch(expression) .setQuery(QueryBuilders.matchAllQuery()) .get(); - assertThat(searchResponse.getHits().getTotalHits(), is(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, is(1L)); MultiSearchResponse multiSearchResponse = client.prepareMultiSearch() .add(client.prepareSearch(expression).setQuery(QueryBuilders.matchAllQuery()).request()) .get(); - assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); UpdateResponse updateResponse = client.prepareUpdate(expression, "type", response.getId()) .setDoc(Requests.INDEX_CONTENT_TYPE, "new", "field") diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityRandomTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityRandomTests.java index 27a78981af0..beb54f59631 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityRandomTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityRandomTests.java @@ -110,7 +110,7 @@ public class DocumentLevelSecurityRandomTests extends SecurityIntegTestCase { .prepareSearch("test") .get(); SearchResponse searchResponse2 = client().prepareSearch("alias" + roleI).get(); - assertThat(searchResponse1.getHits().getTotalHits(), equalTo(searchResponse2.getHits().getTotalHits())); + assertThat(searchResponse1.getHits().getTotalHits().value, equalTo(searchResponse2.getHits().getTotalHits().value)); for (int hitI = 0; hitI < searchResponse1.getHits().getHits().length; hitI++) { assertThat(searchResponse1.getHits().getAt(hitI).getId(), equalTo(searchResponse2.getHits().getAt(hitI).getId())); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java index f1ab81ce3a4..8d25f0d8361 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java @@ -354,13 +354,13 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase { .add(client().prepareSearch("test2").setTypes("type1").setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(2)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("id"), is(1)); assertFalse(response.getResponses()[1].isFailure()); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(2)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("id"), is(1)); @@ -372,13 +372,13 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase { .add(client().prepareSearch("test2").setTypes("type1").setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(2)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("id"), is(2)); assertFalse(response.getResponses()[1].isFailure()); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(2)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("id"), is(2)); @@ -392,7 +392,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase { .setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(2L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(2L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(2)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("id"), is(1)); @@ -401,7 +401,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase { assertThat(response.getResponses()[0].getResponse().getHits().getAt(1).getSourceAsMap().get("id"), is(2)); assertFalse(response.getResponses()[1].isFailure()); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(2L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(2L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(2)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("id"), is(1)); @@ -735,7 +735,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase { .get(); do { assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), is((long) numVisible)); + assertThat(response.getHits().getTotalHits().value, is((long) numVisible)); assertThat(response.getHits().getAt(0).getSourceAsMap().size(), is(1)); assertThat(response.getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java index d1cdc1694a6..3a44a973d48 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java @@ -194,7 +194,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase { .should(QueryBuilders.termQuery("field1", "value")) ) .get(); - assertThat(actual.getHits().getTotalHits(), equalTo(expected.getHits().getTotalHits())); + assertThat(actual.getHits().getTotalHits().value, equalTo(expected.getHits().getTotalHits().value)); assertThat(actual.getHits().getHits().length, equalTo(expected.getHits().getHits().length)); for (int i = 0; i < actual.getHits().getHits().length; i++) { assertThat(actual.getHits().getAt(i).getId(), equalTo(expected.getHits().getAt(i).getId())); @@ -215,7 +215,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase { .should(QueryBuilders.termQuery("field2", "value")) ) .get(); - assertThat(actual.getHits().getTotalHits(), equalTo(expected.getHits().getTotalHits())); + assertThat(actual.getHits().getTotalHits().value, equalTo(expected.getHits().getTotalHits().value)); assertThat(actual.getHits().getHits().length, equalTo(expected.getHits().getHits().length)); for (int i = 0; i < actual.getHits().getHits().length; i++) { assertThat(actual.getHits().getAt(i).getId(), equalTo(expected.getHits().getAt(i).getId())); @@ -236,7 +236,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase { .should(QueryBuilders.termQuery("field3", "value")) ) .get(); - assertThat(actual.getHits().getTotalHits(), equalTo(expected.getHits().getTotalHits())); + assertThat(actual.getHits().getTotalHits().value, equalTo(expected.getHits().getTotalHits().value)); assertThat(actual.getHits().getHits().length, equalTo(expected.getHits().getHits().length)); for (int i = 0; i < actual.getHits().getHits().length; i++) { assertThat(actual.getHits().getAt(i).getId(), equalTo(expected.getHits().getAt(i).getId())); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java index dd41bc5a7fd..54832519d85 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java @@ -551,10 +551,10 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .add(client().prepareSearch("test2").setTypes("type1").setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(1)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(1)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); @@ -566,10 +566,10 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .add(client().prepareSearch("test2").setTypes("type1").setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(1)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(1)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); @@ -581,11 +581,11 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .add(client().prepareSearch("test2").setTypes("type1").setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(2)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(2)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); @@ -598,9 +598,9 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .add(client().prepareSearch("test2").setTypes("type1").setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(0)); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(0)); // user5 has no field level security configured, so all fields are returned @@ -611,12 +611,12 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .add(client().prepareSearch("test2").setTypes("type1").setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(3)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field3"), is("value3")); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(3)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); @@ -630,12 +630,12 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .add(client().prepareSearch("test2").setTypes("type1").setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(3)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field3"), is("value3")); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(3)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); @@ -649,12 +649,12 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .add(client().prepareSearch("test2").setTypes("type1").setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(3)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field3"), is("value3")); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(3)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); @@ -668,11 +668,11 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .add(client().prepareSearch("test2").setTypes("type1").setQuery(QueryBuilders.matchAllQuery())) .get(); assertFalse(response.getResponses()[0].isFailure()); - assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[0].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(2)); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); - assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits(), is(1L)); + assertThat(response.getResponses()[1].getResponse().getHits().getTotalHits().value, is(1L)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().size(), is(2)); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).getSourceAsMap().get("field2"), is("value2")); @@ -704,7 +704,7 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .get(); do { - assertThat(response.getHits().getTotalHits(), is((long) numDocs)); + assertThat(response.getHits().getTotalHits().value, is((long) numDocs)); assertThat(response.getHits().getHits().length, is(1)); assertThat(response.getHits().getAt(0).getSourceAsMap().size(), is(1)); assertThat(response.getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); @@ -1381,7 +1381,7 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .setQuery(hasChildQuery("child", termQuery("field1", "yellow"), ScoreMode.None)) .get(); assertHitCount(searchResponse, 1L); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1")); searchResponse = client() @@ -1398,7 +1398,7 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { .setQuery(hasChildQuery("child", termQuery("alias", "yellow"), ScoreMode.None)) .get(); assertHitCount(searchResponse, 1L); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1")); searchResponse = client() diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java index b5b939e1744..597314b2a61 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java @@ -113,24 +113,24 @@ public class KibanaUserRoleIntegTests extends NativeRealmIntegTestCase { indexRandom(true, client().prepareIndex().setIndex(index).setType(type).setSource(field, "bar")); SearchResponse response = client().prepareSearch(index).setQuery(QueryBuilders.matchAllQuery()).get(); - final long hits = response.getHits().getTotalHits(); + final long hits = response.getHits().getTotalHits().value; assertThat(hits, greaterThan(0L)); response = client() .filterWithHeader(singletonMap("Authorization", UsernamePasswordToken.basicAuthHeaderValue("kibana_user", USERS_PASSWD))) .prepareSearch(index) .setQuery(QueryBuilders.matchAllQuery()).get(); - assertEquals(response.getHits().getTotalHits(), hits); + assertEquals(response.getHits().getTotalHits().value, hits); MultiSearchResponse multiSearchResponse = client().prepareMultiSearch() .add(client().prepareSearch(index).setQuery(QueryBuilders.matchAllQuery())).get(); - final long multiHits = multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits(); + final long multiHits = multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits().value; assertThat(hits, greaterThan(0L)); multiSearchResponse = client() .filterWithHeader(singletonMap("Authorization", UsernamePasswordToken.basicAuthHeaderValue("kibana_user", USERS_PASSWD))) .prepareMultiSearch() .add(client().prepareSearch(index).setQuery(QueryBuilders.matchAllQuery())).get(); - assertEquals(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits(), multiHits); + assertEquals(multiSearchResponse.getResponses()[0].getResponse().getHits().getTotalHits().value, multiHits); } public void testGetIndex() throws Exception { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/ScrollHelperIntegTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/ScrollHelperIntegTests.java index 3d623f343c3..16fd7bbc208 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/ScrollHelperIntegTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/ScrollHelperIntegTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.security; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.search.SearchRequest; @@ -83,7 +84,13 @@ public class ScrollHelperIntegTests extends ESSingleNodeTestCase { String scrollId = randomAlphaOfLength(5); SearchHit[] hits = new SearchHit[] {new SearchHit(1), new SearchHit(2)}; - InternalSearchResponse internalResponse = new InternalSearchResponse(new SearchHits(hits, 3, 1), null, null, null, false, false, 1); + InternalSearchResponse internalResponse = new InternalSearchResponse(new SearchHits(hits, + new TotalHits(3, TotalHits.Relation.EQUAL_TO), 1), + null, + null, + null, false, + false, + 1); SearchResponse response = new SearchResponse(internalResponse, scrollId, 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java index 65d2e5874ab..ba1d1762f06 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.security.action.saml; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionListener; @@ -154,7 +155,7 @@ public class TransportSamlInvalidateSessionActionTests extends SamlTestCase { searchRequests.add(searchRequest); final SearchHit[] hits = searchFunction.apply(searchRequest); final SearchResponse response = new SearchResponse( - new SearchResponseSections(new SearchHits(hits, hits.length, 0f), + new SearchResponseSections(new SearchHits(hits, new TotalHits(hits.length, TotalHits.Relation.EQUAL_TO), 0f), null, null, false, false, null, 1), "_scrollId1", 1, 1, 0, 1, null, null); listener.onResponse((Response) response); } else if (ClearScrollAction.NAME.equals(action.name())) { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java index 25ec38fbefc..9fe510435c5 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java @@ -947,7 +947,7 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { .prepareSearch(indexName) .setTypes(IndexAuditTrail.DOC_TYPE) .get(); - if (searchResponse.getHits().getTotalHits() > 0L) { + if (searchResponse.getHits().getTotalHits().value > 0L) { searchResponseSetOnce.set(searchResponse); return true; } @@ -960,7 +960,7 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { SearchResponse response = searchResponseSetOnce.get(); assertNotNull(response); - assertEquals(1, response.getHits().getTotalHits()); + assertEquals(1, response.getHits().getTotalHits().value); return response.getHits().getHits()[0]; } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/TokenAuthIntegTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/TokenAuthIntegTests.java index 0b000dd07da..c4efdc16e10 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/TokenAuthIntegTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/TokenAuthIntegTests.java @@ -153,7 +153,7 @@ public class TokenAuthIntegTests extends SecurityIntegTestCase { .setSize(1) .setTerminateAfter(1) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); docId.set(searchResponse.getHits().getAt(0).getId()); }); @@ -185,7 +185,7 @@ public class TokenAuthIntegTests extends SecurityIntegTestCase { .setSize(0) .setTerminateAfter(1) .get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); }, 30, TimeUnit.SECONDS); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/esnative/NativeRealmIntegTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/esnative/NativeRealmIntegTests.java index d8d3a3f3ccb..af337cdc718 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/esnative/NativeRealmIntegTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/esnative/NativeRealmIntegTests.java @@ -257,7 +257,7 @@ public class NativeRealmIntegTests extends NativeRealmIntegTestCase { String token = basicAuthHeaderValue("joe", new SecureString("s3krit".toCharArray())); SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get(); - assertEquals(1L, searchResp.getHits().getTotalHits()); + assertEquals(1L, searchResp.getHits().getTotalHits().value); } public void testUpdatingUserAndAuthentication() throws Exception { @@ -278,7 +278,7 @@ public class NativeRealmIntegTests extends NativeRealmIntegTestCase { String token = basicAuthHeaderValue("joe", new SecureString("s3krit".toCharArray())); SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get(); - assertEquals(1L, searchResp.getHits().getTotalHits()); + assertEquals(1L, searchResp.getHits().getTotalHits().value); c.preparePutUser("joe", "s3krit2".toCharArray(), hasher, SecuritySettingsSource.TEST_ROLE).get(); @@ -292,7 +292,7 @@ public class NativeRealmIntegTests extends NativeRealmIntegTestCase { token = basicAuthHeaderValue("joe", new SecureString("s3krit2".toCharArray())); searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get(); - assertEquals(1L, searchResp.getHits().getTotalHits()); + assertEquals(1L, searchResp.getHits().getTotalHits().value); } public void testCreateDeleteAuthenticate() { @@ -314,7 +314,7 @@ public class NativeRealmIntegTests extends NativeRealmIntegTestCase { String token = basicAuthHeaderValue("joe", new SecureString("s3krit".toCharArray())); SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get(); - assertEquals(1L, searchResp.getHits().getTotalHits()); + assertEquals(1L, searchResp.getHits().getTotalHits().value); DeleteUserResponse response = c.prepareDeleteUser("joe").get(); assertThat(response.found(), is(true)); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java index e9ed559ab8e..b50ff864392 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java @@ -212,7 +212,7 @@ public class ReadActionsTests extends SecurityIntegTestCase { assertEquals(2, multiSearchResponse.getResponses().length); assertFalse(multiSearchResponse.getResponses()[0].isFailure()); SearchResponse searchResponse = multiSearchResponse.getResponses()[0].getResponse(); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L)); assertReturnedIndices(searchResponse, "test1", "test2", "test3"); assertTrue(multiSearchResponse.getResponses()[1].isFailure()); Exception exception = multiSearchResponse.getResponses()[1].getFailure(); @@ -227,7 +227,7 @@ public class ReadActionsTests extends SecurityIntegTestCase { assertEquals(2, multiSearchResponse.getResponses().length); assertFalse(multiSearchResponse.getResponses()[0].isFailure()); SearchResponse searchResponse = multiSearchResponse.getResponses()[0].getResponse(); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L)); assertReturnedIndices(searchResponse, "test1", "test2", "test3"); assertFalse(multiSearchResponse.getResponses()[1].isFailure()); assertNoSearchHits(multiSearchResponse.getResponses()[1].getResponse()); @@ -243,7 +243,7 @@ public class ReadActionsTests extends SecurityIntegTestCase { assertEquals(2, multiSearchResponse.getResponses().length); assertFalse(multiSearchResponse.getResponses()[0].isFailure()); SearchResponse searchResponse = multiSearchResponse.getResponses()[0].getResponse(); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L)); assertReturnedIndices(searchResponse, "test1", "test2", "test3"); assertTrue(multiSearchResponse.getResponses()[1].isFailure()); Exception exception = multiSearchResponse.getResponses()[1].getFailure(); @@ -258,7 +258,7 @@ public class ReadActionsTests extends SecurityIntegTestCase { assertEquals(2, multiSearchResponse.getResponses().length); assertFalse(multiSearchResponse.getResponses()[0].isFailure()); SearchResponse searchResponse = multiSearchResponse.getResponses()[0].getResponse(); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L)); assertReturnedIndices(searchResponse, "test1", "test2", "test3"); assertFalse(multiSearchResponse.getResponses()[1].isFailure()); assertNoSearchHits(multiSearchResponse.getResponses()[1].getResponse()); @@ -298,7 +298,7 @@ public class ReadActionsTests extends SecurityIntegTestCase { assertEquals(2, multiSearchResponse.getResponses().length); assertFalse(multiSearchResponse.getResponses()[0].isFailure()); SearchResponse searchResponse = multiSearchResponse.getResponses()[0].getResponse(); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L)); assertReturnedIndices(searchResponse, "test1", "test2", "test3"); assertNoSearchHits(multiSearchResponse.getResponses()[1].getResponse()); } @@ -309,7 +309,7 @@ public class ReadActionsTests extends SecurityIntegTestCase { assertEquals(2, multiSearchResponse.getResponses().length); assertFalse(multiSearchResponse.getResponses()[0].isFailure()); SearchResponse searchResponse = multiSearchResponse.getResponses()[0].getResponse(); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L)); assertReturnedIndices(searchResponse, "test1", "test2", "test3"); assertTrue(multiSearchResponse.getResponses()[1].isFailure()); Exception exception = multiSearchResponse.getResponses()[1].getFailure(); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/SecurityScrollTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/SecurityScrollTests.java index 4466190f83d..276f7a35e14 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/SecurityScrollTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/SecurityScrollTests.java @@ -48,12 +48,12 @@ public class SecurityScrollTests extends SecurityIntegTestCase { .setQuery(matchAllQuery()) .setSize(1) .get(); - assertEquals(numDocs, response.getHits().getTotalHits()); + assertEquals(numDocs, response.getHits().getTotalHits().value); assertEquals(1, response.getHits().getHits().length); if (randomBoolean()) { response = client().prepareSearchScroll(response.getScrollId()).setScroll(TimeValue.timeValueSeconds(5L)).get(); - assertEquals(numDocs, response.getHits().getTotalHits()); + assertEquals(numDocs, response.getHits().getTotalHits().value); assertEquals(1, response.getHits().getHits().length); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/NativePrivilegeStoreTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/NativePrivilegeStoreTests.java index 2c5bd4a321e..c95204ddfdf 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/NativePrivilegeStoreTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/NativePrivilegeStoreTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.security.authz.store; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; @@ -171,7 +172,9 @@ public class NativePrivilegeStoreTests extends ESTestCase { final SearchHit[] hits = buildHits(sourcePrivileges); listener.get().onResponse(new SearchResponse(new SearchResponseSections( - new SearchHits(hits, hits.length, 0f), null, null, false, false, null, 1), "_scrollId1", 1, 1, 0, 1, null, null)); + new SearchHits(hits, new TotalHits(hits.length, TotalHits.Relation.EQUAL_TO), 0f), + null, null, false, false, null, 1), + "_scrollId1", 1, 1, 0, 1, null, null)); assertResult(sourcePrivileges, future); } @@ -196,7 +199,9 @@ public class NativePrivilegeStoreTests extends ESTestCase { final SearchHit[] hits = buildHits(sourcePrivileges); listener.get().onResponse(new SearchResponse(new SearchResponseSections( - new SearchHits(hits, hits.length, 0f), null, null, false, false, null, 1), "_scrollId1", 1, 1, 0, 1, null, null)); + new SearchHits(hits, new TotalHits(hits.length, TotalHits.Relation.EQUAL_TO), 0f), + null, null, false, false, null, 1), + "_scrollId1", 1, 1, 0, 1, null, null)); assertResult(sourcePrivileges, future); } diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/execution/search/Querier.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/execution/search/Querier.java index df6859cc635..8a0163df0bb 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/execution/search/Querier.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/execution/search/Querier.java @@ -253,7 +253,7 @@ public class Querier { List refs = query.columns(); List exts = new ArrayList<>(refs.size()); - ConstantExtractor totalCount = new ConstantExtractor(response.getHits().getTotalHits()); + ConstantExtractor totalCount = new ConstantExtractor(response.getHits().getTotalHits().value); for (FieldExtraction ref : refs) { exts.add(createExtractor(ref, totalCount)); } @@ -324,7 +324,7 @@ public class Querier { if (scrollId != null && // is all the content already retrieved? (Boolean.TRUE.equals(response.isTerminatedEarly()) - || response.getHits().getTotalHits() == hits.length + || response.getHits().getTotalHits().value == hits.length || hitRowSet.isLimitReached())) { // if so, clear the scroll clear(response.getScrollId(), ActionListener.wrap( diff --git a/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java b/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java index 91dc8c85389..df60cc43d77 100644 --- a/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java +++ b/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java @@ -46,6 +46,7 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue; +import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HIT_AS_INT_PARAM; import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -137,6 +138,7 @@ public class XPackRestIT extends ESClientYamlSuiteTestCase { return; } Request searchWatchesRequest = new Request("GET", ".watches/_search"); + searchWatchesRequest.addParameter(TOTAL_HIT_AS_INT_PARAM, "true"); searchWatchesRequest.addParameter("size", "1000"); Response response = adminClient().performRequest(searchWatchesRequest); ObjectPath objectPathResponse = ObjectPath.createFromResponse(response); @@ -179,7 +181,10 @@ public class XPackRestIT extends ESClientYamlSuiteTestCase { return acknowledged != null && (Boolean) acknowledged; }, () -> "Exception when enabling monitoring"); - awaitCallApi("search", singletonMap("index", ".monitoring-*"), emptyList(), + Map searchParams = new HashMap<>(); + searchParams.put("index", ".monitoring-*"); + searchParams.put(TOTAL_HIT_AS_INT_PARAM, "true"); + awaitCallApi("search", searchParams, emptyList(), response -> ((Number) response.evaluate("hits.total")).intValue() > 0, () -> "Exception when waiting for monitoring documents to be indexed"); } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.rollup.rollup_search.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.rollup.rollup_search.json index bc535784fc4..3b00c519d7b 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.rollup.rollup_search.json +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.rollup.rollup_search.json @@ -16,6 +16,13 @@ "required": false, "description": "The doc type inside the index" } + }, + "params": { + "rest_total_hits_as_int" : { + "type" : "boolean", + "description" : "Indicates whether hits.total should be rendered as an integer or an object in the rest search response", + "default" : false + } } }, "body": { diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/authenticate/10_field_level_security.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/authenticate/10_field_level_security.yml index acb2daf3ae9..22981698d29 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/authenticate/10_field_level_security.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/authenticate/10_field_level_security.yml @@ -108,6 +108,7 @@ teardown: - do: headers: { Authorization: "Basic ZnVsbDp4LXBhY2stdGVzdC1wYXNzd29yZA==" } # full - user search: + rest_total_hits_as_int: true index: the_alias size: 0 from: 0 @@ -128,6 +129,7 @@ teardown: - do: headers: { Authorization: "Basic bGltaXRlZDp4LXBhY2stdGVzdC1wYXNzd29yZA==" } # limited - user search: + rest_total_hits_as_int: true index: the_alias size: 0 from: 0 @@ -146,6 +148,7 @@ teardown: - do: headers: { Authorization: "Basic bGltaXRlZDp4LXBhY2stdGVzdC1wYXNzd29yZA==" } # limited - user search: + rest_total_hits_as_int: true index: the_* size: 0 from: 0 @@ -164,6 +167,7 @@ teardown: - do: headers: { Authorization: "Basic bGltaXRlZDp4LXBhY2stdGVzdC1wYXNzd29yZA==" } # limited - user search: + rest_total_hits_as_int: true index: test_* size: 0 from: 0 diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/indices.freeze/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/indices.freeze/10_basic.yml index 8f79225ddc3..16a0aace0e4 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/indices.freeze/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/indices.freeze/10_basic.yml @@ -22,6 +22,7 @@ - do: search: + rest_total_hits_as_int: true index: test ignore_throttled: false body: @@ -38,6 +39,7 @@ - do: search: + rest_total_hits_as_int: true index: _all body: query: @@ -59,6 +61,7 @@ - do: search: + rest_total_hits_as_int: true index: _all ignore_throttled: false body: @@ -70,6 +73,7 @@ - do: search: + rest_total_hits_as_int: true index: _all body: query: @@ -108,6 +112,7 @@ - do: search: + rest_total_hits_as_int: true index: _all body: query: @@ -118,6 +123,7 @@ - do: search: + rest_total_hits_as_int: true index: _all ignore_throttled: false body: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/custom_all_field.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/custom_all_field.yml index 0497f15f757..435d890e7be 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/custom_all_field.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/custom_all_field.yml @@ -84,54 +84,63 @@ setup: - do: search: + rest_total_hits_as_int: true index: .ml-anomalies-custom-all-test-1 body: { query: { query_string: { query: "A by field" } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: .ml-anomalies-custom-all-test-1 body: { query: { query_string: { query: "A partition field" } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: .ml-anomalies-custom-all-test-1 body: { query: { query_string: { query: "An over field" } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: .ml-anomalies-custom-all-test-1 body: { query: { query_string: { query: "An influencer field" } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: .ml-anomalies-custom-all-test-1 body: { query: { query_string: { query: "Cause by field" } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: .ml-anomalies-custom-all-test-1 body: { query: { query_string: { query: "Cause partition field" } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: .ml-anomalies-custom-all-test-1 body: { query: { query_string: { query: "Cause over field" } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: .ml-anomalies-custom-all-test-1 body: { query: { query_string: { query: "Cause correlated by field" } } } - match: { hits.total: 1 } - do: search: + rest_total_hits_as_int: true index: .ml-anomalies-custom-all-test-1 body: { query: { query_string: { query: "custom-all-test-1" } } } - match: { hits.total: 1 } @@ -141,6 +150,7 @@ setup: - do: search: + rest_total_hits_as_int: true body: { query: { bool: { must: [ { query_string: { query: "result_type:record"} }, { query_string: { query: "A by field" } }, diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/monitoring/bulk/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/monitoring/bulk/10_basic.yml index 37d2e5feda3..0c201aa6ef5 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/monitoring/bulk/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/monitoring/bulk/10_basic.yml @@ -31,6 +31,7 @@ - do: search: + rest_total_hits_as_int: true index: .monitoring-kibana-* body: { "query": { "term" : { "type": "test_type" } } } @@ -59,6 +60,7 @@ - do: search: + rest_total_hits_as_int: true index: .monitoring-kibana-* body: { "query": { "term" : { "type": "default_type" } } } @@ -68,6 +70,7 @@ - do: search: + rest_total_hits_as_int: true index: .monitoring-kibana-* body: { "query": { "term" : { "type": "custom_type" } } } @@ -77,6 +80,7 @@ # We actively ignore indexing requests made to the _data index starting with 5.5 - do: search: + rest_total_hits_as_int: true index: .monitoring-data-* - match: { hits.total: 0 } @@ -105,6 +109,7 @@ - do: search: + rest_total_hits_as_int: true index: .monitoring-kibana-* body: { "query": { "term" : { "type": "default_type" } } } @@ -112,6 +117,7 @@ - do: search: + rest_total_hits_as_int: true index: .monitoring-kibana-* body: { "query": { "term" : { "type": "custom_type" } } } @@ -120,6 +126,7 @@ # We actively ignore indexing requests made to the _data index starting with 5.5, even for the old versions - do: search: + rest_total_hits_as_int: true index: .monitoring-data-* - match: { hits.total: 0 } @@ -184,6 +191,7 @@ - do: search: + rest_total_hits_as_int: true index: .monitoring-beats-* - match: { hits.total: 2 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/monitoring/bulk/20_privileges.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/monitoring/bulk/20_privileges.yml index 07cd7d25936..128f30f2147 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/monitoring/bulk/20_privileges.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/monitoring/bulk/20_privileges.yml @@ -103,6 +103,7 @@ teardown: - do: search: + rest_total_hits_as_int: true index: .monitoring-logstash-* body: { "query": { "term" : { "type": "logstash_metric" } } } - match: { hits.total: 1 } @@ -110,6 +111,7 @@ teardown: # We actively ignore indexing requests made to .monitoring-data-N starting with 5.5 - do: search: + rest_total_hits_as_int: true index: .monitoring-data-* - match: { hits.total: 0 } @@ -135,6 +137,7 @@ teardown: - do: search: + rest_total_hits_as_int: true index: .monitoring-logstash-* body: { "query": { "term" : { "type": "logstash_metric" } } } - match: { hits.total: 1 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/roles/30_prohibited_role_query.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/roles/30_prohibited_role_query.yml index fd90474a1fb..ea6bc86a7e3 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/roles/30_prohibited_role_query.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/roles/30_prohibited_role_query.yml @@ -66,6 +66,7 @@ teardown: headers: Authorization: "Basic am9lOngtcGFjay10ZXN0LXBhc3N3b3Jk" search: + rest_total_hits_as_int: true index: index body: { "query" : { "match_all" : {} } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/rollup_search.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/rollup_search.yml index 3399376b6ab..2876b6398ae 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/rollup_search.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/rollup_search.yml @@ -154,33 +154,6 @@ setup: - match: { aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z" } - match: { aggregations.histo.buckets.3.doc_count: 20 } ---- -"Basic Search with rest_total_hits_as_int": - - skip: - version: " - 6.5.99" - reason: rest_total_hits_as_int was introduced in 6.6.0 - - do: - xpack.rollup.rollup_search: - index: "foo_rollup" - body: - size: 0 - aggs: - histo: - date_histogram: - field: "timestamp" - interval: "1h" - time_zone: "UTC" - - - length: { aggregations.histo.buckets: 4 } - - match: { aggregations.histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z" } - - match: { aggregations.histo.buckets.0.doc_count: 1 } - - match: { aggregations.histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z" } - - match: { aggregations.histo.buckets.1.doc_count: 2 } - - match: { aggregations.histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z" } - - match: { aggregations.histo.buckets.2.doc_count: 10 } - - match: { aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z" } - - match: { aggregations.histo.buckets.3.doc_count: 20 } - --- "Formatted Date Histo": @@ -212,6 +185,7 @@ setup: - do: xpack.rollup.rollup_search: + rest_total_hits_as_int: true index: "foo_rollup" body: size: 0 @@ -221,6 +195,22 @@ setup: - match: { hits.total: 0 } - is_false: aggregations +--- +"Empty aggregation with new response format": + + - do: + xpack.rollup.rollup_search: + index: "foo_rollup" + body: + size: 0 + aggs: {} + + - length: { hits.hits: 0 } + - match: { hits.total.value: 0 } + - match: { hits.total.relation: eq } + - is_false: aggregations + + --- "Search with Metric": diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/security_tests.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/security_tests.yml index 3db0fa34ae2..a6708dfa287 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/security_tests.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/security_tests.yml @@ -147,6 +147,7 @@ teardown: - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: foo body: query: @@ -158,6 +159,7 @@ teardown: - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: rollup body: query: @@ -308,6 +310,7 @@ teardown: - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: foo body: query: @@ -319,6 +322,7 @@ teardown: - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: rollup body: query: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/10_index_doc.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/10_index_doc.yml index b5132fc75e0..d68493bdcdd 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/10_index_doc.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/10_index_doc.yml @@ -149,12 +149,14 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: only_index - match: { hits.total: 3 } - do: # superuser search: + rest_total_hits_as_int: true index: everything - match: { hits.total: 3 } @@ -226,11 +228,13 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: only_read - match: { hits.total: 0 } - do: # superuser search: + rest_total_hits_as_int: true index: only_delete - match: { hits.total: 0 } @@ -252,6 +256,7 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: only_index body: { "query": { "term": { "_id": "14" } } } - match: { hits.total: 1 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/11_delete_doc.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/11_delete_doc.yml index 3fd523ac495..defff96601b 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/11_delete_doc.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/11_delete_doc.yml @@ -127,12 +127,14 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: only_delete body: { "query": { "terms": { "_id": [ "3", "4", "5" ] } } } - match: { hits.total: 3 } - do: # superuser search: + rest_total_hits_as_int: true index: everything body: { "query": { "terms": { "_id": [ "8", "9", "10" ] } } } - match: { hits.total: 3 } @@ -185,12 +187,14 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: only_delete body: { "query": { "terms": { "_id": [ "3", "4", "5" ] } } } - match: { hits.total: 0 } - do: # superuser search: + rest_total_hits_as_int: true index: everything body: { "query": { "terms": { "_id": [ "8", "9", "10" ] } } } - match: { hits.total: 0 } @@ -259,12 +263,14 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: only_read - match: { hits.total: 1 } - do: # superuser search: + rest_total_hits_as_int: true index: only_index - match: { hits.total: 1 } @@ -285,12 +291,14 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: only_read body: { "query": { "term": { "_id": "1" } } } - match: { hits.total: 1 } - do: # superuser search: + rest_total_hits_as_int: true index: only_delete body: { "query": { "term": { "_id": "6" } } } - match: { hits.total: 0 } @@ -318,6 +326,7 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: only_delete body: { "query": { "terms": { "_id": [ "11", "7" ] } } } # 11 wasn't created, 7 was deleted @@ -325,6 +334,7 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: only_index body: { "query": { "terms": { "_id": [ "12", "2" ] } } } # 12 was created, 2 wasn't deleted diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/12_index_alias.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/12_index_alias.yml index 1e947c5639d..a2e392d9053 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/12_index_alias.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/12_index_alias.yml @@ -183,11 +183,13 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: write_index_1 - match: { hits.total: 8 } - do: # superuser search: + rest_total_hits_as_int: true index: write_index_2 - match: { hits.total: 1 } @@ -251,6 +253,7 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: read_index - match: { hits.total: 0 } @@ -272,6 +275,7 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: write_index_1 body: { "query": { "term": { "_id": "14" } } } - match: { hits.total: 1 } @@ -302,11 +306,13 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: write_index_1 body: { "query": { "terms": { "_id": [ "16", "18" ] } } } - match: { hits.total: 2 } - do: # superuser search: + rest_total_hits_as_int: true index: write_index_2 body: { "query": { "terms": { "_id": [ "19" ] } } } - match: { hits.total: 1 } @@ -366,6 +372,7 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: write_index_1 body: { "query": { "terms": { "_id": [ "21" ] } } } - match: { hits.total: 1 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/13_index_datemath.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/13_index_datemath.yml index 7f3a20a6074..5d714415d2a 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/13_index_datemath.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/13_index_datemath.yml @@ -72,6 +72,7 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: "write-*" - match: { hits.total: 3 } @@ -109,6 +110,7 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: "read-*" - match: { hits.total: 0 } @@ -133,6 +135,7 @@ teardown: - do: # superuser search: + rest_total_hits_as_int: true index: write-* body: { "query": { "term": { "_id": "8" } } } - match: { hits.total: 1 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/21_search_doc.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/21_search_doc.yml index b26b797bd29..5d7a531a1d9 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/21_search_doc.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/authz/21_search_doc.yml @@ -149,6 +149,7 @@ teardown: - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: only_read body: - match: { hits.total: 2 } @@ -158,6 +159,7 @@ teardown: - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: read_write body: - match: { hits.total: 2 } @@ -167,6 +169,7 @@ teardown: - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: everything body: - match: { hits.total: 2 } @@ -176,12 +179,14 @@ teardown: - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true body: { "query": { "term": { "tag": "can-read" } } } - match: { hits.total: 6 } - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user msearch: + rest_total_hits_as_int: true body: - { } - { "query": { "term": { "tag": "can-read" } } } @@ -200,6 +205,7 @@ teardown: catch: forbidden headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: only_index body: @@ -207,24 +213,28 @@ teardown: catch: forbidden headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: only_delete body: - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true body: { "query": { "term": { "tag": "no-read" } } } - match: { hits.total: 0 } - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true body: { "query": { "term": { "_index": "only_index" } } } - match: { hits.total: 0 } - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user msearch: + rest_total_hits_as_int: true body: - { } - { "query": { "term": { "tag": "no-read" } } } @@ -242,12 +252,14 @@ teardown: - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true body: { "query": { "term": { "tag": "tag-a" } } } - match: { hits.total: 3 } # can-read, read_write, everything - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user msearch: + rest_total_hits_as_int: true body: - { } - { "query": { "term": { "tag": "tag-a" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/hidden-index/10_security_read.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/hidden-index/10_security_read.yml index dd81f4dc35f..6701669a379 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/hidden-index/10_security_read.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/hidden-index/10_security_read.yml @@ -73,11 +73,13 @@ teardown: catch: forbidden headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: ".security" - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: ".secu*rity" - match: { hits.total: 0 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/hidden-index/11_security-6_read.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/hidden-index/11_security-6_read.yml index 8d88211d2a1..d9f0fff8e11 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/security/hidden-index/11_security-6_read.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/security/hidden-index/11_security-6_read.yml @@ -73,11 +73,13 @@ teardown: catch: forbidden headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: ".security-6" - do: headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user search: + rest_total_hits_as_int: true index: ".security*6" - match: { hits.total: 0 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/set_security_user/10_small_users_one_index.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/set_security_user/10_small_users_one_index.yml index 24ea7c03c80..2e7617b9b8e 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/set_security_user/10_small_users_one_index.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/set_security_user/10_small_users_one_index.yml @@ -125,6 +125,7 @@ teardown: headers: Authorization: "Basic am9lOngtcGFjay10ZXN0LXBhc3N3b3Jk" search: + rest_total_hits_as_int: true index: shared_logs body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} @@ -136,6 +137,7 @@ teardown: headers: Authorization: "Basic am9objp4LXBhY2stdGVzdC1wYXNzd29yZA==" search: + rest_total_hits_as_int: true index: shared_logs body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/snapshot/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/snapshot/10_basic.yml index c0f161472b7..fd0aee19cfb 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/snapshot/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/snapshot/10_basic.yml @@ -74,6 +74,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: test_index body: query: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/10_basic.yml index f74fd7a9a65..385f2e9da65 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/10_basic.yml @@ -46,6 +46,7 @@ - do: search: + rest_total_hits_as_int: true index: .watches body: { "query": { "term": { "_id": "my_watch" } } } - match: { hits.total: 1 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/activate_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/activate_watch/10_basic.yml index b71486295d1..221887494c5 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/activate_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/activate_watch/10_basic.yml @@ -50,6 +50,7 @@ - do: search: + rest_total_hits_as_int: true index: .watches body: { "query": { "term": { "_id": "my_watch" } } } - match: { hits.total: 1 } @@ -70,6 +71,7 @@ - do: search: + rest_total_hits_as_int: true index: .watches body: { "query": { "term": { "_id": "my_watch" } } } - match: { hits.total: 1 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/delete_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/delete_watch/10_basic.yml index ede88d2ae16..44d4e187e3f 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/delete_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/delete_watch/10_basic.yml @@ -54,6 +54,7 @@ teardown: - do: search: + rest_total_hits_as_int: true index: .watches body: { "query": { "term": { "_id": "my_watch" } } } - match: { hits.total: 0 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yml index 9ae698ced70..b3ad1e6d545 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yml @@ -160,5 +160,6 @@ teardown: - do: search: + rest_total_hits_as_int: true index: my_test_index - match: { hits.total : 1 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/10_basic.yml index 74f6ce6520f..180b72f2ba4 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/10_basic.yml @@ -49,6 +49,7 @@ teardown: - do: search: + rest_total_hits_as_int: true index: .watches body: { "query": { "term": { "_id": "my_watch" } } } - match: { hits.total: 1 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/80_put_get_watch_with_passwords.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/80_put_get_watch_with_passwords.yml index db1fa843704..03bc40c9372 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/80_put_get_watch_with_passwords.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/80_put_get_watch_with_passwords.yml @@ -299,6 +299,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: .watches body: > { diff --git a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java index d5e2fe9b74b..3663d586159 100644 --- a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java +++ b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java @@ -76,7 +76,7 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase { assertThat(ex.getMessage(), equalTo("Index [" + testIndex + "] cannot be upgraded")); SearchResponse searchResponse = client().prepareSearch(testIndex).get(); - assertEquals(2L, searchResponse.getHits().getTotalHits()); + assertEquals(2L, searchResponse.getHits().getTotalHits().value); } public void testInternalUpgradePrePostChecks() throws Exception { @@ -123,7 +123,7 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase { assertThat(response.getCreated(), equalTo(2L)); SearchResponse searchResponse = client().prepareSearch(testIndex).get(); - assertEquals(2L, searchResponse.getHits().getTotalHits()); + assertEquals(2L, searchResponse.getHits().getTotalHits().value); assertTrue(preUpgradeIsCalled.get()); assertTrue(postUpgradeIsCalled.get()); diff --git a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/InternalIndexReindexerIT.java b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/InternalIndexReindexerIT.java index 71e3348b058..013680ee2d1 100644 --- a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/InternalIndexReindexerIT.java +++ b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/InternalIndexReindexerIT.java @@ -84,7 +84,7 @@ public class InternalIndexReindexerIT extends IndexUpgradeIntegTestCase { assertThat(response.getCreated(), equalTo(2L)); SearchResponse searchResponse = client().prepareSearch("test-123").get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(searchResponse.getHits().getHits().length, equalTo(2)); for (SearchHit hit : searchResponse.getHits().getHits()) { assertThat(hit.getId(), startsWith("bar-")); diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherService.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherService.java index f088633887c..796d06b0b81 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherService.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherService.java @@ -305,7 +305,7 @@ public class WatcherService { throw new ElasticsearchException("Partial response while loading watches"); } - if (response.getHits().getTotalHits() == 0) { + if (response.getHits().getTotalHits().value == 0) { return Collections.emptyList(); } diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/execution/TriggeredWatchStore.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/execution/TriggeredWatchStore.java index b613cfd6d18..c5ca671e13e 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/execution/TriggeredWatchStore.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/execution/TriggeredWatchStore.java @@ -160,7 +160,7 @@ public class TriggeredWatchStore { SearchResponse response = null; try { response = client.search(searchRequest).actionGet(defaultSearchTimeout); - logger.debug("trying to find triggered watches for ids {}: found [{}] docs", ids, response.getHits().getTotalHits()); + logger.debug("trying to find triggered watches for ids {}: found [{}] docs", ids, response.getHits().getTotalHits().value); while (response.getHits().getHits().length != 0) { for (SearchHit hit : response.getHits()) { Wid wid = new Wid(hit.getId()); diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/search/ExecutableSearchInput.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/search/ExecutableSearchInput.java index 50b33d5247b..c99452a3987 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/search/ExecutableSearchInput.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/search/ExecutableSearchInput.java @@ -80,29 +80,29 @@ public class ExecutableSearchInput extends ExecutableInput client.search(searchRequest).actionGet(timeout)); if (logger.isDebugEnabled()) { - logger.debug("[{}] found [{}] hits", ctx.id(), response.getHits().getTotalHits()); + logger.debug("[{}] found [{}] hits", ctx.id(), response.getHits().getTotalHits().value); for (SearchHit hit : response.getHits()) { logger.debug("[{}] hit [{}]", ctx.id(), hit.getSourceAsMap()); } } final Payload payload; + final Params params; + if (request.isRestTotalHitsAsint()) { + params = new MapParams(Collections.singletonMap("rest_total_hits_as_int", "true")); + } else { + params = EMPTY_PARAMS; + } if (input.getExtractKeys() != null) { - Params params; - if (request.isRestTotalHitsAsint()) { - params = new MapParams(Collections.singletonMap("rest_total_hits_a_int", "true")); - } else { - params = EMPTY_PARAMS; - } BytesReference bytes = XContentHelper.toXContent(response, XContentType.JSON, params, false); // EMPTY is safe here because we never use namedObject try (XContentParser parser = XContentHelper - .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, bytes)) { + .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, bytes, XContentType.JSON)) { Map filteredKeys = XContentFilterKeysUtils.filterMapOrdered(input.getExtractKeys(), parser); payload = new Payload.Simple(filteredKeys); } } else { - payload = new Payload.XContent(response); + payload = new Payload.XContent(response, params); } return new SearchInput.Result(request, payload); diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java index 6741f870167..8619143c83d 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java @@ -116,7 +116,7 @@ public class WatcherSearchTemplateRequest implements ToXContentObject { * Defaults to false. */ public void setRestTotalHitsAsInt(boolean value) { - this.restTotalHitsAsInt = restTotalHitsAsInt; + this.restTotalHitsAsInt = value; } public BytesReference getSearchSource() { diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/search/ExecutableSearchTransform.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/search/ExecutableSearchTransform.java index 1b408bc5e64..ed712f52b3b 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/search/ExecutableSearchTransform.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/search/ExecutableSearchTransform.java @@ -22,6 +22,8 @@ import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest; import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateService; +import java.util.Collections; + import static org.elasticsearch.xpack.watcher.transform.search.SearchTransform.TYPE; public class ExecutableSearchTransform extends ExecutableTransform { @@ -51,7 +53,13 @@ public class ExecutableSearchTransform extends ExecutableTransform client.search(searchRequest).actionGet(timeout)); - return new SearchTransform.Result(request, new Payload.XContent(resp)); + final Params params; + if (request.isRestTotalHitsAsint()) { + params = new MapParams(Collections.singletonMap("rest_total_hits_as_int", "true")); + } else { + params = EMPTY_PARAMS; + } + return new SearchTransform.Result(request, new Payload.XContent(resp, params)); } catch (Exception e) { logger.error((Supplier) () -> new ParameterizedMessage("failed to execute [{}] transform for [{}]", TYPE, ctx.id()), e); return new SearchTransform.Result(request, e); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherServiceTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherServiceTests.java index 0f670ea4cde..03751637a79 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherServiceTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherServiceTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.watcher; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.refresh.RefreshAction; @@ -194,7 +195,7 @@ public class WatcherServiceTests extends ESTestCase { when(watch.status()).thenReturn(watchStatus); when(parser.parse(eq(id), eq(true), any(), eq(XContentType.JSON))).thenReturn(watch); } - SearchHits searchHits = new SearchHits(hits, count, 1.0f); + SearchHits searchHits = new SearchHits(hits, new TotalHits(count, TotalHits.Relation.EQUAL_TO), 1.0f); SearchResponseSections sections = new SearchResponseSections(searchHits, null, null, false, false, null, 1); SearchResponse searchResponse = new SearchResponse(sections, "scrollId", 1, 1, 0, 10, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionSearchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionSearchTests.java index b8931013ded..92e49136220 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionSearchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionSearchTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.watcher.condition; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.xpack.core.watcher.condition.Condition; @@ -52,7 +53,7 @@ public class ArrayCompareConditionSearchTests extends AbstractWatcherIntegration ArrayCompareCondition condition = new ArrayCompareCondition("ctx.payload.aggregations.top_tweeters.buckets" , "doc_count", op, numberOfDocumentsWatchingFor, quantifier, Clock.systemUTC()); - WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response)); + WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response, ToXContent.EMPTY_PARAMS)); Condition.Result result = condition.execute(ctx); boolean met = quantifier.eval(Arrays.asList(numberOfDocuments, numberOfDocuments), numberOfDocumentsWatchingFor, op); @@ -76,7 +77,7 @@ public class ArrayCompareConditionSearchTests extends AbstractWatcherIntegration response = client().prepareSearch(index) .addAggregation(AggregationBuilders.terms("top_tweeters").field("user.screen_name.keyword").size(3)).get(); - ctx = mockExecutionContext("_name", new Payload.XContent(response)); + ctx = mockExecutionContext("_name", new Payload.XContent(response, ToXContent.EMPTY_PARAMS)); result = condition.execute(ctx); met = quantifier.eval(Arrays.asList(numberOfDocumentsWatchingFor, numberOfDocuments), numberOfDocumentsWatchingFor, op); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/CompareConditionSearchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/CompareConditionSearchTests.java index 0cfc2575386..5c525e10a19 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/CompareConditionSearchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/CompareConditionSearchTests.java @@ -5,9 +5,11 @@ */ package org.elasticsearch.xpack.watcher.condition; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.common.text.Text; +import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.index.Index; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; @@ -45,7 +47,7 @@ public class CompareConditionSearchTests extends AbstractWatcherIntegrationTestC CompareCondition condition = new CompareCondition("ctx.payload.aggregations.rate.buckets.0.doc_count", CompareCondition.Op.GTE, 5, Clock.systemUTC()); - WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response)); + WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response, ToXContent.EMPTY_PARAMS)); CompareCondition.Result result = condition.execute(ctx); assertThat(result.met(), is(false)); Map resolvedValues = result.getResolvedValues(); @@ -61,7 +63,7 @@ public class CompareConditionSearchTests extends AbstractWatcherIntegrationTestC .field("@timestamp").dateHistogramInterval(DateHistogramInterval.HOUR).order(BucketOrder.count(false))) .get(); - ctx = mockExecutionContext("_name", new Payload.XContent(response)); + ctx = mockExecutionContext("_name", new Payload.XContent(response, ToXContent.EMPTY_PARAMS)); result = condition.execute(ctx); assertThat(result.met(), is(true)); resolvedValues = result.getResolvedValues(); @@ -78,14 +80,15 @@ public class CompareConditionSearchTests extends AbstractWatcherIntegrationTestC hit.shard(new SearchShardTarget("a", new Index("a", "indexUUID"), 0, null)); InternalSearchResponse internalSearchResponse = new InternalSearchResponse( - new SearchHits(new SearchHit[]{hit}, 1L, 1f), null, null, null, false, false, 1); - SearchResponse response = new SearchResponse(internalSearchResponse, "", 3, 3, 0, 500L, ShardSearchFailure.EMPTY_ARRAY, - SearchResponse.Clusters.EMPTY); + new SearchHits(new SearchHit[]{hit}, new TotalHits(1L, TotalHits.Relation.EQUAL_TO), 1f), + null, null, null, false, false, 1); + SearchResponse response = new SearchResponse(internalSearchResponse, "", 3, 3, 0, + 500L, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY); - WatchExecutionContext ctx = mockExecutionContext("_watch_name", new Payload.XContent(response)); + WatchExecutionContext ctx = mockExecutionContext("_watch_name", new Payload.XContent(response, ToXContent.EMPTY_PARAMS)); assertThat(condition.execute(ctx).met(), is(true)); hit.score(2f); - when(ctx.payload()).thenReturn(new Payload.XContent(response)); + when(ctx.payload()).thenReturn(new Payload.XContent(response, ToXContent.EMPTY_PARAMS)); CompareCondition.Result result = condition.execute(ctx); assertThat(result.met(), is(false)); Map resolvedValues = result.getResolvedValues(); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java index fc6161cb927..4a6487e3f73 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java @@ -13,6 +13,8 @@ import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -74,13 +76,13 @@ public class ScriptConditionTests extends ESTestCase { "null.foo", AbstractWatcherIntegrationTestCase.WATCHER_LANG); }); - scripts.put("ctx.payload.hits.total > 1", vars -> { - int total = (int) XContentMapValues.extractValue("ctx.payload.hits.total", vars); + scripts.put("ctx.payload.hits.total.value > 1", vars -> { + int total = (int) XContentMapValues.extractValue("ctx.payload.hits.total.value", vars); return total > 1; }); - scripts.put("ctx.payload.hits.total > params.threshold", vars -> { - int total = (int) XContentMapValues.extractValue("ctx.payload.hits.total", vars); + scripts.put("ctx.payload.hits.total.value > params.threshold", vars -> { + int total = (int) XContentMapValues.extractValue("ctx.payload.hits.total.value", vars); int threshold = (int) XContentMapValues.extractValue("params.threshold", vars); return total > threshold; }); @@ -94,26 +96,26 @@ public class ScriptConditionTests extends ESTestCase { } public void testExecute() throws Exception { - ScriptCondition condition = new ScriptCondition(mockScript("ctx.payload.hits.total > 1"), scriptService); + ScriptCondition condition = new ScriptCondition(mockScript("ctx.payload.hits.total.value > 1"), scriptService); SearchResponse response = new SearchResponse(InternalSearchResponse.empty(), "", 3, 3, 0, 500L, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY); - WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response)); + WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response, Settings.EMPTY_PARAMS)); assertFalse(condition.execute(ctx).met()); } public void testExecuteMergedParams() throws Exception { Script script = new Script(ScriptType.INLINE, "mockscript", - "ctx.payload.hits.total > params.threshold", singletonMap("threshold", 1)); + "ctx.payload.hits.total.value > params.threshold", singletonMap("threshold", 1)); ScriptCondition executable = new ScriptCondition(script, scriptService); SearchResponse response = new SearchResponse(InternalSearchResponse.empty(), "", 3, 3, 0, 500L, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY); - WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response)); + WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response, Settings.EMPTY_PARAMS)); assertFalse(executable.execute(ctx).met()); } public void testParserValid() throws Exception { - XContentBuilder builder = createConditionContent("ctx.payload.hits.total > 1", "mockscript", ScriptType.INLINE); + XContentBuilder builder = createConditionContent("ctx.payload.hits.total.value > 1", "mockscript", ScriptType.INLINE); XContentParser parser = createParser(builder); parser.nextToken(); @@ -121,7 +123,7 @@ public class ScriptConditionTests extends ESTestCase { SearchResponse response = new SearchResponse(InternalSearchResponse.empty(), "", 3, 3, 0, 500L, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY); - WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response)); + WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response, Settings.EMPTY_PARAMS)); assertFalse(executable.execute(ctx).met()); @@ -131,7 +133,7 @@ public class ScriptConditionTests extends ESTestCase { parser.nextToken(); executable = ScriptCondition.parse(scriptService, "_watch", parser); - ctx = mockExecutionContext("_name", new Payload.XContent(response)); + ctx = mockExecutionContext("_name", new Payload.XContent(response, Settings.EMPTY_PARAMS)); assertTrue(executable.execute(ctx).met()); } @@ -186,7 +188,7 @@ public class ScriptConditionTests extends ESTestCase { mockScript("null.foo"), scriptService); SearchResponse response = new SearchResponse(InternalSearchResponse.empty(), "", 3, 3, 0, 500L, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY); - WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response)); + WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response, ToXContent.EMPTY_PARAMS)); ScriptException exception = expectThrows(ScriptException.class, () -> condition.execute(ctx)); assertThat(exception.getMessage(), containsString("Error evaluating null.foo")); } @@ -196,7 +198,8 @@ public class ScriptConditionTests extends ESTestCase { scriptService); SearchResponse response = new SearchResponse(InternalSearchResponse.empty(), "", 3, 3, 0, 500L, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY); - WatchExecutionContext ctx = mockExecutionContext("_name", new DateTime(DateTimeZone.UTC), new Payload.XContent(response)); + WatchExecutionContext ctx = mockExecutionContext("_name", new DateTime(DateTimeZone.UTC), + new Payload.XContent(response, ToXContent.EMPTY_PARAMS)); Thread.sleep(10); assertThat(condition.execute(ctx).met(), is(true)); } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/TriggeredWatchStoreTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/TriggeredWatchStoreTests.java index 428ec96df97..11656d838a0 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/TriggeredWatchStoreTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/TriggeredWatchStoreTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.watcher.execution; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; @@ -217,7 +218,7 @@ public class TriggeredWatchStoreTests extends ESTestCase { hit.version(1L); hit.shard(new SearchShardTarget("_node_id", index, 0, null)); hit.sourceRef(source); - SearchHits hits = new SearchHits(new SearchHit[]{hit}, 1, 1.0f); + SearchHits hits = new SearchHits(new SearchHit[]{hit}, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0f); when(searchResponse1.getHits()).thenReturn(hits); when(searchResponse1.getScrollId()).thenReturn("_scrollId"); doAnswer(invocation -> { @@ -231,7 +232,7 @@ public class TriggeredWatchStoreTests extends ESTestCase { hit.version(1L); hit.shard(new SearchShardTarget("_node_id", index, 0, null)); hit.sourceRef(source); - hits = new SearchHits(new SearchHit[]{hit}, 1, 1.0f); + hits = new SearchHits(new SearchHit[]{hit}, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0f); SearchResponse searchResponse2 = new SearchResponse( new InternalSearchResponse(hits, null, null, null, false, null, 1), "_scrollId1", 1, 1, 0, 1, null, null); SearchResponse searchResponse3 = new SearchResponse(InternalSearchResponse.empty(), "_scrollId2", 1, 1, 0, 1, null, null); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryActionConditionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryActionConditionTests.java index 78fc9c290ed..15a74537f70 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryActionConditionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryActionConditionTests.java @@ -107,7 +107,7 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC // only one action should have failed via condition final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id))); - assertThat(response.getHits().getTotalHits(), is(1L)); + assertThat(response.getHits().getTotalHits().value, is(1L)); final SearchHit hit = response.getHits().getAt(0); final List actions = getActionsFromHit(hit.getSourceAsMap()); @@ -152,7 +152,7 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC // only one action should have failed via condition final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id))); - assertThat(response.getHits().getTotalHits(), is(1L)); + assertThat(response.getHits().getTotalHits().value, is(1L)); final SearchHit hit = response.getHits().getAt(0); final List actions = getActionsFromHit(hit.getSourceAsMap()); @@ -202,7 +202,7 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC // all actions should be successful final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id))); - assertThat(response.getHits().getTotalHits(), is(1L)); + assertThat(response.getHits().getTotalHits().value, is(1L)); final SearchHit hit = response.getHits().getAt(0); final List actions = getActionsFromHit(hit.getSourceAsMap()); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java index 2f578a1b880..c9d642b8dc0 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java @@ -97,7 +97,7 @@ public class HistoryTemplateEmailMappingsTests extends AbstractWatcherIntegratio .get(); assertThat(response, notNullValue()); - assertThat(response.getHits().getTotalHits(), is(1L)); + assertThat(response.getHits().getTotalHits().value, is(1L)); Aggregations aggs = response.getAggregations(); assertThat(aggs, notNullValue()); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java index a93b1e94ce9..9d2b767891a 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java @@ -94,7 +94,7 @@ public class HistoryTemplateHttpMappingsTests extends AbstractWatcherIntegration .get(); assertThat(response, notNullValue()); - assertThat(response.getHits().getTotalHits(), is(1L)); + assertThat(response.getHits().getTotalHits().value, is(1L)); Aggregations aggs = response.getAggregations(); assertThat(aggs, notNullValue()); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateIndexActionMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateIndexActionMappingsTests.java index e7b6ad92231..c3b358f4dc0 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateIndexActionMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateIndexActionMappingsTests.java @@ -53,7 +53,7 @@ public class HistoryTemplateIndexActionMappingsTests extends AbstractWatcherInte .get(); assertThat(response, notNullValue()); - assertThat(response.getHits().getTotalHits(), is(1L)); + assertThat(response.getHits().getTotalHits().value, is(1L)); Aggregations aggs = response.getAggregations(); assertThat(aggs, notNullValue()); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java index 69de3bcf871..b512fc46d8f 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java @@ -68,7 +68,7 @@ public class HistoryTemplateSearchInputMappingsTests extends AbstractWatcherInte .get(); assertThat(response, notNullValue()); - assertThat(response.getHits().getTotalHits(), is(1L)); + assertThat(response.getHits().getTotalHits().value, is(1L)); Aggregations aggs = response.getAggregations(); assertThat(aggs, notNullValue()); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java index 278a2c08d7b..f6ee589321f 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java @@ -147,7 +147,7 @@ public class ChainInputTests extends ESTestCase { watchBuilder() .trigger(schedule(interval("5s"))) .input(chainedInputBuilder) - .condition(new ScriptCondition(mockScript("ctx.payload.hits.total == 1"))) + .condition(new ScriptCondition(mockScript("ctx.payload.hits.total.value == 1"))) .addAction("_id", loggingAction("watch [{{ctx.watch_id}}] matched")) .toXContent(builder, ToXContent.EMPTY_PARAMS); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java index 826a273c58b..401d101a469 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java @@ -84,7 +84,7 @@ public class WatcherUtilsTests extends ESTestCase { builder.endObject(); return builder; }; - Map result = WatcherUtils.responseToData(content); + Map result = WatcherUtils.responseToData(content, ToXContent.EMPTY_PARAMS); assertThat(result, equalTo(expected)); } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index 40e87af1f0b..b4a05ef5a34 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -281,7 +281,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase if (type != null) { builder.setTypes(type); } - return builder.get().getHits().getTotalHits(); + return builder.get().getHits().getTotalHits().value; } protected SearchResponse searchHistory(SearchSourceBuilder builder) { @@ -337,16 +337,16 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase ExecutionState.EXECUTED.id()))) .get(); lastResponse.set(searchResponse); - assertThat("could not find executed watch record for watch " + watchName, searchResponse.getHits().getTotalHits(), + assertThat("could not find executed watch record for watch " + watchName, searchResponse.getHits().getTotalHits().value, greaterThanOrEqualTo(minimumExpectedWatchActionsWithActionPerformed)); if (assertConditionMet) { - assertThat((Integer) XContentMapValues.extractValue("result.input.payload.hits.total", + assertThat((Integer) XContentMapValues.extractValue("result.input.payload.hits.total.value", searchResponse.getHits().getAt(0).getSourceAsMap()), greaterThanOrEqualTo(1)); } }); } catch (AssertionError error) { SearchResponse searchResponse = lastResponse.get(); - logger.info("Found [{}] records for watch [{}]", searchResponse.getHits().getTotalHits(), watchName); + logger.info("Found [{}] records for watch [{}]", searchResponse.getHits().getTotalHits().value, watchName); int counter = 1; for (SearchHit hit : searchResponse.getHits().getHits()) { logger.info("hit [{}]=\n {}", counter++, XContentHelper.convertToJson(hit.getSourceRef(), true, true)); @@ -368,7 +368,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", ExecutionState.EXECUTED.id()))) .get(); - return searchResponse.getHits().getTotalHits(); + return searchResponse.getHits().getTotalHits().value; } protected void assertWatchWithNoActionNeeded(final String watchName, @@ -394,11 +394,11 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase ExecutionState.EXECUTION_NOT_NEEDED.id()))) .get(); lastResponse.set(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), greaterThanOrEqualTo(expectedWatchActionsWithNoActionNeeded)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThanOrEqualTo(expectedWatchActionsWithNoActionNeeded)); }); } catch (AssertionError error) { SearchResponse searchResponse = lastResponse.get(); - logger.info("Found [{}] records for watch [{}]", searchResponse.getHits().getTotalHits(), watchName); + logger.info("Found [{}] records for watch [{}]", searchResponse.getHits().getTotalHits().value, watchName); int counter = 1; for (SearchHit hit : searchResponse.getHits().getHits()) { logger.info("hit [{}]=\n {}", counter++, XContentHelper.convertToJson(hit.getSourceRef(), true, true)); @@ -425,7 +425,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", recordState.id()))) .get(); - assertThat("could not find executed watch record", searchResponse.getHits().getTotalHits(), + assertThat("could not find executed watch record", searchResponse.getHits().getTotalHits().value, greaterThanOrEqualTo(recordCount)); }); } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java index 8a7eb841576..81a2911be28 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java @@ -84,7 +84,7 @@ public class WatcherExecutorServiceBenchmark { .condition(new ScriptCondition(new Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, - "ctx.payload.hits.total > 0", + "ctx.payload.hits.total.value > 0", emptyMap()))).buildAsBytes(XContentType.JSON), XContentType.JSON); putAlertRequest.setId(name); watcherClient.putWatch(putAlertRequest).actionGet(); @@ -126,7 +126,7 @@ public class WatcherExecutorServiceBenchmark { PutWatchRequest putAlertRequest = new PutWatchRequest(name, new WatchSourceBuilder() .trigger(schedule(interval("5s"))) .input(searchInput(templateRequest(new SearchSourceBuilder(), "test")) - .extractKeys("hits.total")) + .extractKeys("hits.total.value")) .condition(new ScriptCondition(new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "1 == 1", emptyMap()))) .addAction("_id", indexAction("index", "type")).buildAsBytes(XContentType.JSON), XContentType.JSON); putAlertRequest.setId(name); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java index e89c793e39b..cd24c43cbca 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java @@ -122,7 +122,7 @@ public class WatcherScheduleEngineBenchmark { .condition(new ScriptCondition(new Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, - "ctx.payload.hits.total > 0", + "ctx.payload.hits.total.value > 0", emptyMap()))) .addAction("logging", ActionBuilders.loggingAction("test").setLevel(LoggingLevel.TRACE)) .buildAsBytes(XContentType.JSON), XContentType.JSON diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java index c07e6ba3db1..a037fba6c4d 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java @@ -75,7 +75,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase { .setSource(watchBuilder() .trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS))) .input(searchInput(request)) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.EQ, 1L)) .addAction("_logger", loggingAction("_logging") .setCategory("_category"))) .get(); @@ -95,7 +95,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase { .setSource(watchBuilder() .trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS))) .input(searchInput(searchRequest)) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.EQ, 1L))) .get(); timeWarp().trigger("_name"); // The watch's condition won't meet because there is no data that matches with the query @@ -119,7 +119,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase { .setSource(watchBuilder() .trigger(schedule(cron("0/1 * * * * ? 2020"))) .input(searchInput(searchRequest)) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.EQ, 1L))) .get(); assertThat(indexResponse.isCreated(), is(true)); DeleteWatchResponse deleteWatchResponse = watcherClient.prepareDeleteWatch("_name").get(); @@ -180,7 +180,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase { .addAction("_id", indexAction("idx", "action")); watcherClient().preparePutWatch("_name") - .setSource(source.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))) + .setSource(source.condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.EQ, 1L))) .get(); timeWarp().clock().fastForwardSeconds(5); @@ -188,7 +188,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase { assertWatchWithMinimumPerformedActionsCount("_name", 0, false); watcherClient().preparePutWatch("_name") - .setSource(source.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 0L))) + .setSource(source.condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.EQ, 0L))) .get(); timeWarp().clock().fastForwardSeconds(5); @@ -199,7 +199,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase { watcherClient().preparePutWatch("_name") .setSource(source .trigger(schedule(Schedules.cron("0/1 * * * * ? 2020"))) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 0L))) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.EQ, 0L))) .get(); timeWarp().clock().fastForwardSeconds(5); @@ -244,14 +244,14 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase { watcherClient.preparePutWatch("_name1") .setSource(watchBuilder() .trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS))) - .input(searchInput(request).extractKeys("hits.total")) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))) + .input(searchInput(request).extractKeys("hits.total.value")) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.EQ, 1L))) .get(); // in this watcher the condition will fail, because max_score isn't extracted, only total: watcherClient.preparePutWatch("_name2") .setSource(watchBuilder() .trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS))) - .input(searchInput(request).extractKeys("hits.total")) + .input(searchInput(request).extractKeys("hits.total.value")) .condition(new CompareCondition("ctx.payload.hits.max_score", CompareCondition.Op.GTE, 0L))) .get(); @@ -265,7 +265,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase { SearchResponse searchResponse = searchWatchRecords(builder -> builder.setQuery(matchQuery("watch_id", "_name1"))); assertHitCount(searchResponse, 1); XContentSource source = xContentSource(searchResponse.getHits().getAt(0).getSourceRef()); - assertThat(source.getValue("result.input.payload.hits.total"), equalTo((Object) 1)); + assertThat(source.getValue("result.input.payload.hits.total.value"), equalTo((Object) 1)); } public void testPutWatchWithNegativeSchedule() throws Exception { @@ -349,7 +349,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase { .setSource(watchBuilder() .trigger(schedule(interval("5s"))) .input(searchInput(request)) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GTE, 3L))) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.GTE, 3L))) .get(); logger.info("created watch [{}] at [{}]", watchName, new DateTime(Clock.systemUTC().millis())); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java index 65c5d773046..5a5c5c020da 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java @@ -156,7 +156,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase { .setSource(watchBuilder() .trigger(schedule(cron("0 0/5 * * * ? 2050"))) .input(searchInput(request)) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.EQ, 1L)) .buildAsBytes(XContentType.JSON), XContentType.JSON ) .setWaitForActiveShards(ActiveShardCount.ALL)); @@ -276,8 +276,8 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase { refresh(); SearchResponse searchResponse = client().prepareSearch("output").get(); - assertThat(searchResponse.getHits().getTotalHits(), is(greaterThanOrEqualTo(numberOfWatches))); - long successfulWatchExecutions = searchResponse.getHits().getTotalHits(); + assertThat(searchResponse.getHits().getTotalHits().value, is(greaterThanOrEqualTo(numberOfWatches))); + long successfulWatchExecutions = searchResponse.getHits().getTotalHits().value; // the watch history should contain entries for each triggered watch, which a few have been marked as not executed SearchResponse historySearchResponse = client().prepareSearch(HistoryStoreField.INDEX_PREFIX + "*").setSize(10000).get(); @@ -350,7 +350,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase { // the actual documents are in the output index refresh(); SearchResponse searchResponse = client().prepareSearch(watchRecordIndex).setSize(numRecords).get(); - assertThat(searchResponse.getHits().getTotalHits(), Matchers.equalTo((long) numRecords)); + assertThat(searchResponse.getHits().getTotalHits().value, Matchers.equalTo((long) numRecords)); for (int i = 0; i < numRecords; i++) { assertThat(searchResponse.getHits().getAt(i).getSourceAsMap().get("state"), is(ExecutionState.EXECUTED.id())); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SingleNodeTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SingleNodeTests.java index 2109f2a2d95..6d2d63d4f41 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SingleNodeTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SingleNodeTests.java @@ -59,7 +59,7 @@ public class SingleNodeTests extends AbstractWatcherIntegrationTestCase { assertBusy(() -> { client().admin().indices().prepareRefresh(".watcher-history*"); SearchResponse searchResponse = client().prepareSearch(".watcher-history*").setSize(0).get(); - assertThat(searchResponse.getHits().getTotalHits(), is(greaterThanOrEqualTo(1L))); + assertThat(searchResponse.getHits().getTotalHits().value, is(greaterThanOrEqualTo(1L))); }, 5, TimeUnit.SECONDS); } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java index 1ae49265352..805bda6f9d5 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java @@ -67,7 +67,7 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase { .setSource(watchBuilder() .trigger(schedule(cron("0/5 * * * * ? *"))) .input(searchInput(templateRequest(searchSource(), "events"))) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L)) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.GT, 0L)) .transform(searchTransform(templateRequest(searchSource(), "events"))) .addAction("_a1", indexAction("actions1", "doc")) .addAction("_a2", indexAction("actions2", "doc")) @@ -127,7 +127,7 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase { .setSource(watchBuilder() .trigger(schedule(cron("0/5 * * * * ? *"))) .input(searchInput(templateRequest(searchSource(), "events"))) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L)) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.GT, 0L)) .transform(searchTransform(templateRequest(searchSource(), "events"))) .addAction("_a1", indexAction("actions1", "doc")) .addAction("_a2", indexAction("actions2", "doc")) @@ -195,7 +195,7 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase { .setSource(watchBuilder() .trigger(schedule(cron("0/5 * * * * ? *"))) .input(searchInput(templateRequest(searchSource(), "events"))) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L)) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.GT, 0L)) .transform(searchTransform(templateRequest(searchSource(), "events"))) .addAction("_id", indexAction("actions", "action"))) .get(); @@ -209,7 +209,8 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase { assertThat(ackResponse.getStatus().actionStatus("_id").ackStatus().state(), is(ActionStatus.AckStatus.State.ACKED)); refresh("actions"); - long countAfterAck = client().prepareSearch("actions").setTypes("action").setQuery(matchAllQuery()).get().getHits().getTotalHits(); + long countAfterAck = client().prepareSearch("actions").setTypes("action").setQuery(matchAllQuery()).get() + .getHits().getTotalHits().value; assertThat(countAfterAck, greaterThanOrEqualTo(1L)); restartWatcherRandomly(); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java index 143f760f23c..7b54a043df8 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java @@ -52,7 +52,7 @@ public class WatchMetadataTests extends AbstractWatcherIntegrationTestCase { .setSource(watchBuilder() .trigger(schedule(cron("0/5 * * * * ? *"))) .input(noneInput()) - .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)) + .condition(new CompareCondition("ctx.payload.hits.total.value", CompareCondition.Op.EQ, 1L)) .metadata(metadata)) .get(); @@ -62,7 +62,7 @@ public class WatchMetadataTests extends AbstractWatcherIntegrationTestCase { SearchResponse searchResponse = client().prepareSearch(HistoryStoreField.INDEX_PREFIX_WITH_TEMPLATE + "*") .setQuery(termQuery("metadata.foo", "bar")) .get(); - assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); + assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L)); } public void testWatchMetadataAvailableAtExecution() throws Exception { diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java index 044c3d3061e..0a12a0b1a64 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java @@ -145,13 +145,13 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas SearchResponse response = client().prepareSearch("output1").get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), greaterThanOrEqualTo(1L)); + assertThat(response.getHits().getTotalHits().value, greaterThanOrEqualTo(1L)); assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1)); assertThat(response.getHits().getAt(0).getSourceAsMap().get("key3").toString(), equalTo("20")); response = client().prepareSearch("output2").get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), greaterThanOrEqualTo(1L)); + assertThat(response.getHits().getTotalHits().value, greaterThanOrEqualTo(1L)); assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1)); assertThat(response.getHits().getAt(0).getSourceAsMap().get("key3").toString(), equalTo("20")); } @@ -192,12 +192,12 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas SearchResponse response = client().prepareSearch("output1").get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), greaterThanOrEqualTo(1L)); + assertThat(response.getHits().getTotalHits().value, greaterThanOrEqualTo(1L)); assertThat(response.getHits().getAt(0).getSourceAsString(), containsString("mytestresult")); response = client().prepareSearch("output2").get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), greaterThanOrEqualTo(1L)); + assertThat(response.getHits().getTotalHits().value, greaterThanOrEqualTo(1L)); assertThat(response.getHits().getAt(0).getSourceAsString(), containsString("mytestresult")); } @@ -236,13 +236,13 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas SearchResponse response = client().prepareSearch("output1").get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), greaterThanOrEqualTo(1L)); + assertThat(response.getHits().getTotalHits().value, greaterThanOrEqualTo(1L)); assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1)); assertThat(response.getHits().getAt(0).getSourceAsMap().get("key4").toString(), equalTo("30")); response = client().prepareSearch("output2").get(); assertNoFailures(response); - assertThat(response.getHits().getTotalHits(), greaterThanOrEqualTo(1L)); + assertThat(response.getHits().getTotalHits().value, greaterThanOrEqualTo(1L)); assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1)); assertThat(response.getHits().getAt(0).getSourceAsMap().get("key4").toString(), equalTo("30")); } diff --git a/x-pack/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java b/x-pack/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java index d1ee4f2d9e1..f66e089b2d3 100644 --- a/x-pack/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java +++ b/x-pack/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java @@ -189,7 +189,7 @@ public class IndexAuditIT extends ESIntegTestCase { client().admin().indices().prepareRefresh(".security_audit_log*").get(); logger.info("refreshed audit indices"); return client().prepareSearch(".security_audit_log*").setQuery(query) - .get().getHits().getTotalHits() > 0; + .get().getHits().getTotalHits().value > 0; }, 60L, TimeUnit.SECONDS); } diff --git a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java index 1192c780171..271a7910fd4 100644 --- a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.test.StreamsUtils; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.upgrades.AbstractFullClusterRestartTestCase; @@ -41,6 +42,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; +import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HIT_AS_INT_PARAM; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; @@ -350,6 +352,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertBusy(() -> { client().performRequest(new Request("POST", "id-test-results-rollup/_refresh")); final Request searchRequest = new Request("GET", "id-test-results-rollup/_search"); + searchRequest.addParameter(TOTAL_HIT_AS_INT_PARAM, "true"); try { Map searchResponse = entityAsMap(client().performRequest(searchRequest)); assertNotNull(ObjectPath.eval("hits.total", searchResponse)); @@ -389,6 +392,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertBusy(() -> { client().performRequest(new Request("POST", "id-test-results-rollup/_refresh")); final Request searchRequest = new Request("GET", "id-test-results-rollup/_search"); + searchRequest.addParameter(TOTAL_HIT_AS_INT_PARAM, "true"); try { Map searchResponse = entityAsMap(client().performRequest(searchRequest)); assertNotNull(ObjectPath.eval("hits.total", searchResponse)); @@ -496,8 +500,9 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertThat(basic, hasEntry("username", "Aladdin")); // password doesn't come back because it is hidden assertThat(basic, hasEntry(is("password"), anyOf(startsWith("::es_encrypted::"), is("::es_redacted::")))); - - Map history = entityAsMap(client().performRequest(new Request("GET", ".watcher-history*/_search"))); + Request searchRequest = new Request("GET", ".watcher-history*/_search"); + searchRequest.addParameter(RestSearchAction.TOTAL_HIT_AS_INT_PARAM, "true"); + Map history = entityAsMap(client().performRequest(searchRequest)); Map hits = (Map) history.get("hits"); assertThat((int) (hits.get("total")), greaterThanOrEqualTo(2)); } diff --git a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/10_basic.yml b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/10_basic.yml index 35c6212451c..5291b8735ba 100644 --- a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/10_basic.yml +++ b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/10_basic.yml @@ -67,6 +67,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: local_index,my_remote_cluster:test_index body: aggs: @@ -85,6 +86,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: local_index,my_remote_cluster:test_index body: query: @@ -105,6 +107,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: my_remote_cluster:test_index body: aggs: @@ -123,6 +126,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: "my_*:test_index" body: aggs: @@ -140,6 +144,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: local_index body: aggs: @@ -174,6 +179,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: test_remote_cluster:test_index - match: { _shards.total: 3 } @@ -184,6 +190,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: "*_remote_cluster:test_ind*" - match: { _shards.total: 6 } @@ -195,6 +202,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: my_remote_cluster:aliased_test_index - match: { _shards.total: 3 } @@ -208,6 +216,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: my_remote_cluster:secure_alias # TODO make this a wildcard once - match: { _shards.total: 2 } diff --git a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/20_info.yml b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/20_info.yml index 490edf794f6..2f30a285a70 100644 --- a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/20_info.yml +++ b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/20_info.yml @@ -63,6 +63,7 @@ teardown: # otherwise the cluster might not have been connected yet. - do: search: + rest_total_hits_as_int: true index: test_remote_cluster:test_index - do: diff --git a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/40_scroll.yml b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/40_scroll.yml index 97e0cfab862..bfc3d0d9950 100644 --- a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/40_scroll.yml +++ b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/40_scroll.yml @@ -43,6 +43,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: my_remote_cluster:test_index size: 4 scroll: 1m @@ -62,6 +63,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } scroll: + rest_total_hits_as_int: true body: { "scroll_id": "$scroll_id", "scroll": "1m"} - match: {hits.total: 6 } @@ -72,6 +74,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 1m @@ -88,6 +91,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: my_remote_cluster:test_index size: 4 scroll: 1m @@ -107,6 +111,7 @@ teardown: - do: # steal the scroll ID cross cluster and make sure it fails catch: /search_context_missing_exception/ scroll: + rest_total_hits_as_int: true body: { "scroll_id": "$scroll_id", "scroll": "1m"} - do: diff --git a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml index 0b224518782..1b35d8546a5 100644 --- a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml +++ b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml @@ -42,6 +42,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: "*:foo-*" - match: { _shards.total: 0 } @@ -50,6 +51,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: "my_remote_cluster:foo-*" - match: { _shards.total: 0 } @@ -59,10 +61,12 @@ teardown: catch: "forbidden" headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: "*:foo-bar" - do: catch: "forbidden" headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: "my_remote_cluster:foo-bar" diff --git a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/60_skip_shards.yml b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/60_skip_shards.yml index ad27f58567a..add6f8ac62e 100644 --- a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/60_skip_shards.yml +++ b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/60_skip_shards.yml @@ -66,6 +66,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: "skip_shards_index,my_remote_cluster:single_doc_index" pre_filter_shard_size: 1 body: { "size" : 10, "query" : { "range" : { "created_at" : { "gte" : "2016-02-01", "lt": "2018-02-01"} } } } @@ -82,6 +83,7 @@ teardown: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: "skip_shards_index,my_remote_cluster:single_doc_index" pre_filter_shard_size: 1 body: { "size" : 10, "query" : { "range" : { "created_at" : { "gte" : "2015-02-01", "lt": "2016-02-01"} } } } diff --git a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/remote_cluster/10_basic.yml b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/remote_cluster/10_basic.yml index adcf0cf0770..dc1b512736d 100644 --- a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/remote_cluster/10_basic.yml +++ b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/remote_cluster/10_basic.yml @@ -149,6 +149,7 @@ setup: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: test_index body: aggs: @@ -165,6 +166,7 @@ setup: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: aliased_test_index - match: { _shards.total: 3 } @@ -175,6 +177,7 @@ setup: - do: headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: + rest_total_hits_as_int: true index: secure_alias - match: { _shards.total: 2 } diff --git a/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/10_reindex.yml b/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/10_reindex.yml index ab9f56652e3..6173583a346 100644 --- a/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/10_reindex.yml +++ b/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/10_reindex.yml @@ -47,6 +47,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -79,6 +80,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -166,10 +168,12 @@ setup: - do: catch: missing search: + rest_total_hits_as_int: true index: other_dest - do: search: + rest_total_hits_as_int: true index: dest - length: { hits.hits: 1 } - match: { hits.hits.0._index: dest } @@ -206,6 +210,7 @@ setup: # We copied just one doc, presumably the one without the hidden field - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -216,6 +221,7 @@ setup: # We didn't copy the doc with the hidden field - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -248,6 +254,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -257,6 +264,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -266,6 +274,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -349,6 +358,7 @@ setup: - do: search: index: dest + rest_total_hits_as_int: true body: query: match: diff --git a/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/15_reindex_from_remote.yml b/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/15_reindex_from_remote.yml index b558ad72677..a68b5262c02 100644 --- a/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/15_reindex_from_remote.yml +++ b/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/15_reindex_from_remote.yml @@ -73,6 +73,7 @@ - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -118,6 +119,7 @@ - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -212,10 +214,12 @@ - do: catch: missing search: + rest_total_hits_as_int: true index: other_dest - do: search: + rest_total_hits_as_int: true index: dest - length: { hits.hits: 1 } - match: { hits.hits.0._index: dest } @@ -266,6 +270,7 @@ # We copied just one doc, presumably the one without the hidden field - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -276,6 +281,7 @@ # We didn't copy the doc with the hidden field - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -322,6 +328,7 @@ - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -331,6 +338,7 @@ - do: search: + rest_total_hits_as_int: true index: dest body: query: @@ -340,6 +348,7 @@ - do: search: + rest_total_hits_as_int: true index: dest body: query: diff --git a/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/20_update_by_query.yml b/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/20_update_by_query.yml index caf29f2fc6b..805d9973bfd 100644 --- a/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/20_update_by_query.yml +++ b/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/20_update_by_query.yml @@ -24,6 +24,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: source body: query: @@ -55,6 +56,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: source body: query: @@ -86,6 +88,7 @@ setup: - do: search: + rest_total_hits_as_int: true index: source body: query: @@ -160,6 +163,7 @@ setup: # We only updated one doc, presumably the one without the hidden field - do: search: + rest_total_hits_as_int: true index: source body: query: @@ -170,6 +174,7 @@ setup: # We didn't update the doc with the hidden field - do: search: + rest_total_hits_as_int: true index: source body: query: diff --git a/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/30_delete_by_query.yml b/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/30_delete_by_query.yml index deffc4ce5e2..22bd593cfb5 100644 --- a/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/30_delete_by_query.yml +++ b/x-pack/qa/reindex-tests-with-security/src/test/resources/rest-api-spec/test/30_delete_by_query.yml @@ -167,6 +167,7 @@ setup: # We only deleted one doc, presumably the one without the hidden field - do: search: + rest_total_hits_as_int: true index: source body: query: @@ -177,6 +178,7 @@ setup: # We didn't delete the doc with the hidden field set to "true" - do: search: + rest_total_hits_as_int: true index: source body: query: @@ -191,6 +193,7 @@ setup: # But the doc with the hidden field set to "false" must have been deleted - do: search: + rest_total_hits_as_int: true index: source body: query: diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java index 8372059b823..d657a42d7df 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HIT_AS_INT_PARAM; import static org.hamcrest.Matchers.equalTo; /** @@ -142,6 +143,7 @@ public class IndexingIT extends AbstractUpgradeTestCase { private void assertCount(String index, int count) throws IOException { Request searchTestIndexRequest = new Request("POST", "/" + index + "/_search"); + searchTestIndexRequest.addParameter(TOTAL_HIT_AS_INT_PARAM, "true"); searchTestIndexRequest.addParameter("filter_path", "hits.total"); Response searchTestIndexResponse = client().performRequest(searchTestIndexRequest); assertEquals("{\"hits\":{\"total\":" + count + "}}", diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java index f51835af719..f140aeb20cc 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HIT_AS_INT_PARAM; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; @@ -196,6 +197,7 @@ public class RollupIDUpgradeIT extends AbstractUpgradeTestCase { collectedIDs.clear(); client().performRequest(new Request("POST", "rollup/_refresh")); final Request searchRequest = new Request("GET", "rollup/_search"); + searchRequest.addParameter(TOTAL_HIT_AS_INT_PARAM, "true"); try { Map searchResponse = entityAsMap(client().performRequest(searchRequest)); assertNotNull(ObjectPath.eval("hits.total", searchResponse)); diff --git a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/10_basic.yml b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/10_basic.yml index 66c92797eef..0cd2a9bf1fa 100644 --- a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/10_basic.yml +++ b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/10_basic.yml @@ -31,6 +31,7 @@ - do: search: + rest_total_hits_as_int: true index: upgraded_scroll size: 1 scroll: 5m diff --git a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/50_token_auth.yml b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/50_token_auth.yml index 093902f8d0a..96e6278b358 100644 --- a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/50_token_auth.yml +++ b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/50_token_auth.yml @@ -28,6 +28,7 @@ headers: Authorization: Bearer ${token} search: + rest_total_hits_as_int: true index: token_index - match: { hits.total: 6 } @@ -36,6 +37,7 @@ headers: Authorization: Bearer ${token} search: + rest_total_hits_as_int: true index: token_index - match: { hits.total: 6 } @@ -44,6 +46,7 @@ headers: Authorization: Bearer ${token} search: + rest_total_hits_as_int: true index: token_index - match: { hits.total: 6 } diff --git a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/60_watcher.yml b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/60_watcher.yml index 30a22e63673..2952e649c76 100644 --- a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/60_watcher.yml +++ b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/60_watcher.yml @@ -31,6 +31,7 @@ - do: search: + rest_total_hits_as_int: true index: .watcher-history-* body: { diff --git a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/50_token_auth.yml b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/50_token_auth.yml index 864332ecd33..974ef56a758 100644 --- a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/50_token_auth.yml +++ b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/50_token_auth.yml @@ -69,6 +69,7 @@ headers: Authorization: Bearer ${token} search: + rest_total_hits_as_int: true index: token_index - match: { hits.total: 5 } diff --git a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/60_watcher.yml b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/60_watcher.yml index 2547ddd7023..810307bbb28 100644 --- a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/60_watcher.yml +++ b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/60_watcher.yml @@ -51,6 +51,7 @@ - do: search: + rest_total_hits_as_int: true index: .watcher-history-* body: { diff --git a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml index 7249b4a32c7..1d5f89667db 100644 --- a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml +++ b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml @@ -10,6 +10,7 @@ - do: scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 1m @@ -19,6 +20,7 @@ - do: scroll: + rest_total_hits_as_int: true scroll_id: $scroll_id scroll: 1m diff --git a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/50_token_auth.yml b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/50_token_auth.yml index 9f576512fc7..2598b498f08 100644 --- a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/50_token_auth.yml +++ b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/50_token_auth.yml @@ -27,6 +27,7 @@ headers: Authorization: Bearer ${token} search: + rest_total_hits_as_int: true index: token_index - match: { hits.total: 6 } @@ -37,4 +38,5 @@ Authorization: Bearer boom catch: /missing authentication token/ search: + rest_total_hits_as_int: true index: token_index diff --git a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/60_watcher.yml b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/60_watcher.yml index 75e31c62a84..3828db6128f 100644 --- a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/60_watcher.yml +++ b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/60_watcher.yml @@ -31,6 +31,7 @@ - do: search: + rest_total_hits_as_int: true index: .watcher-history-* body: { diff --git a/x-pack/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java b/x-pack/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java index c427d8bf32c..6a49e18ca93 100644 --- a/x-pack/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java +++ b/x-pack/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java @@ -152,7 +152,7 @@ public class SmokeTestMonitoringWithSecurityIT extends ESIntegTestCase { // Checks that the HTTP exporter has successfully exported some data assertBusy(() -> { try { - assertThat(client().prepareSearch(MONITORING_PATTERN).setSize(0).get().getHits().getTotalHits(), greaterThan(0L)); + assertThat(client().prepareSearch(MONITORING_PATTERN).setSize(0).get().getHits().getTotalHits().value, greaterThan(0L)); } catch (Exception e) { fail("exception when checking for monitoring documents: " + e.getMessage()); } diff --git a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/10_templated_role_query.yml b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/10_templated_role_query.yml index 30284ab1645..f815b58777d 100644 --- a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/10_templated_role_query.yml +++ b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/10_templated_role_query.yml @@ -161,6 +161,7 @@ teardown: headers: Authorization: "Basic aW5saW5lX3RlbXBsYXRlX3VzZXI6eC1wYWNrLXRlc3QtcGFzc3dvcmQ" search: + rest_total_hits_as_int: true index: foobar body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} @@ -172,6 +173,7 @@ teardown: headers: Authorization: "Basic c3RvcmVkX3RlbXBsYXRlX3VzZXI6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" search: + rest_total_hits_as_int: true index: foobar body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} @@ -183,6 +185,7 @@ teardown: headers: Authorization: "Basic dGVybXNfdGVtcGxhdGVfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" search: + rest_total_hits_as_int: true index: foobar body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} diff --git a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/11_templated_role_query_runas.yml b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/11_templated_role_query_runas.yml index 0c6bd4cbdac..ef3bc45671b 100644 --- a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/11_templated_role_query_runas.yml +++ b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/11_templated_role_query_runas.yml @@ -161,6 +161,7 @@ teardown: headers: es-security-runas-user: "inline_template_user" search: + rest_total_hits_as_int: true index: foobar body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} @@ -172,6 +173,7 @@ teardown: headers: es-security-runas-user: "stored_template_user" search: + rest_total_hits_as_int: true index: foobar body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} @@ -183,6 +185,7 @@ teardown: headers: es-security-runas-user: "terms_template_user" search: + rest_total_hits_as_int: true index: foobar body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} diff --git a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/20_small_users_one_index.yml b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/20_small_users_one_index.yml index ff5fad0e82d..e63cc02e27c 100644 --- a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/20_small_users_one_index.yml +++ b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/20_small_users_one_index.yml @@ -114,6 +114,7 @@ teardown: headers: Authorization: "Basic am9lOngtcGFjay10ZXN0LXBhc3N3b3Jk" search: + rest_total_hits_as_int: true index: shared_logs body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} @@ -124,6 +125,7 @@ teardown: headers: Authorization: "Basic am9objp4LXBhY2stdGVzdC1wYXNzd29yZA==" search: + rest_total_hits_as_int: true index: shared_logs body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} @@ -182,6 +184,7 @@ teardown: headers: Authorization: "Basic am9lOngtcGFjay10ZXN0LXBhc3N3b3Jk" search: + rest_total_hits_as_int: true index: shared_logs body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} @@ -192,6 +195,7 @@ teardown: headers: Authorization: "Basic am9objp4LXBhY2stdGVzdC1wYXNzd29yZA==" search: + rest_total_hits_as_int: true index: shared_logs body: { "query" : { "match_all" : {} } } - match: { hits.total: 1} diff --git a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/30_search_template.yml b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/30_search_template.yml index e6e71b74b60..c676615bee0 100644 --- a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/30_search_template.yml +++ b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/30_search_template.yml @@ -61,6 +61,7 @@ teardown: headers: Authorization: "Basic aW5saW5lX3RlbXBsYXRlX3VzZXI6eC1wYWNrLXRlc3QtcGFzc3dvcmQ" search_template: + rest_total_hits_as_int: true index: foobar body: source: @@ -79,6 +80,7 @@ teardown: headers: Authorization: "Basic aW5saW5lX3RlbXBsYXRlX3VzZXI6eC1wYWNrLXRlc3QtcGFzc3dvcmQ" search_template: + rest_total_hits_as_int: true body: source: query: @@ -96,6 +98,7 @@ teardown: headers: Authorization: "Basic aW5saW5lX3RlbXBsYXRlX3VzZXI6eC1wYWNrLXRlc3QtcGFzc3dvcmQ" search_template: + rest_total_hits_as_int: true index: foo* body: source: @@ -114,6 +117,7 @@ teardown: headers: Authorization: "Basic aW5saW5lX3RlbXBsYXRlX3VzZXI6eC1wYWNrLXRlc3QtcGFzc3dvcmQ" search_template: + rest_total_hits_as_int: true index: unauthorized* body: source: @@ -132,6 +136,7 @@ teardown: headers: Authorization: "Basic aW5saW5lX3RlbXBsYXRlX3VzZXI6eC1wYWNrLXRlc3QtcGFzc3dvcmQ" msearch_template: + rest_total_hits_as_int: true body: - index: foobar - source: diff --git a/x-pack/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityIT.java b/x-pack/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityIT.java index 02083cbedb2..66bcf82a500 100644 --- a/x-pack/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityIT.java +++ b/x-pack/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityIT.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HIT_AS_INT_PARAM; import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -323,6 +324,7 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase { builder.endObject(); Request searchRequest = new Request("POST", "/.watcher-history-*/_search"); + searchRequest.addParameter(TOTAL_HIT_AS_INT_PARAM, "true"); searchRequest.setJsonEntity(Strings.toString(builder)); Response response = client().performRequest(searchRequest); ObjectPath objectPath = ObjectPath.createFromResponse(response); diff --git a/x-pack/qa/smoke-test-watcher-with-security/src/test/resources/rest-api-spec/test/watcher/watcher_and_security/20_test_run_as_execute_watch.yml b/x-pack/qa/smoke-test-watcher-with-security/src/test/resources/rest-api-spec/test/watcher/watcher_and_security/20_test_run_as_execute_watch.yml index 779b41748ac..bd0d32ef9cc 100644 --- a/x-pack/qa/smoke-test-watcher-with-security/src/test/resources/rest-api-spec/test/watcher/watcher_and_security/20_test_run_as_execute_watch.yml +++ b/x-pack/qa/smoke-test-watcher-with-security/src/test/resources/rest-api-spec/test/watcher/watcher_and_security/20_test_run_as_execute_watch.yml @@ -23,9 +23,6 @@ teardown: id: "my_watch" ignore: 404 - - - --- "Test watch search input is run as user who added the watch": - skip: @@ -42,6 +39,7 @@ teardown: "search" : { "request" : { "indices" : [ "my_test_index" ], + "rest_total_hits_as_int": true, "body" :{ "query" : { "match_all": {} } } @@ -97,6 +95,7 @@ teardown: "search" : { "request" : { "indices" : [ "my_test_index" ], + "rest_total_hits_as_int": true, "body" :{ "query" : { "match_all": {} } } @@ -153,6 +152,7 @@ teardown: "search" : { "request" : { "indices" : [ "index_not_allowed_to_read" ], + "rest_total_hits_as_int": true, "body" :{ "query" : { "match_all": {} } } @@ -260,6 +260,7 @@ teardown: "transform" : { "search" : { "request" : { + "rest_total_hits_as_int": true, "indices" : [ "index_not_allowed_to_read" ], "body" :{ "query" : { "match_all": {} } diff --git a/x-pack/qa/smoke-test-watcher/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherTestSuiteIT.java b/x-pack/qa/smoke-test-watcher/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherTestSuiteIT.java index 93089a78e5b..ecb03b5ddb3 100644 --- a/x-pack/qa/smoke-test-watcher/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherTestSuiteIT.java +++ b/x-pack/qa/smoke-test-watcher/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherTestSuiteIT.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HIT_AS_INT_PARAM; import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasEntry; @@ -193,6 +194,7 @@ public class SmokeTestWatcherTestSuiteIT extends ESRestTestCase { builder.endObject(); Request searchRequest = new Request("POST", "/.watcher-history-*/_search"); + searchRequest.addParameter(TOTAL_HIT_AS_INT_PARAM, "true"); searchRequest.setJsonEntity(Strings.toString(builder)); Response response = client().performRequest(searchRequest); ObjectPath objectPath = ObjectPath.createFromResponse(response); diff --git a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/25_array_compare.yml b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/25_array_compare.yml index cb5e6d6b1f9..e2529323932 100644 --- a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/25_array_compare.yml +++ b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/25_array_compare.yml @@ -49,6 +49,7 @@ "search": { "request": { "indices": [ "test_1" ], + "rest_total_hits_as_int": true, "body": { "aggs": { "top_levels": { diff --git a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/30_search_input.yml b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/30_search_input.yml index 1b023dbedec..074b8d0fea7 100644 --- a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/30_search_input.yml +++ b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/30_search_input.yml @@ -70,6 +70,7 @@ setup: "search" : { "request" : { "indices" : "idx", + "rest_total_hits_as_int": true, "body" : { "query" : { "bool" : { @@ -144,6 +145,7 @@ setup: "search" : { "request" : { "indices" : "idx", + "rest_total_hits_as_int": true, "template" : { "id": "search-template", "params": { diff --git a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/40_search_transform.yml b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/40_search_transform.yml index b4dd70759be..abad97ae944 100644 --- a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/40_search_transform.yml +++ b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/40_search_transform.yml @@ -71,6 +71,7 @@ setup: "search" : { "request" : { "indices" : "idx", + "rest_total_hits_as_int": true, "body" : { "query" : { "bool" : { @@ -128,6 +129,7 @@ setup: "transform" : { "search" : { "request" : { + "rest_total_hits_as_int": true, "indices" : "idx", "template" : { "source" : "{\"query\": {\"bool\" : { \"must\": [{\"term\": {\"value\": \"val_{{ctx.payload.number}}\"}}]}}}" diff --git a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/50_webhook_url_escaping.yml b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/50_webhook_url_escaping.yml index 9952741d4ed..713dbb65b3d 100644 --- a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/50_webhook_url_escaping.yml +++ b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/mustache/50_webhook_url_escaping.yml @@ -52,6 +52,8 @@ host: $hostname port: $port path: "/{{#url}}{{ctx.metadata.index}}{{/url}}/_search" + params: + rest_total_hits_as_int: "true" condition: compare: "ctx.payload.hits.total": diff --git a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/10_basic.yml b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/10_basic.yml index 82764d71667..4ea2a8dc7ab 100644 --- a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/10_basic.yml +++ b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/10_basic.yml @@ -20,6 +20,7 @@ "search" : { "request" : { "indices" : [ "logstash*" ], + "rest_total_hits_as_int": true, "body" : { "query" : { "bool": { diff --git a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/30_inline_watch.yml b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/30_inline_watch.yml index ce3dd7bb731..f9ad2a42414 100644 --- a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/30_inline_watch.yml +++ b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/30_inline_watch.yml @@ -27,6 +27,7 @@ "search" : { "request" : { "indices" : [ "logstash*" ], + "rest_total_hits_as_int": true, "body" : { "query" : { "bool" : { diff --git a/x-pack/qa/third-party/hipchat/src/test/resources/rest-api-spec/test/hipchat/10_hipchat.yml b/x-pack/qa/third-party/hipchat/src/test/resources/rest-api-spec/test/hipchat/10_hipchat.yml index 9277ddae6c6..bd4751cac4b 100644 --- a/x-pack/qa/third-party/hipchat/src/test/resources/rest-api-spec/test/hipchat/10_hipchat.yml +++ b/x-pack/qa/third-party/hipchat/src/test/resources/rest-api-spec/test/hipchat/10_hipchat.yml @@ -69,6 +69,7 @@ - do: search: + rest_total_hits_as_int: true index: ".watcher-history-*" body: > { @@ -158,6 +159,7 @@ - do: search: + rest_total_hits_as_int: true index: ".watcher-history-*" body: > { @@ -248,6 +250,7 @@ - do: search: + rest_total_hits_as_int: true index: ".watcher-history-*" body: > { diff --git a/x-pack/qa/third-party/jira/src/test/resources/rest-api-spec/test/jira/10_jira.yml b/x-pack/qa/third-party/jira/src/test/resources/rest-api-spec/test/jira/10_jira.yml index cc44c433492..55573f0c0f0 100644 --- a/x-pack/qa/third-party/jira/src/test/resources/rest-api-spec/test/jira/10_jira.yml +++ b/x-pack/qa/third-party/jira/src/test/resources/rest-api-spec/test/jira/10_jira.yml @@ -72,6 +72,7 @@ - do: search: + rest_total_hits_as_int: true index: ".watcher-history-*" - match: { hits.total: 1 } @@ -96,6 +97,7 @@ - do: search: + rest_total_hits_as_int: true index: ".watcher-history-*" body: query: @@ -107,6 +109,7 @@ - do: search: + rest_total_hits_as_int: true index: ".watcher-history-*" body: query: @@ -187,6 +190,7 @@ - do: search: + rest_total_hits_as_int: true index: ".watcher-history-*" body: query: @@ -334,6 +338,7 @@ - do: search: + rest_total_hits_as_int: true index: ".watcher-history-*" body: query: diff --git a/x-pack/qa/third-party/pagerduty/src/test/resources/rest-api-spec/test/pagerduty/10_pagerduty.yml b/x-pack/qa/third-party/pagerduty/src/test/resources/rest-api-spec/test/pagerduty/10_pagerduty.yml index 47706e5f1e7..fa83c8e8e8c 100644 --- a/x-pack/qa/third-party/pagerduty/src/test/resources/rest-api-spec/test/pagerduty/10_pagerduty.yml +++ b/x-pack/qa/third-party/pagerduty/src/test/resources/rest-api-spec/test/pagerduty/10_pagerduty.yml @@ -77,6 +77,7 @@ - do: search: + rest_total_hits_as_int: true index: ".watcher-history-*" body: > { diff --git a/x-pack/qa/third-party/slack/src/test/resources/rest-api-spec/test/slack/10_slack.yml b/x-pack/qa/third-party/slack/src/test/resources/rest-api-spec/test/slack/10_slack.yml index 259bc9e1d25..f5719ddbfc0 100644 --- a/x-pack/qa/third-party/slack/src/test/resources/rest-api-spec/test/slack/10_slack.yml +++ b/x-pack/qa/third-party/slack/src/test/resources/rest-api-spec/test/slack/10_slack.yml @@ -106,6 +106,7 @@ - do: search: + rest_total_hits_as_int: true index: ".watcher-history-*" body: > {