Only log one types warning per bulk search request. (#37446)

This commit is contained in:
Julie Tibshirani 2019-01-15 12:38:32 -08:00 committed by GitHub
parent e7511753a9
commit 0a3bff2ca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 8 deletions

View File

@ -79,6 +79,14 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler {
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
MultiSearchTemplateRequest multiRequest = parseRequest(request, allowExplicitIndex);
// Emit a single deprecation message if any search template contains types.
for (SearchTemplateRequest searchTemplateRequest : multiRequest.requests()) {
if (searchTemplateRequest.getRequest().types().length > 0) {
deprecationLogger.deprecatedAndMaybeLog("msearch_with_types", TYPES_DEPRECATION_MESSAGE);
break;
}
}
return channel -> client.execute(MultiSearchTemplateAction.INSTANCE, multiRequest, new RestToXContentListener<>(channel));
}
@ -93,9 +101,6 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler {
RestMultiSearchAction.parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex,
(searchRequest, bytes) -> {
if (searchRequest.types().length > 0) {
deprecationLogger.deprecatedAndMaybeLog("msearch_template_with_types", TYPES_DEPRECATION_MESSAGE);
}
SearchTemplateRequest searchTemplateRequest = SearchTemplateRequest.fromXContent(bytes);
if (searchTemplateRequest.getScript() != null) {
searchTemplateRequest.setRequest(searchRequest);

View File

@ -77,8 +77,6 @@ public class MultiSearchTemplateRequestTests extends ESTestCase {
assertEquals(1, request.requests().get(0).getScriptParams().size());
assertEquals(1, request.requests().get(1).getScriptParams().size());
assertEquals(1, request.requests().get(2).getScriptParams().size());
assertWarnings(RestMultiSearchTemplateAction.TYPES_DEPRECATION_MESSAGE);
}
public void testParseWithCarriageReturn() throws Exception {

View File

@ -88,6 +88,14 @@ public class RestMultiSearchAction extends BaseRestHandler {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
MultiSearchRequest multiSearchRequest = parseRequest(request, allowExplicitIndex);
// Emit a single deprecation message if any search request contains types.
for (SearchRequest searchRequest : multiSearchRequest.requests()) {
if (searchRequest.types().length > 0) {
deprecationLogger.deprecatedAndMaybeLog("msearch_with_types", TYPES_DEPRECATION_MESSAGE);
break;
}
}
return channel -> client.multiSearch(multiSearchRequest, new RestToXContentListener<>(channel));
}
@ -114,9 +122,6 @@ public class RestMultiSearchAction extends BaseRestHandler {
}
parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, parser) -> {
if (searchRequest.types().length > 0) {
deprecationLogger.deprecatedAndMaybeLog("msearch_with_types", TYPES_DEPRECATION_MESSAGE);
}
searchRequest.source(SearchSourceBuilder.fromXContent(parser, false));
RestSearchAction.checkRestTotalHits(restRequest, searchRequest);
multiRequest.add(searchRequest);