-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Fix missing intermediate object error when applying dynamic template #87622
Changes from all commits
76f0af5
29d84c0
0a83a88
0d823ab
278e903
089f157
c578ade
e1afb3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,14 +102,14 @@ Builder addMappers(Map<String, Mapper> mappers) { | |
} | ||
|
||
/** | ||
* Adds a dynamically created Mapper to this builder. | ||
* Adds a dynamically created {@link Mapper} to this builder. | ||
* | ||
* @param name the name of the Mapper, including object prefixes | ||
* @param prefix the object prefix of this mapper | ||
* @param mapper the mapper to add | ||
* @param context the DocumentParserContext in which the mapper has been built | ||
*/ | ||
public void addDynamic(String name, String prefix, Mapper mapper, DocumentParserContext context) { | ||
public final void addDynamic(String name, String prefix, Mapper mapper, DocumentParserContext context) { | ||
// If the mapper to add has no dots, or the current object mapper has subobjects set to false, | ||
// we just add it as it is for sure a leaf mapper | ||
if (name.contains(".") == false || subobjects.value() == false) { | ||
|
@@ -118,29 +118,29 @@ public void addDynamic(String name, String prefix, Mapper mapper, DocumentParser | |
// otherwise we strip off the first object path of the mapper name, load or create | ||
// the relevant object mapper, and then recurse down into it, passing the remainder | ||
// of the mapper name. So for a mapper 'foo.bar.baz', we locate 'foo' and then | ||
// call addDynamic on it with the name 'bar.baz'. | ||
// call addDynamic on it with the name 'bar.baz', and next call addDynamic on 'bar' with the name 'baz'. | ||
else { | ||
int firstDotIndex = name.indexOf("."); | ||
String childName = name.substring(0, firstDotIndex); | ||
String fullChildName = prefix == null ? childName : prefix + "." + childName; | ||
ObjectMapper.Builder childBuilder = findChild(fullChildName, context); | ||
childBuilder.addDynamic(name.substring(firstDotIndex + 1), fullChildName, mapper, context); | ||
add(childBuilder); | ||
String immediateChild = name.substring(0, firstDotIndex); | ||
String immediateChildFullName = prefix == null ? immediateChild : prefix + "." + immediateChild; | ||
ObjectMapper.Builder parentBuilder = findObjectBuilder(immediateChildFullName, context); | ||
parentBuilder.addDynamic(name.substring(firstDotIndex + 1), immediateChildFullName, mapper, context); | ||
add(parentBuilder); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appreciate that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ++ I see what you mean. |
||
} | ||
} | ||
|
||
private static ObjectMapper.Builder findChild(String fullChildName, DocumentParserContext context) { | ||
// does the child mapper already exist? if so, use that | ||
ObjectMapper child = context.mappingLookup().objectMappers().get(fullChildName); | ||
if (child != null) { | ||
return child.newBuilder(context.indexSettings().getIndexVersionCreated()); | ||
private static ObjectMapper.Builder findObjectBuilder(String fullName, DocumentParserContext context) { | ||
// does the object mapper already exist? if so, use that | ||
ObjectMapper objectMapper = context.mappingLookup().objectMappers().get(fullName); | ||
if (objectMapper != null) { | ||
return objectMapper.newBuilder(context.indexSettings().getIndexVersionCreated()); | ||
} | ||
// has the child mapper been added as a dynamic update already? | ||
child = context.getDynamicObjectMapper(fullChildName); | ||
if (child != null) { | ||
return child.newBuilder(context.indexSettings().getIndexVersionCreated()); | ||
// has the object mapper been added as a dynamic update already? | ||
objectMapper = context.getDynamicObjectMapper(fullName); | ||
if (objectMapper != null) { | ||
return objectMapper.newBuilder(context.indexSettings().getIndexVersionCreated()); | ||
} | ||
throw new IllegalArgumentException("Missing intermediate object " + fullChildName); | ||
throw new IllegalStateException("Missing intermediate object " + fullName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the only relevant change in this file: IllegalArgumentException -> IllegalStateException . All the rest is renaming child to parent. |
||
} | ||
|
||
protected final Map<String, Mapper> buildMappers(boolean root, MapperBuilderContext context) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the changes in this file from now on are just renaming mapper -> parentObjectMapper