Merge pull request #12214 from martijnvg/percolator/_parent_field/npe

Fix NPE when percolating a document that has a _parent field configured in its mapping
This commit is contained in:
Martijn van Groningen 2015-07-14 10:31:10 +02:00
commit 44275f3e3e
2 changed files with 20 additions and 2 deletions

View File

@ -249,7 +249,9 @@ public class ParentFieldMapper extends MetadataFieldMapper {
@Override
public void postParse(ParseContext context) throws IOException {
parse(context);
if (context.sourceToParse().flyweight() == false) {
parse(context);
}
}
@Override

View File

@ -2054,7 +2054,7 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
@Test
public void testParentChild() throws Exception {
// We don't fail p/c queries, but those queries are unsuable because only one document can be provided in
// We don't fail p/c queries, but those queries are unusable because only a single document can be provided in
// the percolate api
assertAcked(prepareCreate("index").addMapping("child", "_parent", "type=parent").addMapping("parent"));
@ -2063,5 +2063,21 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
.execute().actionGet();
}
@Test
public void testPercolateDocumentWithParentField() throws Exception {
assertAcked(prepareCreate("index").addMapping("child", "_parent", "type=parent").addMapping("parent"));
client().prepareIndex("index", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
// Just percolating a document that has a _parent field in its mapping should just work:
PercolateResponse response = client().preparePercolate()
.setDocumentType("parent")
.setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("field", "value"))
.get();
assertMatchCount(response, 1);
assertThat(response.getMatches()[0].getId().string(), equalTo("1"));
}
}