-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add support for script to boolean field mapper #71454
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
javanna
merged 14 commits into
elastic:master
from
javanna:enhancement/boolean_mapper_script
Apr 12, 2021
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f6346d5
Add support for script to boolean field mapper
javanna ec26992
iter
javanna 6df4380
iter
javanna 2c42e95
merge
javanna e97452f
Merge branch 'master' into enhancement/boolean_mapper_script
javanna 55511d5
tests
javanna 34d4353
clarify runForDoc
javanna fd81169
docs
javanna e759f87
yaml tests
javanna ab103a7
iter
javanna 38d2203
spotless
javanna 30ef85e
iter
javanna 7fd4e4c
iter
javanna 142623f
iter
javanna 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
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
134 changes: 134 additions & 0 deletions
134
...mlRestTest/resources/rest-api-spec/test/runtime_fields/63_boolean_calculated_at_index.yml
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 |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| --- | ||
| setup: | ||
| - do: | ||
| indices.create: | ||
| index: sensor | ||
| body: | ||
| settings: | ||
| number_of_shards: 1 | ||
| number_of_replicas: 0 | ||
| mappings: | ||
| properties: | ||
| timestamp: | ||
| type: date | ||
| temperature: | ||
| type: long | ||
| voltage: | ||
| type: double | ||
| node: | ||
| type: keyword | ||
| over_v: | ||
| type: boolean | ||
| script: | ||
| source: | | ||
| for (def v : doc['voltage']) { | ||
| emit(v >= params.min_v); | ||
| } | ||
| params: | ||
| min_v: 5.0 | ||
| # Test fetching from _source | ||
| over_v_from_source: | ||
| type: boolean | ||
| script: | ||
| source: | | ||
| emit(params._source.voltage >= 5.0); | ||
| # Test many booleans | ||
| big_vals: | ||
| type: boolean | ||
| script: | ||
| source: | | ||
| for (def v : doc['temperature']) { | ||
| emit(v >= 200); | ||
| } | ||
| for (def v : doc['voltage']) { | ||
| emit(v >= 5.0); | ||
| } | ||
|
|
||
|
|
||
| - do: | ||
| bulk: | ||
| index: sensor | ||
| refresh: true | ||
| body: | | ||
| {"index":{}} | ||
| {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a"} | ||
| {"index":{}} | ||
| {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b"} | ||
| {"index":{}} | ||
| {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a"} | ||
| {"index":{}} | ||
| {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b"} | ||
| {"index":{}} | ||
| {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c"} | ||
| {"index":{}} | ||
| {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c"} | ||
|
|
||
| --- | ||
| "get mapping": | ||
| - do: | ||
| indices.get_mapping: | ||
| index: sensor | ||
| - match: {sensor.mappings.properties.over_v.type: boolean } | ||
| - match: | ||
| sensor.mappings.properties.over_v.script.source: | | ||
| for (def v : doc['voltage']) { | ||
| emit(v >= params.min_v); | ||
| } | ||
| - match: {sensor.mappings.properties.over_v.script.params: {min_v: 5.0} } | ||
| - match: {sensor.mappings.properties.over_v.script.lang: painless } | ||
|
|
||
| --- | ||
| "fetch fields": | ||
| - do: | ||
| search: | ||
| index: sensor | ||
| body: | ||
| sort: timestamp | ||
| fields: [over_v, over_v_from_source, big_vals] | ||
| - match: {hits.total.value: 6} | ||
| - match: {hits.hits.0.fields.over_v: [false] } | ||
| - match: {hits.hits.0.fields.over_v_from_source: [false] } | ||
| - match: {hits.hits.0.fields.big_vals: [false, true] } # doc values are sorted with falses before trues | ||
|
|
||
| --- | ||
| "docvalue_fields": | ||
| - do: | ||
| search: | ||
| index: sensor | ||
| body: | ||
| sort: timestamp | ||
| docvalue_fields: [over_v, over_v_from_source, big_vals] | ||
| - match: {hits.total.value: 6} | ||
| - match: {hits.hits.0.fields.over_v: [false] } | ||
| - match: {hits.hits.0.fields.over_v_from_source: [false] } | ||
| - match: {hits.hits.0.fields.big_vals: [false, true] } # doc values are sorted with falses before trues | ||
|
|
||
| --- | ||
| "terms agg": | ||
| - do: | ||
| search: | ||
| index: sensor | ||
| body: | ||
| aggs: | ||
| over_v: | ||
| terms: | ||
| field: over_v | ||
| - match: {hits.total.value: 6} | ||
| - match: {aggregations.over_v.buckets.0.key_as_string: "true"} | ||
| - match: {aggregations.over_v.buckets.0.doc_count: 4} | ||
| - match: {aggregations.over_v.buckets.1.key_as_string: "false"} | ||
| - match: {aggregations.over_v.buckets.1.doc_count: 2} | ||
|
|
||
| --- | ||
| "term query": | ||
| - do: | ||
| search: | ||
| index: sensor | ||
| body: | ||
| query: | ||
| term: | ||
| over_v: true | ||
| sort: | ||
| timestamp: asc | ||
| - match: {hits.total.value: 4} | ||
| - match: {hits.hits.0._source.voltage: 5.6} |
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
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
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
Oops, something went wrong.
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.
One feature freeze is gone I want to look seriously at moving
mergeto Builder objects, having to carry this stuff around is a real pain.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.
agreed! I am happy to help with that