-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Update by Query is modified to accept short script
parameter.
#26841
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ protected UpdateByQueryRequest buildRequest(RestRequest request) throws IOExcept | |
|
||
Map<String, Consumer<Object>> consumers = new HashMap<>(); | ||
consumers.put("conflicts", o -> internal.setConflicts((String) o)); | ||
consumers.put("script", o -> internal.setScript(parseScript((Map<String, Object>)o))); | ||
consumers.put("script", o -> internal.setScript(parseScript(o))); | ||
|
||
parseInternalRequest(internal, request, consumers); | ||
|
||
|
@@ -76,49 +76,59 @@ protected UpdateByQueryRequest buildRequest(RestRequest request) throws IOExcept | |
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static Script parseScript(Map<String, Object> config) { | ||
String script = null; | ||
ScriptType type = null; | ||
String lang = DEFAULT_SCRIPT_LANG; | ||
Map<String, Object> params = Collections.emptyMap(); | ||
for (Iterator<Map.Entry<String, Object>> itr = config.entrySet().iterator(); itr.hasNext();) { | ||
Map.Entry<String, Object> entry = itr.next(); | ||
String parameterName = entry.getKey(); | ||
Object parameterValue = entry.getValue(); | ||
if (Script.LANG_PARSE_FIELD.match(parameterName)) { | ||
if (parameterValue instanceof String || parameterValue == null) { | ||
lang = (String) parameterValue; | ||
} else { | ||
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); | ||
} | ||
} else if (Script.PARAMS_PARSE_FIELD.match(parameterName)) { | ||
if (parameterValue instanceof Map || parameterValue == null) { | ||
params = (Map<String, Object>) parameterValue; | ||
} else { | ||
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); | ||
} | ||
} else if (ScriptType.INLINE.getParseField().match(parameterName)) { | ||
if (parameterValue instanceof String || parameterValue == null) { | ||
script = (String) parameterValue; | ||
type = ScriptType.INLINE; | ||
} else { | ||
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); | ||
} | ||
} else if (ScriptType.STORED.getParseField().match(parameterName)) { | ||
if (parameterValue instanceof String || parameterValue == null) { | ||
script = (String) parameterValue; | ||
type = ScriptType.STORED; | ||
} else { | ||
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); | ||
private static Script parseScript(Object config) { | ||
assert config != null : "Script should not be null"; | ||
|
||
if (config instanceof String) { | ||
return new Script((String) config); | ||
} else if (config instanceof Map) { | ||
Map<String,Object> configMap = (Map<String, Object>) config; | ||
String script = null; | ||
ScriptType type = null; | ||
String lang = DEFAULT_SCRIPT_LANG; | ||
Map<String, Object> params = Collections.emptyMap(); | ||
for (Iterator<Map.Entry<String, Object>> itr = configMap.entrySet().iterator(); itr.hasNext();) { | ||
Map.Entry<String, Object> entry = itr.next(); | ||
String parameterName = entry.getKey(); | ||
Object parameterValue = entry.getValue(); | ||
if (Script.LANG_PARSE_FIELD.match(parameterName)) { | ||
if (parameterValue instanceof String || parameterValue == null) { | ||
lang = (String) parameterValue; | ||
} else { | ||
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); | ||
} | ||
} else if (Script.PARAMS_PARSE_FIELD.match(parameterName)) { | ||
if (parameterValue instanceof Map || parameterValue == null) { | ||
params = (Map<String, Object>) parameterValue; | ||
} else { | ||
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); | ||
} | ||
} else if (ScriptType.INLINE.getParseField().match(parameterName)) { | ||
if (parameterValue instanceof String || parameterValue == null) { | ||
script = (String) parameterValue; | ||
type = ScriptType.INLINE; | ||
} else { | ||
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); | ||
} | ||
} else if (ScriptType.STORED.getParseField().match(parameterName)) { | ||
if (parameterValue instanceof String || parameterValue == null) { | ||
script = (String) parameterValue; | ||
type = ScriptType.STORED; | ||
} else { | ||
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); | ||
} | ||
} | ||
} | ||
} | ||
if (script == null) { | ||
throw new ElasticsearchParseException("expected one of [{}] or [{}] fields, but found none", | ||
if (script == null) { | ||
throw new ElasticsearchParseException("expected one of [{}] or [{}] fields, but found none", | ||
ScriptType.INLINE.getParseField().getPreferredName(), ScriptType.STORED.getParseField().getPreferredName()); | ||
} | ||
assert type != null : "if script is not null, type should definitely not be null"; | ||
} | ||
assert type != null : "if script is not null, type should definitely not be null"; | ||
|
||
return new Script(type, lang, script, params); | ||
return new Script(type, lang, script, params); | ||
} | ||
else { | ||
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. We usually don't put a newline between |
||
throw new IllegalArgumentException("Script value should be a String or a Map"); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you fix the indentation on this to line up?