-
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
Disallow "enabled" attribute change for types in mapping update (#33566) #33933
Changes from 2 commits
f09f1a1
7e6cb90
ce31c85
696b9a3
c1db69e
e4458be
02b50dd
df57bbb
1a890a4
51feaae
1489108
760b6cc
ec6e768
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 |
---|---|---|
|
@@ -458,6 +458,8 @@ protected void doMerge(final ObjectMapper mergeWith) { | |
|
||
for (Mapper mergeWithMapper : mergeWith) { | ||
Mapper mergeIntoMapper = mappers.get(mergeWithMapper.simpleName()); | ||
throwExceptionIfEnabledAttributeIsUpdatedForType(mergeWith, mergeWithMapper, mergeIntoMapper); | ||
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. nit: ImNotABigFanOfOverlyLongMethodNamesButWhatTheHeckIfYouReallyLikeIt ;-) 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'll shorten it, I'm not a big fan neither. |
||
|
||
Mapper merged; | ||
if (mergeIntoMapper == null) { | ||
// no mapping, simply add it | ||
|
@@ -470,6 +472,25 @@ protected void doMerge(final ObjectMapper mergeWith) { | |
} | ||
} | ||
|
||
private void throwExceptionIfEnabledAttributeIsUpdatedForType(ObjectMapper mergeWith, Mapper mergeWithMapper, Mapper mergeIntoMapper) { | ||
if (mergeIntoMapper instanceof ObjectMapper && mergeWithMapper instanceof ObjectMapper) { | ||
final ObjectMapper mergeIntoObjectMapper = (ObjectMapper) mergeIntoMapper; | ||
final ObjectMapper mergeWithObjectMapper = (ObjectMapper) mergeWithMapper; | ||
|
||
if (mergeIntoObjectMapper.isEnabled() != mergeWithObjectMapper.isEnabled()) { | ||
if (mergeIntoObjectMapper.nestedTypeFilter() instanceof TermQuery) { | ||
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'm not quite sure I understand what the 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 dug into this with a debugger and the I've been a (tiny) bit paranoiac as I wanted to be sure to not make other things break. I'll have another debugging session to see how things work when updating mapping with 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. Well, it looks like updating the command
output
I'll now have a look if removing this conditional block doesn't conflict with other 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. No |
||
final TermQuery termQuery = (TermQuery) mergeIntoObjectMapper.nestedTypeFilter(); | ||
|
||
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. nit: maybe delete this line 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. Yes, these two lines are related, no need to add a blank line, I'll remove it. |
||
if (termQuery.getTerm() != null && "_type".equals(termQuery.getTerm().field())) { | ||
final String path = mergeWith.fullPath() + "." + mergeWithObjectMapper.simpleName() + ".enabled"; | ||
|
||
throw new MapperException("Can't update attribute for type [{}] in index mapping", path); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public ObjectMapper updateFieldType(Map<String, MappedFieldType> fullNameToFieldType) { | ||
List<Mapper> updatedMappers = null; | ||
|
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.
nit: not sure we need another constructor here, can you just insert the args into the message String in the call?
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.
Sure.
Is
LoggerMessageFormat#format
preferred overString#format
or maybe just string concatenation?