Fixed bug (NPE) in mpercolate api, defaults from percolating existing documents where also applied for the regular percolate api, these defaults were none existing (null).

This commit is contained in:
Martijn van Groningen 2013-11-01 11:17:16 +01:00
parent 65fc90728e
commit d660b18298
3 changed files with 27 additions and 15 deletions

View File

@ -199,6 +199,20 @@ public class MultiPercolateRequest extends ActionRequest<MultiPercolateRequest>
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<String, Object> entry : header.entrySet()) {
Object value = entry.getValue();
@ -219,20 +233,6 @@ public class MultiPercolateRequest extends ActionRequest<MultiPercolateRequest>
}
}
}
// 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 {

View File

@ -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()));
}
}

View File

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