-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script parameter to long and double field mappers (#69531)
This commit adds a script parameter to long and double fields that makes it possible to calculate a value for these fields at index time. It uses the same script context as the equivalent runtime fields, and allows for multiple index-time scripted fields to cross-refer while still checking for indirection loops.
- Loading branch information
1 parent
9576f3e
commit 1653f2f
Showing
33 changed files
with
1,771 additions
and
51 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
152 changes: 152 additions & 0 deletions
152
.../yamlRestTest/resources/rest-api-spec/test/runtime_fields/23_long_calculated_at_index.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,152 @@ | ||
--- | ||
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 | ||
voltage_times_ten: | ||
type: long | ||
script: | ||
source: | | ||
for (double v : doc['voltage']) { | ||
emit((long)(v * params.multiplier)); | ||
} | ||
params: | ||
multiplier: 10 | ||
voltage_times_ten_no_dv: | ||
type: long | ||
doc_values: false | ||
script: | ||
source: | | ||
for (double v : doc['voltage']) { | ||
emit((long)(v * params.multiplier)); | ||
} | ||
params: | ||
multiplier: 10 | ||
# test multiple values | ||
temperature_digits: | ||
type: long | ||
script: | ||
source: | | ||
for (long temperature : doc['temperature']) { | ||
long t = temperature; | ||
while (t != 0) { | ||
emit(t % 10); | ||
t /= 10; | ||
} | ||
} | ||
- 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.voltage_times_ten.type: long } | ||
- match: | ||
sensor.mappings.properties.voltage_times_ten.script.source: | | ||
for (double v : doc['voltage']) { | ||
emit((long)(v * params.multiplier)); | ||
} | ||
- match: {sensor.mappings.properties.voltage_times_ten.script.params: {multiplier: 10} } | ||
- match: {sensor.mappings.properties.voltage_times_ten.script.lang: painless } | ||
|
||
--- | ||
"fetch fields": | ||
- do: | ||
search: | ||
index: sensor | ||
body: | ||
sort: timestamp | ||
fields: | ||
- voltage_times_ten | ||
- voltage_times_ten_no_dv | ||
- temperature_digits | ||
- match: {hits.total.value: 6} | ||
- match: {hits.hits.0.fields.voltage_times_ten: [40] } | ||
- match: {hits.hits.0.fields.temperature_digits: [2, 0, 2] } | ||
- match: {hits.hits.0.fields.voltage_times_ten: [40] } | ||
- match: {hits.hits.0.fields.voltage_times_ten_no_dv: [40] } | ||
- match: {hits.hits.1.fields.voltage_times_ten: [42] } | ||
- match: {hits.hits.2.fields.voltage_times_ten: [56] } | ||
- match: {hits.hits.3.fields.voltage_times_ten: [51] } | ||
- match: {hits.hits.4.fields.voltage_times_ten: [58] } | ||
- match: {hits.hits.5.fields.voltage_times_ten: [52] } | ||
|
||
--- | ||
"docvalue_fields": | ||
- do: | ||
search: | ||
index: sensor | ||
body: | ||
sort: timestamp | ||
docvalue_fields: | ||
- voltage_times_ten | ||
- temperature_digits | ||
- match: {hits.total.value: 6} | ||
- match: {hits.hits.0.fields.voltage_times_ten: [40] } | ||
- match: {hits.hits.0.fields.temperature_digits: [0, 2, 2] } | ||
- match: {hits.hits.0.fields.voltage_times_ten: [40] } | ||
- match: {hits.hits.1.fields.voltage_times_ten: [42] } | ||
- match: {hits.hits.2.fields.voltage_times_ten: [56] } | ||
- match: {hits.hits.3.fields.voltage_times_ten: [51] } | ||
- match: {hits.hits.4.fields.voltage_times_ten: [58] } | ||
- match: {hits.hits.5.fields.voltage_times_ten: [52] } | ||
|
||
--- | ||
"terms agg": | ||
- do: | ||
search: | ||
index: sensor | ||
body: | ||
aggs: | ||
v10: | ||
terms: | ||
field: voltage_times_ten | ||
- match: {hits.total.value: 6} | ||
- match: {aggregations.v10.buckets.0.key: 40.0} | ||
- match: {aggregations.v10.buckets.0.doc_count: 1} | ||
- match: {aggregations.v10.buckets.1.key: 42.0} | ||
- match: {aggregations.v10.buckets.1.doc_count: 1} | ||
|
||
--- | ||
"term query": | ||
- do: | ||
search: | ||
index: sensor | ||
body: | ||
query: | ||
term: | ||
voltage_times_ten: 58 | ||
- match: {hits.total.value: 1} | ||
- match: {hits.hits.0._source.voltage: 5.8} |
Oops, something went wrong.