Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure parameters are updated when merging flattened mappings. #48971

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/reference/mapping/types/flattened.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ The following mapping parameters are accepted:

The maximum allowed depth of the flattened object field, in terms of nested
inner objects. If a flattened object field exceeds this limit, then an
error will be thrown. Defaults to `20`.
error will be thrown. Defaults to `20`. Note that `depth_limit` can be
updated dynamically through the <<indices-put-mapping, put mapping>> API.

<<doc-values,`doc_values`>>::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
}
}

private final FlatObjectFieldParser fieldParser;
private FlatObjectFieldParser fieldParser;
private int depthLimit;
private int ignoreAbove;

Expand All @@ -552,7 +552,12 @@ protected String contentType() {
@Override
protected void doMerge(Mapper mergeWith) {
super.doMerge(mergeWith);
this.ignoreAbove = ((FlatObjectFieldMapper) mergeWith).ignoreAbove;

FlatObjectFieldMapper other = ((FlatObjectFieldMapper) mergeWith);
this.depthLimit = other.depthLimit;
this.ignoreAbove = other.ignoreAbove;
this.fieldParser = new FlatObjectFieldParser(fieldType.name(), keyedFieldName(),
fieldType, depthLimit, ignoreAbove);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,12 @@ public void testFieldMultiplicity() throws Exception {
}

public void testDepthLimit() throws IOException {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
// First verify the default behavior when depth_limit is not set.
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
.startObject("type")
.startObject("properties")
.startObject("field")
.field("type", "flattened")
.field("depth_limit", 2)
.endObject()
.endObject()
.endObject()
Expand All @@ -340,8 +340,25 @@ public void testDepthLimit() throws IOException {
.endObject()
.endObject());

mapper.parse(new SourceToParse("test", "1", doc, XContentType.JSON));

// Set a lower value for depth_limit and check that the field is rejected.
String newMapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
.startObject("type")
.startObject("properties")
.startObject("field")
.field("type", "flattened")
.field("depth_limit", 2)
.endObject()
.endObject()
.endObject()
.endObject());

DocumentMapper newMapper = mapper.merge(
parser.parse("type", new CompressedXContent(newMapping)).mapping());

expectThrows(MapperParsingException.class, () ->
mapper.parse(new SourceToParse("test", "1", doc, XContentType.JSON)));
newMapper.parse(new SourceToParse("test", "1", doc, XContentType.JSON)));
}

public void testEagerGlobalOrdinals() throws IOException {
Expand All @@ -362,12 +379,12 @@ public void testEagerGlobalOrdinals() throws IOException {
}

public void testIgnoreAbove() throws IOException {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
// First verify the default behavior when ignore_above is not set.
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
.startObject("type")
.startObject("properties")
.startObject("field")
.field("type", "flattened")
.field("ignore_above", 10)
.endObject()
.endObject()
.endObject()
Expand All @@ -386,7 +403,26 @@ public void testIgnoreAbove() throws IOException {

ParsedDocument parsedDoc = mapper.parse(new SourceToParse("test", "1", doc, XContentType.JSON));
IndexableField[] fields = parsedDoc.rootDoc().getFields("field");
assertEquals(0, fields.length);
assertEquals(2, fields.length);

// Set a lower value for ignore_above and check that the field is skipped.
String newMapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
.startObject("type")
.startObject("properties")
.startObject("field")
.field("type", "flattened")
.field("ignore_above", "10")
.endObject()
.endObject()
.endObject()
.endObject());

DocumentMapper newMapper = mapper.merge(
parser.parse("type", new CompressedXContent(newMapping)).mapping());

ParsedDocument newParsedDoc = newMapper.parse(new SourceToParse("test", "1", doc, XContentType.JSON));
IndexableField[] newFields = newParsedDoc.rootDoc().getFields("field");
assertEquals(0, newFields.length);
}

public void testNullValues() throws Exception {
Expand Down