From e4b84747458a7c7a843356b8abc25933e14cf45e Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 19 Jul 2021 14:22:33 +0100 Subject: [PATCH] # This is a combination of 4 commits.tree 09bd3af420b9a9e07270415c9f84b7a43bf7af9c parent 1920f000ea4f5f2ccd4d7d715a51a8e80402f223 author Alan Woodward 1626700953 +0100 committer Alan Woodward 1626700953 +0100 Make NestedObjectMapper its own class (#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 #4: fix merge includes --- .../index/mapper/NestedObjectMapper.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/NestedObjectMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/NestedObjectMapper.java index 30279f565d55b..870fa3df550ee 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/NestedObjectMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/NestedObjectMapper.java @@ -43,11 +43,19 @@ Builder includeInRoot(boolean includeInRoot) { return this; } + void includeInRoot(Explicit includeInRoot) { + this.includeInRoot = includeInRoot; + } + Builder includeInParent(boolean includeInParent) { this.includeInParent = new Explicit<>(includeInParent, true); return this; } + void includeInParent(Explicit includeInParent) { + this.includeInParent = includeInParent; + } + @Override public NestedObjectMapper build(ContentPath contentPath) { return new NestedObjectMapper(name, contentPath.pathAsText(name), buildMappers(contentPath), this); @@ -94,6 +102,7 @@ protected static void parseNested(String name, Map node, NestedO private Explicit includeInParent; private final String nestedTypePath; private final Query nestedTypeFilter; + private final Version indexCreatedVersion; NestedObjectMapper( String name, @@ -110,6 +119,7 @@ protected static void parseNested(String name, Map node, NestedO this.nestedTypeFilter = NestedPathFieldMapper.filter(builder.indexCreatedVersion, nestedTypePath); this.includeInParent = builder.includeInParent; this.includeInRoot = builder.includeInRoot; + this.indexCreatedVersion = builder.indexCreatedVersion; } public Query nestedTypeFilter() { @@ -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;