From 8958e9fd4a671564e179732172b92fc37877cccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Dev=C3=A8ze?= Date: Fri, 2 Sep 2011 12:07:03 +0200 Subject: [PATCH] fix bug in parent handling where the parsed parent value was not set in the SourceToParse --- .../index/mapper/internal/ParentFieldMapper.java | 1 + .../elasticsearch/index/mapper/parent/ParentMappingTests.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java index 1efcb38e0c3..9883a761343 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java @@ -122,6 +122,7 @@ public class ParentFieldMapper extends AbstractFieldMapper implements Inter if (context.parser().currentName() != null && context.parser().currentName().equals(Defaults.NAME)) { // we are in the parsing of _parent phase String parentId = context.parser().text(); + context.sourceToParse().parent(parentId); return new Field(names.indexName(), Uid.createUid(context.stringBuilder(), type, parentId), store, index); } // otherwise, we are running it post processing of the xcontent diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/parent/ParentMappingTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/parent/ParentMappingTests.java index 87dfc10af7f..25be48f2ca9 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/parent/ParentMappingTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/parent/ParentMappingTests.java @@ -48,6 +48,7 @@ public class ParentMappingTests { .copiedBytes()).type("type").id("1")); // no _parent mapping, used as a simple field + assertThat(doc.parent(), equalTo(null)); assertThat(doc.rootDoc().get("_parent"), equalTo("1122")); } @@ -63,7 +64,8 @@ public class ParentMappingTests { .field("x_field", "x_value") .endObject() .copiedBytes()).type("type").id("1")); - + + assertThat(doc.parent(), equalTo("1122")); assertThat(doc.rootDoc().get("_parent"), equalTo(Uid.createUid("p_type", "1122"))); }