Skip to content

Commit

Permalink
# This is a combination of 4 commits.tree 09bd3af420b9a9e07270415c9f8…
Browse files Browse the repository at this point in the history
…4b7a43bf7af9c

parent 1920f00
author Alan Woodward <romseygeek@apache.org> 1626700953 +0100
committer Alan Woodward <romseygeek@apache.org> 1626700953 +0100

Make NestedObjectMapper its own class (elastic#74410)

Nested objects are implemented via a Nested class directly on object mappers,
even though nested and non-nested objects have quite different semantics. In
addition, most call-sites that need to get an object mapper in fact need a nested
object mapper. To make it clearer that nested and object mappers are different
beasts with different implementations and different requirements, we should
split them into different classes.

server:test compiles

:server:tests pass

# This is the commit message elastic#4:

fix merge includes
  • Loading branch information
romseygeek committed Jul 19, 2021
1 parent 1920f00 commit e4b8474
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ Builder includeInRoot(boolean includeInRoot) {
return this;
}

void includeInRoot(Explicit<Boolean> includeInRoot) {
this.includeInRoot = includeInRoot;
}

Builder includeInParent(boolean includeInParent) {
this.includeInParent = new Explicit<>(includeInParent, true);
return this;
}

void includeInParent(Explicit<Boolean> includeInParent) {
this.includeInParent = includeInParent;
}

@Override
public NestedObjectMapper build(ContentPath contentPath) {
return new NestedObjectMapper(name, contentPath.pathAsText(name), buildMappers(contentPath), this);
Expand Down Expand Up @@ -94,6 +102,7 @@ protected static void parseNested(String name, Map<String, Object> node, NestedO
private Explicit<Boolean> includeInParent;
private final String nestedTypePath;
private final Query nestedTypeFilter;
private final Version indexCreatedVersion;

NestedObjectMapper(
String name,
Expand All @@ -110,6 +119,7 @@ protected static void parseNested(String name, Map<String, Object> node, NestedO
this.nestedTypeFilter = NestedPathFieldMapper.filter(builder.indexCreatedVersion, nestedTypePath);
this.includeInParent = builder.includeInParent;
this.includeInRoot = builder.includeInRoot;
this.indexCreatedVersion = builder.indexCreatedVersion;
}

public Query nestedTypeFilter() {
Expand Down Expand Up @@ -184,9 +194,11 @@ public ObjectMapper merge(Mapper mergeWith, MapperService.MergeReason reason) {
if (includeInParent.value() != mergeWithObject.includeInParent.value()) {
throw new MapperException("the [include_in_parent] parameter can't be updated on a nested object mapping");
}
builder.includeInParent(includeInParent);
if (includeInRoot.value() != mergeWithObject.includeInRoot.value()) {
throw new MapperException("the [include_in_root] parameter can't be updated on a nested object mapping");
}
builder.includeInRoot(includeInRoot);
}
toMerge.doMerge(mergeWithObject, reason);
return toMerge;
Expand Down

0 comments on commit e4b8474

Please sign in to comment.