-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Fields API to aggregation scripts and field scripts (#76325)
This change updates the aggregation script, map script for aggregations, and field scripts to extend DocBasedScript to give them access to the new fields api.
- Loading branch information
Showing
16 changed files
with
304 additions
and
105 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
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.