-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Add Fields API to aggregation scripts and field scripts #76325
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
050fa27
add fields api to scripted metric aggs and aggregation scripts
jdconrad c3dc59c
add fields api to script fields
jdconrad bf22da5
update tests based on pr feedback
jdconrad 2bc6f90
fix style
jdconrad c2b74a5
Merge branch 'master' into fieldcon
jdconrad 192f2af
fix leaf reader inconsistencies
jdconrad 0f42c6b
fix imports
jdconrad ba81bc0
fix imports
jdconrad 5ac1a3c
moved docbase for score script
jdconrad 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 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
15 changes: 15 additions & 0 deletions
15
.../src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.aggmap.txt
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,15 @@ | ||
# | ||
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
# or more contributor license agreements. Licensed under the Elastic License | ||
# 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
# in compliance with, at your election, the Elastic License 2.0 or the Server | ||
# Side Public License, v 1. | ||
# | ||
|
||
# The whitelist for the fields api | ||
|
||
# The scripts must be whitelisted for painless to find the classes for the field API | ||
class org.elasticsearch.script.ScriptedMetricAggContexts$MapScript @no_import { | ||
} | ||
class org.elasticsearch.script.ScriptedMetricAggContexts$MapScript$Factory @no_import { | ||
} |
15 changes: 15 additions & 0 deletions
15
...main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.aggregation.txt
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,15 @@ | ||
# | ||
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
# or more contributor license agreements. Licensed under the Elastic License | ||
# 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
# in compliance with, at your election, the Elastic License 2.0 or the Server | ||
# Side Public License, v 1. | ||
# | ||
|
||
# The whitelist for the fields api | ||
|
||
# The scripts must be whitelisted for painless to find the classes for the field API | ||
class org.elasticsearch.script.AggregationScript @no_import { | ||
} | ||
class org.elasticsearch.script.AggregationScript$Factory @no_import { | ||
} |
15 changes: 15 additions & 0 deletions
15
...s/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.field.txt
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,15 @@ | ||
# | ||
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
# or more contributor license agreements. Licensed under the Elastic License | ||
# 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
# in compliance with, at your election, the Elastic License 2.0 or the Server | ||
# Side Public License, v 1. | ||
# | ||
|
||
# The whitelist for the fields api | ||
|
||
# The scripts must be whitelisted for painless to find the classes for the field API | ||
class org.elasticsearch.script.FieldScript @no_import { | ||
} | ||
class org.elasticsearch.script.FieldScript @no_import { | ||
} |
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
85 changes: 85 additions & 0 deletions
85
...s/lang-painless/src/yamlRestTest/resources/rest-api-spec/test/painless/130_metric_agg.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,85 @@ | ||
setup: | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
settings: | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
double: | ||
type: double | ||
|
||
- do: | ||
cluster.health: | ||
wait_for_status: green | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 1 | ||
body: | ||
double: 1.0 | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 2 | ||
body: | ||
double: 1.0 | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 3 | ||
body: | ||
double: 2.0 | ||
|
||
- do: | ||
indices.refresh: {} | ||
|
||
--- | ||
"Scripted Metric Agg Total": | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
body: { | ||
"size": 0, | ||
"aggs": { | ||
"total": { | ||
"scripted_metric": { | ||
"init_script": "state.transactions = []", | ||
"map_script": "state.transactions.add(doc['double'].value)", | ||
"combine_script": "double total = 0.0; for (t in state.transactions) { total += t } return total", | ||
"reduce_script": "double total = 0; for (a in states) { total += a } return total" | ||
} | ||
} | ||
} | ||
} | ||
|
||
- match: { hits.total: 3 } | ||
- match: { aggregations.total.value: 4.0 } | ||
|
||
--- | ||
"Scripted Metric Agg Total (fields api)": | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
body: { | ||
"size": 0, | ||
"aggs": { | ||
"total": { | ||
"scripted_metric": { | ||
"init_script": "state.transactions = []", | ||
"map_script": "state.transactions.add(field('double').getValue(0.0))", | ||
"combine_script": "double total = 0.0; for (t in state.transactions) { total += t } return total", | ||
"reduce_script": "double total = 0; for (a in states) { total += a } return total" | ||
} | ||
} | ||
} | ||
} | ||
|
||
- match: { hits.total: 3 } | ||
- match: { aggregations.total.value: 4.0 } |
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.
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.
At this point we should have something like
getRuntimeFieldWhitelist
for this API since a lot of this config code is the same.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 would prefer to do this as a follow up PR. I even wonder if this should maybe be moved elsewhere. The entirety of including these contexts as part of the module is a bit of an afterthought, though I understand doing them through SPI doesn't make sense here given the dependency hierarchy.
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.
Well we should cleanup the whitelisting code. Next PR is fine, but if we wanna do a more fundamental change then I'd prefer the wl code cleanup happen first.