Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class AbstractScriptMappedFieldType extends MappedFieldType {

void mapperXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field("runtime_type", runtimeType());
builder.field("script", script.getIdOrCode()); // TODO For some reason this doesn't allow us to do the full xcontent of the script.
builder.field("script", script, params);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ setup:
day_of_week:
type: script
runtime_type: keyword
script: value(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))
script: |
value(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))
days_starting_with_t:
type: script
runtime_type: keyword
Expand All @@ -30,6 +31,16 @@ setup:
value(dow);
}
}
prefixed_node:
type: script
runtime_type: keyword
script:
source: |
for (String node : doc['node']) {
value(params.prefix + node);
}
params:
prefix: node_

- do:
bulk:
Expand All @@ -49,16 +60,49 @@ setup:
{"index":{}}
{"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c"}

---
"get mapping":
- do:
indices.get_mapping:
index: sensor
- match: {sensor.mappings.properties.day_of_week.type: script }
- match: {sensor.mappings.properties.day_of_week.runtime_type: keyword }
- match:
sensor.mappings.properties.day_of_week.script.source: |
value(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))
- match: {sensor.mappings.properties.day_of_week.script.lang: painless }
- match: {sensor.mappings.properties.days_starting_with_t.type: script }
- match: {sensor.mappings.properties.days_starting_with_t.runtime_type: keyword }
- match:
sensor.mappings.properties.days_starting_with_t.script.source: |
for (String dow: doc['day_of_week']) {
if (dow.startsWith('T')) {
value(dow);
}
}
- match: {sensor.mappings.properties.days_starting_with_t.script.lang: painless }
- match: {sensor.mappings.properties.prefixed_node.type: script }
- match: {sensor.mappings.properties.prefixed_node.runtime_type: keyword }
- match:
sensor.mappings.properties.prefixed_node.script.source: |
for (String node : doc['node']) {
value(params.prefix + node);
}
- match: {sensor.mappings.properties.prefixed_node.script.params: {prefix: node_} }
- match: {sensor.mappings.properties.prefixed_node.script.lang: painless }

---
"docvalue_fields":
- do:
search:
index: sensor
body:
sort: timestamp
docvalue_fields: [day_of_week]
docvalue_fields: [day_of_week, days_starting_with_t, prefixed_node]
- match: {hits.total.value: 6}
- match: {hits.hits.0.fields.day_of_week: [Thursday] }
- match: {hits.hits.0.fields.days_starting_with_t: [Thursday] }
- match: {hits.hits.0.fields.prefixed_node: [node_c] }

---
"terms agg":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ setup:
voltage_times_ten:
type: script
runtime_type: long
script: |
for (double v : doc['voltage']) {
value((long)(v * 10));
}
script:
source: |
for (double v : doc['voltage']) {
value((long)(v * params.multiplier));
}
params:
multiplier: 10
even_voltage_times_ten:
type: script
runtime_type: long
Expand Down Expand Up @@ -52,6 +55,31 @@ setup:
{"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: script }
- match: {sensor.mappings.properties.voltage_times_ten.runtime_type: long }
- match:
sensor.mappings.properties.voltage_times_ten.script.source: |
for (double v : doc['voltage']) {
value((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 }
- match: {sensor.mappings.properties.even_voltage_times_ten.type: script }
- match: {sensor.mappings.properties.even_voltage_times_ten.runtime_type: long }
- match:
sensor.mappings.properties.even_voltage_times_ten.script.source: |
for (long tenV: doc['voltage_times_ten']) {
if (tenV % 2 == 0) {
value(tenV);
}
}
- match: {sensor.mappings.properties.even_voltage_times_ten.script.lang: painless }

---
"docvalue_fields":
- do:
Expand Down