Merge remote-tracking branch 'elastic/master' into zen2

This commit is contained in:
Yannick Welsch 2018-12-05 23:13:12 +01:00
commit a0ae1cc987
495 changed files with 3018 additions and 1371 deletions

View File

@ -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<SearchRequ
protected void doExecute(Task task, SearchRequest request, ActionListener<SearchResponse> 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));
}
}

View File

@ -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:

View File

@ -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
);
}
{

View File

@ -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());

View File

@ -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<String, Object> source = searchHit.getSourceAsMap();

View File

@ -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("<em>value2</em>"));
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("<em>value2</em>"));
@ -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("<em>value2</em>"));
@ -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];

View File

@ -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<String, Object>) 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<SearchResponse> 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<SearchTemplateResponse> listener = new ActionListener<SearchTemplateResponse>() {
@ -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<MultiSearchTemplateResponse> listener = new ActionListener<MultiSearchTemplateResponse>() {
@ -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

View File

@ -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<String, Object> 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<ExecuteWatchResponse> listener = new ActionListener<ExecuteWatchResponse>() {
@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));
}

View File

@ -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;
}
--------------------------------------------------

View File

@ -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

View File

@ -265,7 +265,10 @@ GET /my_ip_locations/_search
"failed" : 0
},
"hits" : {
"total" : 1,
"total" : {
"value": 1,
"relation": "eq"
},
"max_score" : 1.0,
"hits" : [
{

View File

@ -143,7 +143,10 @@ Possible response:
"failed": 0
},
"hits": {
"total": 3,
"total" : {
"value": 3,
"relation": "eq"
},
"max_score": null,
"hits": []
},

View File

@ -143,7 +143,10 @@ Possible response:
"failed": 0
},
"hits": {
"total": 3,
"total" : {
"value": 3,
"relation": "eq"
},
"max_score": null,
"hits": []
},

View File

@ -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": [
{

View File

@ -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" : [
{

View File

@ -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": [
{

View File

@ -300,7 +300,10 @@ GET my_index/_search
"failed": 0
},
"hits": {
"total": 1,
"total" : {
"value": 1,
"relation": "eq"
},
"max_score": 0.5753642,
"hits": [
{

View File

@ -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"
}
}
}
----------------------------------------------------------------

View File

@ -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"
}
}
}
----------------------------------------------------------------

View File

@ -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"
}
}
}
--------------------------------------------------

View File

@ -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" : [ ]
},

View File

@ -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": [
{

View File

@ -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" : []
},

View File

@ -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": [
{

View File

@ -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": []
},

View File

@ -175,7 +175,10 @@ Will return:
{
...,
"hits": {
"total": 4,
"total" : {
"value": 4,
"relation": "eq"
},
"max_score": null,
"hits": [
{

View File

@ -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": [
{

View File

@ -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" : [
{

View File

@ -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`).

View File

@ -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": [
{

View File

@ -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": [
{

View File

@ -72,7 +72,10 @@ Response:
"failed": 0
},
"hits": {
"total": 1,
"total" : {
"value": 1,
"relation": "eq"
},
"max_score": 0.87546873,
"hits": [
{

View File

@ -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" : [ ]
},

View File

@ -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" : [ ]
},

View File

@ -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>
},

View File

@ -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": []
}

View File

@ -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": [
{

View File

@ -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": [
{

View File

@ -257,7 +257,10 @@ Which should look like:
"failed" : 0
},
"hits": {
"total" : 0,
"total" : {
"value": 0,
"relation": "eq"
},
"max_score" : null,
"hits" : []
},

View File

@ -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" : [
{

View File

@ -437,6 +437,7 @@ public final class ObjectParser<Value, Context> extends AbstractObjectParser<Val
OBJECT_ARRAY(START_OBJECT, START_ARRAY),
OBJECT_OR_BOOLEAN(START_OBJECT, VALUE_BOOLEAN),
OBJECT_OR_STRING(START_OBJECT, VALUE_STRING),
OBJECT_OR_LONG(START_OBJECT, VALUE_NUMBER),
OBJECT_ARRAY_BOOLEAN_OR_STRING(START_OBJECT, START_ARRAY, VALUE_BOOLEAN, VALUE_STRING),
OBJECT_ARRAY_OR_STRING(START_OBJECT, START_ARRAY, VALUE_STRING),
VALUE(VALUE_BOOLEAN, VALUE_NULL, VALUE_EMBEDDED_OBJECT, VALUE_NUMBER, VALUE_STRING),

View File

@ -34,12 +34,14 @@
- do:
search:
rest_total_hits_as_int: true
index: empty_bucket_idx
- match: {hits.total: 2}
- do:
search:
rest_total_hits_as_int: true
index: empty_bucket_idx
body: {"aggs": {"histo": {"histogram": {"field": "val1", "interval": 1, "min_doc_count": 0}, "aggs": { "mfs" : { "matrix_stats": {"fields": ["value", "val1"]} } } } } }

View File

@ -129,6 +129,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: unmapped
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "val3"]} } } }
@ -140,6 +141,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val3"]} } } }
@ -152,6 +154,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: [test, unmapped]
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "val3"]} } } }
@ -165,6 +168,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: [test, unmapped]
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "val3"], "missing" : {"val2" : 10} } } } }
@ -179,6 +183,7 @@ setup:
- do:
catch: /parsing_exception/
search:
rest_total_hits_as_int: true
index: test
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2"], "script" : { "my_script" : {"source" : "1 + doc['val1'].value", "lang" : "js"} } } } } }
@ -188,5 +193,6 @@ setup:
- do:
catch: /parsing_exception/
search:
rest_total_hits_as_int: true
index: test
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "val3"], "script" : { "my_script" : {"source" : "my_var + doc['val1'].value", "params" : { "my_var" : 1 }, "lang" : "js" } } } } } }

View File

@ -129,6 +129,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: unmapped
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "vals"]} } } }
@ -140,6 +141,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "vals"], "mode" : "max"} } } }
@ -153,6 +155,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "vals"], "mode" : "min"} } } }
@ -166,6 +169,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: [test, unmapped]
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "vals"]} } } }
@ -179,6 +183,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: [test, unmapped]
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "vals"], "missing" : {"val2" : 10, "vals" : 5 } } } } }
@ -193,6 +198,7 @@ setup:
- do:
catch: /parsing_exception/
search:
rest_total_hits_as_int: true
index: test
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["vals", "val3"], "script" : { "my_script" : {"source" : "1 + doc['val1'].value", "lang" : "js"} } } } } }
@ -202,5 +208,6 @@ setup:
- do:
catch: /parsing_exception/
search:
rest_total_hits_as_int: true
index: test
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val3", "vals"], "script" : { "my_script" : {"source" : "my_var + doc['val1'].value", "params" : { "my_var" : 1 }, "lang" : "js" } } } } } }

View File

@ -249,7 +249,7 @@ public class HighlighterWithAnalyzersTests extends ESIntegTestCase {
.highlighter(highlight().field("field1").order("score").preTags("<x>").postTags("</x>"));
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 <x>browse</x> button is a fancy thing, right <x>bro</x>?"),

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -33,6 +33,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
q: field:bars
analyzer: snowball

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -34,6 +34,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
suggest:

View File

@ -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);
}
}

View File

@ -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 }

View File

@ -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<String> 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) {

View File

@ -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<String> RESPONSE_PARAMS;
static {
final Set<String> responseParams = new HashSet<>(
Arrays.asList(RestSearchAction.TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HIT_AS_INT_PARAM)
);
final Set<String> responseParams = new HashSet<>(Arrays.asList(TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HIT_AS_INT_PARAM));
RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams);
}

View File

@ -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<Search
SearchResponse expectedResponse = expectedInstance.getResponse();
SearchResponse newResponse = newInstance.getResponse();
assertEquals(expectedResponse.getHits().totalHits, newResponse.getHits().totalHits);
assertEquals(expectedResponse.getHits().getTotalHits().value, newResponse.getHits().getTotalHits().value);
assertEquals(expectedResponse.getHits().getMaxScore(), newResponse.getHits().getMaxScore(), 0.0001);
}
}
@ -169,7 +170,7 @@ public class SearchTemplateResponseTests extends AbstractXContentTestCase<Search
SearchHit[] hits = new SearchHit[] { hit };
InternalSearchResponse internalSearchResponse = new InternalSearchResponse(
new SearchHits(hits, 100, 1.5f), null, null, null, false, null, 1);
new SearchHits(hits, new TotalHits(100, TotalHits.Relation.EQUAL_TO), 1.5f), null, null, null, false, null, 1);
SearchResponse searchResponse = new SearchResponse(internalSearchResponse, null,
0, 0, 0, 0, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY);
@ -188,7 +189,10 @@ public class SearchTemplateResponseTests extends AbstractXContentTestCase<Search
.field("failed", 0)
.endObject()
.startObject("hits")
.field("total", 100)
.startObject("total")
.field("value", 100)
.field("relation", "eq")
.endObject()
.field("max_score", 1.5F)
.startArray("hits")
.startObject()

View File

@ -129,5 +129,6 @@
- do:
search_template:
rest_total_hits_as_int: true
body: { "id" : "1", "params" : { "my_value" : "value1_foo", "my_size" : 1 } }
- match: { hits.total: 1 }

View File

@ -18,6 +18,7 @@
- do:
search_template:
rest_total_hits_as_int: true
body: { "source" : { "query": { "term": { "text": { "value": "{{template}}" } } } }, "params": { "template": "value1" } }
- match: { hits.total: 1 }
@ -30,11 +31,13 @@
- do:
search_template:
rest_total_hits_as_int: true
body: { "id" : "1", "params": { "template": "value1" } }
- match: { hits.total: 1 }
- do:
search_template:
rest_total_hits_as_int: true
body: { "source" : { "query": { "match_{{template}}": {} } }, "params" : { "template" : "all" } }
- match: { hits.total: 2 }
@ -45,6 +48,7 @@
- do:
catch: missing
search_template:
rest_total_hits_as_int: true
body: { "id" : "unknown", "params": { "template": "value1" } }
---
@ -97,6 +101,7 @@
- do:
search_template:
rest_total_hits_as_int: true
body: { "id" : "template_1", "params": { "size": "2", "field": "theField", "value": "foo" } }
- match: { hits.total: 4 }
@ -104,6 +109,7 @@
- do:
search_template:
rest_total_hits_as_int: true
body: { "id" : "template_1", "params": { "size": "2", "field": "otherField", "value": "foo" } }
- match: { hits.total: 1 }
@ -111,6 +117,7 @@
- do:
search_template:
rest_total_hits_as_int: true
body: { "id" : "template_1", "params": { "size": "2", "field": "otherField", "value": "foo" }, "explain" : true }
- match: { hits.total: 1 }
@ -119,6 +126,7 @@
- do:
search_template:
rest_total_hits_as_int: true
body: { "id" : "template_1", "params": { "size": "2", "field": "otherField", "value": "foo" }, "profile" : true }
- match: { hits.total: 1 }
@ -126,10 +134,10 @@
- length: { profile: 1 }
---
"Test with rest_total_hits_as_int":
"Test 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:
index:
@ -147,7 +155,8 @@
- do:
search_template:
rest_total_hits_as_int: true
body: { "id": "template_1", "params": {} }
- match: { hits.total: 0 }
- match: { hits.total.value: 0 }
- match: { hits.total.relation: eq }

View File

@ -37,6 +37,7 @@ setup:
- do:
msearch_template:
rest_total_hits_as_int: true
body:
- index: index_*
- source: '{"query": {"match": {"foo": "{{value}}"} } }'
@ -72,6 +73,7 @@ setup:
- do:
msearch_template:
rest_total_hits_as_int: true
body:
# Search 0 is OK
- index: index_*
@ -110,6 +112,7 @@ setup:
- do:
catch: /(.)*action_request_validation_exception(.)*template.is.missing(.)*/
msearch_template:
rest_total_hits_as_int: true
body:
# Search 0 is OK
- index: index_*
@ -136,6 +139,7 @@ setup:
- do:
msearch_template:
rest_total_hits_as_int: true
body:
- index: index_*
- id: stored_template_1
@ -167,8 +171,8 @@ setup:
---
"Test with rest_total_hits_as_int":
- 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:
put_script:
@ -178,7 +182,6 @@ setup:
- do:
msearch_template:
rest_total_hits_as_int: true
body:
- index: index_*
- id: stored_template_1
@ -196,7 +199,10 @@ setup:
field: "foo"
value: "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.1.hits.total.relation: eq }

View File

@ -60,6 +60,7 @@ setup:
- do:
search_template:
rest_total_hits_as_int: true
index: test-*
typed_keys: true
body:
@ -103,6 +104,7 @@ setup:
- do:
msearch_template:
rest_total_hits_as_int: true
typed_keys: true
body:
- index: test-*

View File

@ -35,6 +35,7 @@ setup:
"Scripted Field":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
bar:
@ -49,6 +50,7 @@ setup:
"Scripted Field Doing Compare":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
bar:
@ -61,6 +63,7 @@ setup:
- match: { hits.hits.0.fields.bar.0: true}
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
bar:
@ -76,6 +79,7 @@ setup:
"Scripted Field with a null safe dereference (non-null)":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
bar:
@ -90,6 +94,7 @@ setup:
"Scripted Field with a null safe dereference (null)":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
bar:
@ -104,6 +109,7 @@ setup:
"Access a date":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
bar:
@ -116,6 +122,7 @@ setup:
"Access many dates":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
bar:
@ -134,6 +141,7 @@ setup:
- do:
catch: bad_request
search:
rest_total_hits_as_int: true
body:
script_fields:
bar:

View File

@ -24,6 +24,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:
@ -71,6 +73,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -97,6 +100,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -128,6 +132,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -150,6 +155,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -172,6 +178,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -194,6 +201,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -216,6 +224,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -238,6 +247,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -275,6 +285,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -326,6 +337,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -365,6 +377,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
script_fields:
@ -392,6 +405,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
aggs:
@ -429,6 +443,7 @@
- do:
catch: bad_request
search:
rest_total_hits_as_int: true
index: test
body:
aggs:
@ -463,6 +478,7 @@
- do:
catch: bad_request
search:
rest_total_hits_as_int: true
index: test
allow_partial_search_results: false
body:

View File

@ -67,6 +67,7 @@ setup:
"boolean":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -76,6 +77,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -90,6 +92,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -99,6 +102,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -110,6 +114,7 @@ setup:
"geo_point":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -120,6 +125,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -132,6 +138,7 @@ setup:
"ip":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -141,6 +148,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -152,6 +160,7 @@ setup:
"keyword":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -161,6 +170,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -175,6 +185,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -184,6 +195,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -195,6 +207,7 @@ setup:
"integer":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -204,6 +217,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -215,6 +229,7 @@ setup:
"short":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -224,6 +239,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -235,6 +251,7 @@ setup:
"byte":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -244,6 +261,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -255,6 +273,7 @@ setup:
"double":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -264,6 +283,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -275,6 +295,7 @@ setup:
"float":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -284,6 +305,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -295,6 +317,7 @@ setup:
"half_float":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -304,6 +327,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -315,6 +339,7 @@ setup:
"scaled_float":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -324,6 +349,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -335,6 +361,7 @@ setup:
"token_count":
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -344,6 +371,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:

View File

@ -29,6 +29,7 @@
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:
@ -38,6 +39,7 @@
- do:
search:
rest_total_hits_as_int: true
body:
script_fields:
field:

View File

@ -66,6 +66,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
@ -97,6 +98,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
@ -128,6 +130,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
@ -159,6 +162,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
@ -185,6 +189,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
@ -211,6 +216,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
@ -237,6 +243,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
@ -263,6 +270,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
@ -288,6 +296,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:

View File

@ -42,6 +42,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -53,6 +54,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -94,6 +96,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -113,6 +116,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -131,6 +135,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -177,6 +182,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -196,6 +202,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -214,6 +221,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -269,6 +277,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -287,6 +296,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -305,6 +315,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -323,6 +334,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -341,6 +353,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -359,6 +372,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -377,6 +391,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -395,6 +410,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -413,6 +429,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -431,6 +448,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -449,6 +467,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
@ -467,6 +486,7 @@ setup:
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:

View File

@ -190,7 +190,7 @@ public class TokenCountFieldMapperIntegrationIT extends ESIntegTestCase {
}
private void assertSearchReturns(SearchResponse result, String... ids) {
assertThat(result.getHits().getTotalHits(), equalTo((long) ids.length));
assertThat(result.getHits().getTotalHits().value, equalTo((long) ids.length));
assertThat(result.getHits().getHits().length, equalTo(ids.length));
List<String> foundIds = new ArrayList<>();
for (SearchHit hit : result.getHits()) {

View File

@ -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:

View File

@ -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:

View File

@ -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 }

View File

@ -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;

View File

@ -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"));
}

View File

@ -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<String> 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));

View File

@ -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"));
}

View File

@ -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" }

View File

@ -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:

View File

@ -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:

View File

@ -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<Object[], XContentType> 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"));
}

View File

@ -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);

View File

@ -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());

View File

@ -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 }

View File

@ -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 }

View File

@ -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 }

View File

@ -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 }

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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 }

View File

@ -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:

View File

@ -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();

View File

@ -36,6 +36,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:

View File

@ -24,6 +24,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:

View File

@ -24,6 +24,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:

View File

@ -36,6 +36,7 @@
- do:
search:
rest_total_hits_as_int: true
index: phonetic_sample
body:
query:

View File

@ -24,6 +24,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:

View File

@ -24,6 +24,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:

View File

@ -24,6 +24,7 @@
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:

Some files were not shown because too many files have changed in this diff Show More