[HLRC] Send min_score as query string parameter to the count API (#46829)

Prior to this commit min_score was sent as request body parameter
(via SearchSourceBuilder), which is not possible in the count api.

Similar to #46474
This commit is contained in:
Martijn van Groningen 2019-09-20 09:57:35 +02:00
parent add7148f3b
commit d82712417f
No known key found for this signature in database
GPG Key ID: AB236F4FCF2AF12A
3 changed files with 11 additions and 3 deletions

View File

@ -501,6 +501,9 @@ final class RequestConverters {
if (countRequest.terminateAfter() != 0){ if (countRequest.terminateAfter() != 0){
params.withTerminateAfter(countRequest.terminateAfter()); params.withTerminateAfter(countRequest.terminateAfter());
} }
if (countRequest.minScore() != null){
params.putParam("min_score", String.valueOf(countRequest.minScore()));
}
request.addParameters(params.asMap()); request.addParameters(params.asMap());
request.setEntity(createEntity(countRequest.source(), REQUEST_BODY_CONTENT_TYPE)); request.setEntity(createEntity(countRequest.source(), REQUEST_BODY_CONTENT_TYPE));
return request; return request;

View File

@ -44,6 +44,7 @@ public final class CountRequest extends ActionRequest implements IndicesRequest.
private SearchSourceBuilder searchSourceBuilder; private SearchSourceBuilder searchSourceBuilder;
private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS;
private int terminateAfter = SearchContext.DEFAULT_TERMINATE_AFTER; private int terminateAfter = SearchContext.DEFAULT_TERMINATE_AFTER;
private Float minScore;
public CountRequest() { public CountRequest() {
this.searchSourceBuilder = new SearchSourceBuilder(); this.searchSourceBuilder = new SearchSourceBuilder();
@ -158,11 +159,11 @@ public final class CountRequest extends ActionRequest implements IndicesRequest.
} }
public Float minScore() { public Float minScore() {
return this.searchSourceBuilder.minScore(); return minScore;
} }
public CountRequest minScore(Float minScore) { public CountRequest minScore(Float minScore) {
this.searchSourceBuilder.minScore(minScore); this.minScore = minScore;
return this; return this;
} }

View File

@ -1234,10 +1234,14 @@ public class RequestConvertersTests extends ESTestCase {
countRequest.preference(randomAlphaOfLengthBetween(3, 10)); countRequest.preference(randomAlphaOfLengthBetween(3, 10));
expectedParams.put("preference", countRequest.preference()); expectedParams.put("preference", countRequest.preference());
} }
if (randomBoolean()){ if (randomBoolean()) {
countRequest.terminateAfter(randomIntBetween(0, Integer.MAX_VALUE)); countRequest.terminateAfter(randomIntBetween(0, Integer.MAX_VALUE));
expectedParams.put("terminate_after", String.valueOf(countRequest.terminateAfter())); expectedParams.put("terminate_after", String.valueOf(countRequest.terminateAfter()));
} }
if (randomBoolean()) {
countRequest.minScore((float) randomIntBetween(1, 10));
expectedParams.put("min_score", String.valueOf(countRequest.minScore()));
}
} }
public void testMultiSearch() throws IOException { public void testMultiSearch() throws IOException {