-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle missing and multiple values in script
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: - 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 - 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 Closes #29286
- Loading branch information
1 parent
e2d770d
commit 5aeab57
Showing
11 changed files
with
277 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
117 changes: 117 additions & 0 deletions
117
...ainless/src/test/resources/rest-api-spec/test/painless/70_missing_and_multiple_values.yml
This file contains 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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
setup: | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
settings: | ||
number_of_shards: 1 | ||
mappings: | ||
_doc: | ||
properties: | ||
dval: | ||
type: double | ||
lval: | ||
type: long | ||
|
||
- do: | ||
index: | ||
index: test | ||
type: _doc | ||
id: 1 | ||
body: { "dval": 5.5, "lval": 5 } | ||
|
||
- do: | ||
index: | ||
index: test | ||
type: _doc | ||
id: 2 | ||
body: { "dval": [5.5, 3.5, 4.5] } | ||
|
||
|
||
- do: | ||
index: | ||
index: test | ||
type: _doc | ||
id: 3 | ||
body: { "lval": [5, 3, 4] } | ||
|
||
- do: | ||
indices.refresh: {} | ||
|
||
--- | ||
"check double and long values: missing values and operations on multiple values": | ||
- skip: | ||
version: " - 6.99.99" | ||
reason: Handling missing values and operations on multiple values were added after these versions | ||
|
||
- do: | ||
search: | ||
body: | ||
script_fields: | ||
val_dval: | ||
script: | ||
source: "doc['dval']?.value ?: -1.0" | ||
min_dval: | ||
script: | ||
source: "doc['dval']?.min ?: -1.0" | ||
max_dval: | ||
script: | ||
source: "doc['dval']?.max ?: -1.0" | ||
sum_dval: | ||
script: | ||
source: "doc['dval']?.sum ?: -1.0" | ||
avg_dval: | ||
script: | ||
source: "doc['dval']?.avg ?: -1.0" | ||
val_lval: | ||
script: | ||
source: "doc['lval']?.value ?: -1" | ||
min_lval: | ||
script: | ||
source: "doc['lval']?.min ?: -1" | ||
max_lval: | ||
script: | ||
source: "doc['lval']?.max ?: -1" | ||
sum_lval: | ||
script: | ||
source: "doc['lval']?.sum ?: -1" | ||
avg_lval: | ||
script: | ||
source: "doc['lval']?.avg ?: -1" | ||
|
||
- match: { hits.hits.0.fields.val_dval.0: 5.5} | ||
- match: { hits.hits.0.fields.min_dval.0: 5.5} | ||
- match: { hits.hits.0.fields.max_dval.0: 5.5} | ||
- match: { hits.hits.0.fields.sum_dval.0: 5.5} | ||
- match: { hits.hits.0.fields.avg_dval.0: 5.5} | ||
|
||
- match: { hits.hits.0.fields.val_lval.0: 5} | ||
- match: { hits.hits.0.fields.min_lval.0: 5} | ||
- match: { hits.hits.0.fields.max_lval.0: 5} | ||
- match: { hits.hits.0.fields.sum_lval.0: 5} | ||
- match: { hits.hits.0.fields.avg_lval.0: 5} | ||
|
||
- match: { hits.hits.1.fields.val_dval.0: 3.5} | ||
- match: { hits.hits.1.fields.min_dval.0: 3.5} | ||
- match: { hits.hits.1.fields.max_dval.0: 5.5} | ||
- match: { hits.hits.1.fields.sum_dval.0: 13.5} | ||
- match: { hits.hits.1.fields.avg_dval.0: 4.5} | ||
|
||
- match: { hits.hits.1.fields.val_lval.0: -1} | ||
- match: { hits.hits.1.fields.min_lval.0: -1} | ||
- match: { hits.hits.1.fields.max_lval.0: -1} | ||
- match: { hits.hits.1.fields.sum_lval.0: -1} | ||
- match: { hits.hits.1.fields.avg_lval.0: -1} | ||
|
||
- match: { hits.hits.2.fields.val_dval.0: -1.0} | ||
- match: { hits.hits.2.fields.min_dval.0: -1.0} | ||
- match: { hits.hits.2.fields.max_dval.0: -1.0} | ||
- match: { hits.hits.2.fields.sum_dval.0: -1.0} | ||
- match: { hits.hits.2.fields.avg_dval.0: -1.0} | ||
|
||
- match: { hits.hits.2.fields.val_lval.0: 3} | ||
- match: { hits.hits.2.fields.min_lval.0: 3} | ||
- match: { hits.hits.2.fields.max_lval.0: 5} | ||
- match: { hits.hits.2.fields.sum_lval.0: 12} | ||
- match: { hits.hits.2.fields.avg_lval.0: 4} | ||
|
This file contains 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
Oops, something went wrong.