From 472216f65176bc69bf061f3e7b0f705f0c74c596 Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Mon, 8 Apr 2019 16:40:59 +0200 Subject: [PATCH] Support empty first line in msearch request body Relates to #39841 --- .../action/search/MultiSearchRequest.java | 6 ------ .../action/search/MultiSearchRequestTests.java | 10 ++++++++++ .../action/search/msearch-no-metadata.json | 8 ++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 server/src/test/resources/org/elasticsearch/action/search/msearch-no-metadata.json diff --git a/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java b/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java index 195e146ab7ca1..528be0369166e 100644 --- a/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java +++ b/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java @@ -183,12 +183,6 @@ public static void readMultiLineFormat(BytesReference data, if (nextMarker == -1) { break; } - // support first line with \n - if (nextMarker == 0) { - from = nextMarker + 1; - continue; - } - SearchRequest searchRequest = new SearchRequest(); if (indices != null) { searchRequest.indices(indices); diff --git a/server/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java b/server/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java index da22ce4c96c1a..afe957e2bf3ee 100644 --- a/server/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java @@ -48,6 +48,7 @@ import static org.elasticsearch.search.RandomSearchRequestGenerator.randomSearchRequest; import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; @@ -180,6 +181,15 @@ public void testSimpleAdd4() throws Exception { assertThat(request.requests().get(2).routing(), equalTo("123")); } + public void testNoMetadata() throws Exception { + MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/msearch-no-metadata.json"); + assertThat(request.requests().size(), equalTo(4)); + for (SearchRequest searchRequest : request.requests()) { + assertThat(searchRequest.indices().length, equalTo(0)); + assertThat(searchRequest.source().query(), instanceOf(MatchAllQueryBuilder.class)); + } + } + public void testResponseErrorToXContent() { long tookInMillis = randomIntBetween(1, 1000); MultiSearchResponse response = new MultiSearchResponse( diff --git a/server/src/test/resources/org/elasticsearch/action/search/msearch-no-metadata.json b/server/src/test/resources/org/elasticsearch/action/search/msearch-no-metadata.json new file mode 100644 index 0000000000000..a13fa283eeccf --- /dev/null +++ b/server/src/test/resources/org/elasticsearch/action/search/msearch-no-metadata.json @@ -0,0 +1,8 @@ + +{ "query": {"match_all": {}}} + +{ "query": {"match_all": {}}} + +{ "query": {"match_all": {}}} + +{ "query": {"match_all": {}}}