allow to provide no header (but still \n) for msearch
This commit is contained in:
parent
4a9cb6408c
commit
c6130b95e5
|
@ -70,24 +70,19 @@ public class MultiSearchRequest implements ActionRequest {
|
|||
if (nextMarker == -1) {
|
||||
break;
|
||||
}
|
||||
// now parse the action
|
||||
XContentParser parser = xContent.createParser(data, from, nextMarker - from);
|
||||
|
||||
// move pointers
|
||||
from = nextMarker + 1;
|
||||
|
||||
// Move to START_OBJECT
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
if (token == null) {
|
||||
continue;
|
||||
}
|
||||
assert token == XContentParser.Token.START_OBJECT;
|
||||
|
||||
|
||||
SearchRequest searchRequest = new SearchRequest(indices);
|
||||
if (types != null && types.length > 0) {
|
||||
searchRequest.types(types);
|
||||
}
|
||||
|
||||
// now parse the action
|
||||
XContentParser parser = xContent.createParser(data, from, nextMarker - from);
|
||||
try {
|
||||
// Move to START_OBJECT, if token is null, its an empty data
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
if (token != null) {
|
||||
assert token == XContentParser.Token.START_OBJECT;
|
||||
String currentFieldName = null;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
|
@ -108,7 +103,13 @@ public class MultiSearchRequest implements ActionRequest {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
parser.close();
|
||||
}
|
||||
|
||||
// move pointers
|
||||
from = nextMarker + 1;
|
||||
// now for the body
|
||||
nextMarker = findNextMarker(marker, from, data, length);
|
||||
if (nextMarker == -1) {
|
||||
|
@ -134,7 +135,7 @@ public class MultiSearchRequest implements ActionRequest {
|
|||
return -1;
|
||||
}
|
||||
|
||||
List<SearchRequest> requests() {
|
||||
public List<SearchRequest> requests() {
|
||||
return this.requests;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class BulkActionTests {
|
||||
public class BulkRequestTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleBulk1() throws Exception {
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Licensed to ElasticSearch and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. ElasticSearch licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.test.unit.action.search;
|
||||
|
||||
import org.elasticsearch.action.search.MultiSearchRequest;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.common.io.Streams;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Test
|
||||
public class MultiSearchRequestTests {
|
||||
|
||||
@Test
|
||||
public void simpleAdd() throws Exception {
|
||||
byte[] data = Streams.copyToBytesFromClasspath("/org/elasticsearch/test/unit/action/search/simple-msearch1.json");
|
||||
MultiSearchRequest request = new MultiSearchRequest().add(data, 0, data.length, false, null, null);
|
||||
assertThat(request.requests().size(), equalTo(5));
|
||||
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
|
||||
assertThat(request.requests().get(0).types().length, equalTo(0));
|
||||
assertThat(request.requests().get(1).indices()[0], equalTo("test"));
|
||||
assertThat(request.requests().get(1).types()[0], equalTo("type1"));
|
||||
assertThat(request.requests().get(2).indices(), nullValue());
|
||||
assertThat(request.requests().get(2).types().length, equalTo(0));
|
||||
assertThat(request.requests().get(3).indices(), nullValue());
|
||||
assertThat(request.requests().get(3).types().length, equalTo(0));
|
||||
assertThat(request.requests().get(3).searchType(), equalTo(SearchType.COUNT));
|
||||
assertThat(request.requests().get(4).indices(), nullValue());
|
||||
assertThat(request.requests().get(4).types().length, equalTo(0));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{"index":"test"}
|
||||
{"query" : {"match_all" {}}}
|
||||
{"index" : "test", "type" : "type1"}
|
||||
{"query" : {"match_all" {}}}
|
||||
{}
|
||||
{"query" : {"match_all" {}}}
|
||||
{"search_type" : "count"}
|
||||
{"query" : {"match_all" {}}}
|
||||
|
||||
{"query" : {"match_all" {}}}
|
Loading…
Reference in New Issue