Skip to content

Commit 266de98

Browse files
authored
Add rest_total_hits_as_int in HLRC's search request (#46076)
This commit adds a query parameter called rest_total_hits_as_int to all HLRC's search requests that support it (_search, _msearch, ...). This makes the HLRC client's search compatible with any node in version >= 6.6.0 since rest_total_hits_as_int has been added in 6.6.0. This means that nodes in version < 6.6.0 won't be able to handle search requests sent by an HLRC in version 6.8.3 but we already warn in the docs that the client is forward compatible only: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-compatibility.html Closes #43925
1 parent cfd70e9 commit 266de98

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ static Request search(SearchRequest searchRequest, String searchEndpoint) throws
392392

393393
private static void addSearchRequestParams(Params params, SearchRequest searchRequest) {
394394
params.putParam(RestSearchAction.TYPED_KEYS_PARAM, "true");
395+
params.putParam(RestSearchAction.TOTAL_HIT_AS_INT_PARAM, "true");
395396
params.withRouting(searchRequest.routing());
396397
params.withPreference(searchRequest.preference());
397398
params.withIndicesOptions(searchRequest.indicesOptions());
@@ -425,6 +426,7 @@ static Request multiSearch(MultiSearchRequest multiSearchRequest) throws IOExcep
425426

426427
Params params = new Params(request);
427428
params.putParam(RestSearchAction.TYPED_KEYS_PARAM, "true");
429+
params.putParam(RestSearchAction.TOTAL_HIT_AS_INT_PARAM, "true");
428430
if (multiSearchRequest.maxConcurrentSearchRequests() != MultiSearchRequest.MAX_CONCURRENT_SEARCH_REQUESTS_DEFAULT) {
429431
params.putParam("max_concurrent_searches", Integer.toString(multiSearchRequest.maxConcurrentSearchRequests()));
430432
}
@@ -458,6 +460,7 @@ static Request multiSearchTemplate(MultiSearchTemplateRequest multiSearchTemplat
458460

459461
Params params = new Params(request);
460462
params.putParam(RestSearchAction.TYPED_KEYS_PARAM, "true");
463+
params.putParam(RestSearchAction.TOTAL_HIT_AS_INT_PARAM, "true");
461464
if (multiSearchTemplateRequest.maxConcurrentSearchRequests() != MultiSearchRequest.MAX_CONCURRENT_SEARCH_REQUESTS_DEFAULT) {
462465
params.putParam("max_concurrent_searches", Integer.toString(multiSearchTemplateRequest.maxConcurrentSearchRequests()));
463466
}

client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ public void testMultiSearch() throws IOException {
11191119

11201120
Map<String, String> expectedParams = new HashMap<>();
11211121
expectedParams.put(RestSearchAction.TYPED_KEYS_PARAM, "true");
1122+
expectedParams.put(RestSearchAction.TOTAL_HIT_AS_INT_PARAM, "true");
11221123
if (randomBoolean()) {
11231124
multiSearchRequest.maxConcurrentSearchRequests(randomIntBetween(1, 8));
11241125
expectedParams.put("max_concurrent_searches", Integer.toString(multiSearchRequest.maxConcurrentSearchRequests()));
@@ -1733,6 +1734,7 @@ private static void setRandomSearchParams(SearchRequest searchRequest,
17331734
searchRequest.scroll(randomTimeValue());
17341735
expectedParams.put("scroll", searchRequest.scroll().keepAlive().getStringRep());
17351736
}
1737+
expectedParams.put(RestSearchAction.TOTAL_HIT_AS_INT_PARAM, "true");
17361738
}
17371739

17381740
static void setRandomIndicesOptions(Consumer<IndicesOptions> setter, Supplier<IndicesOptions> getter,

0 commit comments

Comments
 (0)