Multi Search API: Allow to set search_type on REST endpoint URI to apply to all search requests, closes #2023.
This commit is contained in:
parent
cf1fd26346
commit
133bd72f8d
|
@ -62,7 +62,8 @@ public class MultiSearchRequest implements ActionRequest {
|
|||
return this;
|
||||
}
|
||||
|
||||
public MultiSearchRequest add(byte[] data, int from, int length, boolean contentUnsafe, @Nullable String[] indices, @Nullable String[] types) throws Exception {
|
||||
public MultiSearchRequest add(byte[] data, int from, int length, boolean contentUnsafe,
|
||||
@Nullable String[] indices, @Nullable String[] types, @Nullable String searchType) throws Exception {
|
||||
XContent xContent = XContentFactory.xContent(data, from, length);
|
||||
byte marker = xContent.streamSeparator();
|
||||
while (true) {
|
||||
|
@ -80,6 +81,7 @@ public class MultiSearchRequest implements ActionRequest {
|
|||
if (types != null && types.length > 0) {
|
||||
searchRequest.types(types);
|
||||
}
|
||||
searchRequest.searchType(searchType);
|
||||
|
||||
// now parse the action
|
||||
if (nextMarker - from > 0) {
|
||||
|
|
|
@ -62,7 +62,8 @@ public class RestMultiSearchAction extends BaseRestHandler {
|
|||
String[] types = RestActions.splitTypes(request.param("type"));
|
||||
|
||||
try {
|
||||
multiSearchRequest.add(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength(), request.contentUnsafe(), indices, types);
|
||||
multiSearchRequest.add(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength(), request.contentUnsafe(),
|
||||
indices, types, request.param("search_type"));
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
XContentBuilder builder = restContentBuilder(request);
|
||||
|
|
|
@ -36,7 +36,7 @@ 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);
|
||||
MultiSearchRequest request = new MultiSearchRequest().add(data, 0, data.length, false, null, 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));
|
||||
|
@ -54,7 +54,7 @@ public class MultiSearchRequestTests {
|
|||
@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);
|
||||
MultiSearchRequest request = new MultiSearchRequest().add(data, 0, data.length, false, null, 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));
|
||||
|
|
Loading…
Reference in New Issue