fixed issue2371 (incorrect behavior of path_match)
This commit is contained in:
parent
768b8b4d2b
commit
bd9a5bfa0c
|
@ -520,16 +520,16 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
|
|||
objectMapper = mappers.get(currentFieldName);
|
||||
if (objectMapper == null) {
|
||||
newMapper = true;
|
||||
// remove the current field name from path, since template search and the object builder add it as well...
|
||||
context.path().remove();
|
||||
Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "object");
|
||||
if (builder == null) {
|
||||
builder = MapperBuilders.object(currentFieldName).enabled(true).dynamic(dynamic).pathType(pathType);
|
||||
}
|
||||
// remove the current field name from path, since the object builder adds it as well...
|
||||
context.path().remove();
|
||||
BuilderContext builderContext = new BuilderContext(context.indexSettings(), context.path());
|
||||
objectMapper = builder.build(builderContext);
|
||||
putMapper(objectMapper);
|
||||
// now re add it
|
||||
// ...now re add it
|
||||
context.path().add(currentFieldName);
|
||||
context.setMappingsModified();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.test.unit.index.mapper.dynamictemplate.pathmatch;
|
|||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.index.field.data.strings.StringFieldDataType;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.FieldMappers;
|
||||
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
||||
|
@ -31,11 +32,12 @@ import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
|
|||
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PathMatchDynamicTempalteTests {
|
||||
public class PathMatchDynamicTemplateTests {
|
||||
|
||||
@Test
|
||||
public void testSimple() throws Exception {
|
||||
|
@ -68,5 +70,11 @@ public class PathMatchDynamicTempalteTests {
|
|||
fieldMappers = docMapper.mappers().fullName("obj1.obj2.name");
|
||||
assertThat(fieldMappers.mappers().size(), equalTo(1));
|
||||
assertThat(fieldMappers.mapper().stored(), equalTo(false));
|
||||
|
||||
// verify more complex path_match expressions
|
||||
|
||||
fieldMappers = docMapper.mappers().fullName("obj3.obj4.prop1");
|
||||
assertThat(fieldMappers.mappers().size(), equalTo(1));
|
||||
assertThat(fieldMappers.mapper().fieldDataType(), instanceOf(StringFieldDataType.class));
|
||||
}
|
||||
}
|
|
@ -6,5 +6,10 @@
|
|||
"obj2":{
|
||||
"name":"obj2_level"
|
||||
}
|
||||
},
|
||||
"obj3":{
|
||||
"obj4":{
|
||||
"prop1":"prop1_value"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,14 @@
|
|||
"store":"yes"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"template_3":{
|
||||
"path_match":"*.obj4.*",
|
||||
"mapping":{
|
||||
"type":"string"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue