Skip to content

Commit

Permalink
Use absolute field name when filtering mappings instead of just paren…
Browse files Browse the repository at this point in the history
…t name

fixes elastic#1139
  • Loading branch information
jbaiera committed Apr 20, 2018
1 parent 31e8906 commit 6e88f3b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Expand Up @@ -73,7 +73,7 @@ private static boolean filterField(Field field, String parentName, List<Field> f
if (FieldType.isCompound(field.type())) {
List<Field> nested = new ArrayList<Field>();
for (Field nestedField : field.properties()) {
intact &= filterField(nestedField, field.name(), nested, includes, excludes);
intact &= filterField(nestedField, fieldName, nested, includes, excludes);
}
filtered.add(new Field(field.name(), field.type(), nested));
}
Expand Down
Expand Up @@ -180,6 +180,26 @@ public void testFieldInclude() throws Exception {
assertThat(props[1].name(), is("name"));
}

@Test
public void testFieldNestedInclude() throws Exception {
Map value = new ObjectMapper().readValue(getClass().getResourceAsStream("multi_level_field_with_same_name.json"), Map.class);
MappingSet mappings = parseMapping(value);
Mapping mapping = mappings.getMapping("index", "artiststimestamp");

Mapping filtered = mapping.filter(Collections.singleton("links.image.url"), Collections.<String> emptyList());

assertThat(mapping.getName(), is(filtered.getName()));

Field[] props = filtered.getFields();

assertThat(props.length, is(1));
assertThat(props[0].name(), is("links"));
assertThat(props[0].properties().length, is(1));
assertThat(props[0].properties()[0].name(), is("image"));
assertThat(props[0].properties()[0].properties().length, is(1));
assertThat(props[0].properties()[0].properties()[0].name(), is("url"));
}

@Test
public void testFieldExclude() throws Exception {
Map value = new ObjectMapper().readValue(getClass().getResourceAsStream("nested_arrays_mapping.json"), Map.class);
Expand Down
Expand Up @@ -11,6 +11,16 @@
"properties" : {
"url" : {
"type" : "string"
},
"image": {
"properties": {
"kind": {
"type": "string"
},
"url": {
"type": "string"
}
}
}
}
},
Expand Down

0 comments on commit 6e88f3b

Please sign in to comment.