Skip to content

Handle missing and multiple values in script #30257

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

Conversation

mayya-sharipova
Copy link
Contributor

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

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 is the following system property is set:
    `export ES_JAVA_OPTS="-Des.script.null_for_missing_value=true"'

Closes elastic#29286
@mayya-sharipova
Copy link
Contributor Author

@elasticmachine run sample packaging tests

1 similar comment
@mayya-sharipova
Copy link
Contributor Author

@elasticmachine run sample packaging tests

@rjernst rjernst added the :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache label Apr 30, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >feature >non-issue v6.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants