Handle missing and multiple values in script #30257
Closed
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.
Previously in script for numeric fields, there was no way to check if
a document is missing a value. Also certain operations on multiple-
values fields were missing.
This PR adds the following:
add the following functions for multiple-valued numeric fields:
doc['field'].min returns the minumum amoung values
doc['field'].max returns the maximum amoung values
doc['field'].sum returns the sum of amoung values
doc['field'].avg returns the average of values
return null for doc['field'] if a document is missing a 'field1':
Now we can do this:
if (doc['field'] == null) {return -1;} return doc['field'].value; or
doc['field']?.value ?: -1
This new behaviour will only work if the following system property is set:
`export ES_JAVA_OPTS="-Des.script.null_for_missing_value=true"'
Closes #29286