diff --git a/src/main/java/org/elasticsearch/action/percolate/MultiPercolateRequest.java b/src/main/java/org/elasticsearch/action/percolate/MultiPercolateRequest.java index c1b3d036b62..46f5c2d843a 100644 --- a/src/main/java/org/elasticsearch/action/percolate/MultiPercolateRequest.java +++ b/src/main/java/org/elasticsearch/action/percolate/MultiPercolateRequest.java @@ -199,6 +199,20 @@ public class MultiPercolateRequest extends ActionRequest percolateRequest.ignoreIndices(IgnoreIndices.fromString((String) value)); } } + + // Setting values based on get request, if needed... + if ((percolateRequest.indices() == null || percolateRequest.indices().length == 0) && getRequest.index() != null) { + percolateRequest.indices(getRequest.index()); + } + if (percolateRequest.documentType() == null && getRequest.type() != null) { + percolateRequest.documentType(getRequest.type()); + } + if (percolateRequest.routing() == null && getRequest.routing() != null) { + percolateRequest.routing(getRequest.routing()); + } + if (percolateRequest.preference() == null && getRequest.preference() != null) { + percolateRequest.preference(getRequest.preference()); + } } else { for (Map.Entry entry : header.entrySet()) { Object value = entry.getValue(); @@ -219,20 +233,6 @@ public class MultiPercolateRequest extends ActionRequest } } } - - // Setting defaults, if needed... - if ((percolateRequest.indices() == null || percolateRequest.indices().length == 0) && percolateRequest.getRequest().index() != null) { - percolateRequest.indices(percolateRequest.getRequest().index()); - } - if (percolateRequest.documentType() == null && percolateRequest.getRequest().type() != null) { - percolateRequest.documentType(percolateRequest.getRequest().type()); - } - if (percolateRequest.routing() == null && percolateRequest.getRequest().routing() != null) { - percolateRequest.routing(percolateRequest.getRequest().routing()); - } - if (percolateRequest.preference() == null && percolateRequest.getRequest().preference() != null) { - percolateRequest.preference(percolateRequest.getRequest().preference()); - } } private String[] parseArray(XContentParser parser) throws IOException { diff --git a/src/test/java/org/elasticsearch/action/percolate/MultiPercolatorRequestTests.java b/src/test/java/org/elasticsearch/action/percolate/MultiPercolatorRequestTests.java index 2a0fdf7bbb2..164f5bdd386 100644 --- a/src/test/java/org/elasticsearch/action/percolate/MultiPercolatorRequestTests.java +++ b/src/test/java/org/elasticsearch/action/percolate/MultiPercolatorRequestTests.java @@ -125,7 +125,7 @@ public class MultiPercolatorRequestTests extends ElasticsearchTestCase { request.indices("my-index1").documentType("my-type1").ignoreIndices(IgnoreIndices.MISSING); request.add(data, 0, data.length, false); - assertThat(request.requests().size(), equalTo(2)); + assertThat(request.requests().size(), equalTo(3)); PercolateRequest percolateRequest = request.requests().get(0); assertThat(percolateRequest.indices()[0], equalTo("my-index1")); assertThat(percolateRequest.documentType(), equalTo("my-type1")); @@ -149,6 +149,16 @@ public class MultiPercolatorRequestTests extends ElasticsearchTestCase { assertThat(percolateRequest.source(), notNullValue()); sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map(); assertThat(sourceMap.get("doc"), equalTo((Object)MapBuilder.newMapBuilder().put("field1", "value2").map())); + + percolateRequest = request.requests().get(2); + assertThat(percolateRequest.indices()[0], equalTo("my-index1")); + assertThat(percolateRequest.documentType(), equalTo("my-type1")); + assertThat(percolateRequest.ignoreIndices(), equalTo(IgnoreIndices.MISSING)); + assertThat(percolateRequest.onlyCount(), equalTo(false)); + assertThat(percolateRequest.getRequest(), nullValue()); + assertThat(percolateRequest.source(), notNullValue()); + sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map(); + assertThat(sourceMap.get("doc"), equalTo((Object)MapBuilder.newMapBuilder().put("field1", "value3").map())); } } diff --git a/src/test/java/org/elasticsearch/action/percolate/mpercolate2.json b/src/test/java/org/elasticsearch/action/percolate/mpercolate2.json index 8d5acf492d7..27899a45152 100644 --- a/src/test/java/org/elasticsearch/action/percolate/mpercolate2.json +++ b/src/test/java/org/elasticsearch/action/percolate/mpercolate2.json @@ -2,3 +2,5 @@ {"doc" : {"field1" : "value1"}} {"percolate" : {"index" : "my-index1", "type" : "my-type1", "routing" : "my-routing-1", "preference" : "_local", "ignore_indices" : "missing"}} {"doc" : {"field1" : "value2"}} +{"percolate" : {}} +{"doc" : {"field1" : "value3"}}