Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.http.client.methods.HttpPut;
import org.apache.http.nio.entity.NByteArrayEntity;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
Expand Down Expand Up @@ -62,6 +63,7 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
Expand Down Expand Up @@ -132,6 +134,10 @@
import static org.hamcrest.Matchers.nullValue;

public class RequestConvertersTests extends ESTestCase {

private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
LogManager.getLogger(RequestConvertersTests.class));

public void testPing() {
Request request = RequestConverters.ping();
assertEquals("/", request.getEndpoint());
Expand Down Expand Up @@ -1256,7 +1262,7 @@ public void testMultiSearch() throws IOException {
};
MultiSearchRequest.readMultiLineFormat(new BytesArray(EntityUtils.toByteArray(request.getEntity())),
REQUEST_BODY_CONTENT_TYPE.xContent(), consumer, null, multiSearchRequest.indicesOptions(), null, null, null, null,
xContentRegistry(), true);
xContentRegistry(), true, deprecationLogger);
assertEquals(requests, multiSearchRequest.requests());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
Expand Down Expand Up @@ -175,7 +176,8 @@ public static void readMultiLineFormat(BytesReference data,
String searchType,
Boolean ccsMinimizeRoundtrips,
NamedXContentRegistry registry,
boolean allowExplicitIndex) throws IOException {
boolean allowExplicitIndex,
DeprecationLogger deprecationLogger) throws IOException {
int from = 0;
byte marker = xContent.streamSeparator();
while (true) {
Expand All @@ -186,6 +188,8 @@ public static void readMultiLineFormat(BytesReference data,
// support first line with \n
if (nextMarker == 0) {
from = nextMarker + 1;
deprecationLogger.deprecated("support for empty first line before any action metadata in msearch API is deprecated and " +
"will be removed in the next major version");
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static void parseMultiLineRequest(RestRequest request, IndicesOptions ind
final XContent xContent = sourceTuple.v1().xContent();
final BytesReference data = sourceTuple.v2();
MultiSearchRequest.readMultiLineFormat(data, xContent, consumer, indices, indicesOptions, types, routing,
searchType, ccsMinimizeRoundtrips, request.getXContentRegistry(), allowExplicitIndex);
searchType, ccsMinimizeRoundtrips, request.getXContentRegistry(), allowExplicitIndex, deprecationLogger);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

package org.elasticsearch.action.search;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.CheckedBiConsumer;
import org.elasticsearch.common.CheckedRunnable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
Expand All @@ -48,10 +50,15 @@
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;

public class MultiSearchRequestTests extends ESTestCase {

private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
LogManager.getLogger(MultiSearchRequestTests.class));

public void testSimpleAdd() throws Exception {
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/simple-msearch1.json");
assertThat(request.requests().size(),
Expand Down Expand Up @@ -180,6 +187,28 @@ public void testSimpleAdd4() throws Exception {
assertThat(request.requests().get(2).routing(), equalTo("123"));
}

public void testEmptyFirstLine1() throws Exception {
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/msearch-empty-first-line1.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));
}
assertWarnings("support for empty first line before any action metadata in msearch API is deprecated and will be removed " +
"in the next major version");
}

public void testEmptyFirstLine2() throws Exception {
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/msearch-empty-first-line2.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));
}
assertWarnings("support for empty first line before any action metadata in msearch API is deprecated and will be removed " +
"in the next major version");
}

public void testResponseErrorToXContent() {
long tookInMillis = randomIntBetween(1, 1000);
MultiSearchResponse response = new MultiSearchResponse(
Expand Down Expand Up @@ -262,7 +291,7 @@ public void testMultiLineSerialization() throws IOException {
parsedRequest.add(r);
};
MultiSearchRequest.readMultiLineFormat(new BytesArray(originalBytes), xContentType.xContent(),
consumer, null, null, null, null, null, null, xContentRegistry(), true);
consumer, null, null, null, null, null, null, xContentRegistry(), true, deprecationLogger);
assertEquals(originalRequest, parsedRequest);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


{ "query": {"match_all": {}}}
{}
{ "query": {"match_all": {}}}

{ "query": {"match_all": {}}}
{}
{ "query": {"match_all": {}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

{}
{ "query": {"match_all": {}}}

{ "query": {"match_all": {}}}
{}
{ "query": {"match_all": {}}}

{ "query": {"match_all": {}}}