msearch should accept a leading \n, closes #1736.

This commit is contained in:
Shay Banon 2012-02-27 00:27:43 +02:00
parent 9a51179c22
commit c72772e621
5 changed files with 46 additions and 0 deletions

View File

@ -70,6 +70,11 @@ public class MultiSearchRequest implements ActionRequest {
if (nextMarker == -1) {
break;
}
// support first line with \n
if (nextMarker == 0) {
from = nextMarker + 1;
continue;
}
SearchRequest searchRequest = new SearchRequest(indices);
if (types != null && types.length > 0) {

View File

@ -43,4 +43,12 @@ public class BulkRequestTests {
bulkRequest.add(bulkAction.getBytes(), 0, bulkAction.length(), true, null, null);
assertThat(bulkRequest.numberOfActions(), equalTo(3));
}
@Test
public void testSimpleBulk3() throws Exception {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/test/unit/action/bulk/simple-bulk3.json");
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(bulkAction.getBytes(), 0, bulkAction.length(), true, null, null);
assertThat(bulkRequest.numberOfActions(), equalTo(3));
}
}

View File

@ -0,0 +1,5 @@
{ "index":{ } }
{ "field1" : "value1" }
{ "delete" : { "_id" : "2" } }
{ "create" : { "_id" : "3" } }
{ "field1" : "value3" }

View File

@ -50,4 +50,22 @@ public class MultiSearchRequestTests {
assertThat(request.requests().get(4).indices(), nullValue());
assertThat(request.requests().get(4).types().length, equalTo(0));
}
@Test
public void simpleAdd2() throws Exception {
byte[] data = Streams.copyToBytesFromClasspath("/org/elasticsearch/test/unit/action/search/simple-msearch2.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));
}
}

View File

@ -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" {}}}