Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a7f538c
Take 3... Just re-use scripts, exposing things via a MemoryIndex if n…
romseygeek Feb 24, 2021
1a330f6
add test for cross references
romseygeek Feb 24, 2021
6c6e6d3
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 2, 2021
e004881
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 4, 2021
5e1cf03
Only support script on long and double
romseygeek Mar 4, 2021
bc993f9
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 4, 2021
6d77d28
Allow calculated fields to refer to each other
romseygeek Mar 5, 2021
d81d1a2
Add value fetchers; yaml tests
romseygeek Mar 5, 2021
381b591
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 5, 2021
0074b4d
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 9, 2021
51946a8
Avoid null metadata
romseygeek Mar 9, 2021
d97af2d
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 9, 2021
6a6426f
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 10, 2021
d4913be
Pass index name; throw error if you try and index into a script field
romseygeek Mar 10, 2021
5331ae5
Rename, consolidate, add javadocs
romseygeek Mar 15, 2021
4b35f37
split postparsecontext into context and phase executor
romseygeek Mar 15, 2021
6569f5a
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 15, 2021
4d79be2
Make defining test scripts easier
romseygeek Mar 15, 2021
cead316
loop detection
romseygeek Mar 15, 2021
1faea30
disallow stored scripts
romseygeek Mar 15, 2021
3b26fe3
Don't use memory index
romseygeek Mar 15, 2021
2e2dde3
tidy
romseygeek Mar 15, 2021
2e01777
cleanup
romseygeek Mar 16, 2021
152faac
better error message
romseygeek Mar 16, 2021
ea291c4
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 16, 2021
4d3d4f1
Throw error if we try to refer to runtime fields in indextime scripts
romseygeek Mar 16, 2021
9791f94
Add fetch tests for long/double index-time script fields with no docv…
romseygeek Mar 16, 2021
918dc6a
javadocs
romseygeek Mar 16, 2021
79e48ee
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 18, 2021
1917ddb
Add test to MapperTestCase that checks fielddata returned via LazyDoc…
romseygeek Mar 18, 2021
7981259
Allow test case to say if field does not support scripts
romseygeek Mar 18, 2021
b8ade1a
unsigned long doesn't support scripts
romseygeek Mar 18, 2021
45c0bab
or geoshapewithdocvalues
romseygeek Mar 18, 2021
ea2cef5
Error handling
romseygeek Mar 22, 2021
4a08638
Don't load from docvalues at fetch time
romseygeek Mar 22, 2021
cff8281
tests
romseygeek Mar 22, 2021
a5e8078
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 22, 2021
1276a9a
duh
romseygeek Mar 22, 2021
09f5966
we don't sort emitted values
romseygeek Mar 22, 2021
c945b6a
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 23, 2021
f68b5d8
Add parameter requirements and preclusions
romseygeek Mar 23, 2021
fb879ef
Add some basic docs
romseygeek Mar 23, 2021
19edac6
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 23, 2021
b584c9d
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 24, 2021
d76a88b
Implement document() on lazy reader properly
romseygeek Mar 24, 2021
ede91b9
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 27, 2021
b647239
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 29, 2021
d20db3a
feedback
romseygeek Mar 29, 2021
7615f62
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 29, 2021
9b60436
DocumentLeafReader to top; execute functions to DocumentParser; renam…
romseygeek Mar 29, 2021
c888b32
Remove MapperScript
romseygeek Mar 29, 2021
47e73b7
precommit
romseygeek Mar 29, 2021
5a6ba36
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 29, 2021
b8df6c2
deef
romseygeek Mar 30, 2021
878a187
Die IndexTimeScript Die
romseygeek Mar 30, 2021
9aba5d3
Merge remote-tracking branch 'origin/master' into runtime/runtime-to-…
romseygeek Mar 30, 2021
de582e4
javadoc
romseygeek Mar 30, 2021
58cd88f
more
romseygeek Mar 31, 2021
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 @@ -79,7 +79,7 @@ public class ScriptScoreBenchmark {
private final ScriptModule scriptModule = new ScriptModule(Settings.EMPTY, pluginsService.filterPlugins(ScriptPlugin.class));

private final Map<String, MappedFieldType> fieldTypes = Map.ofEntries(
Map.entry("n", new NumberFieldType("n", NumberType.LONG, false, false, true, true, null, Map.of()))
Map.entry("n", new NumberFieldType("n", NumberType.LONG, false, false, true, true, null, Map.of(), null))
);
private final IndexFieldDataCache fieldDataCache = new IndexFieldDataCache.None();
private final CircuitBreakerService breakerService = new NoneCircuitBreakerService();
Expand Down
25 changes: 23 additions & 2 deletions docs/reference/mapping/types/numeric.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ The following parameters are accepted by numeric types:

Try to convert strings to numbers and truncate fractions for integers.
Accepts `true` (default) and `false`. Not applicable for `unsigned_long`.
Note that this cannot be set if the `script` parameter is used.

<<doc-values,`doc_values`>>::

Expand All @@ -127,7 +128,8 @@ The following parameters are accepted by numeric types:
<<ignore-malformed,`ignore_malformed`>>::

If `true`, malformed numbers are ignored. If `false` (default), malformed
numbers throw an exception and reject the whole document.
numbers throw an exception and reject the whole document. Note that this
cannot be set if the `script` parameter is used.

<<mapping-index,`index`>>::

Expand All @@ -137,7 +139,26 @@ The following parameters are accepted by numeric types:

Accepts a numeric value of the same `type` as the field which is
substituted for any explicit `null` values. Defaults to `null`, which
means the field is treated as missing.
means the field is treated as missing. Note that this cannot be set
if the `script` parameter is used.

`on_script_error`::

Defines what to do if the script defined by the `script` parameter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be leaving a comment so late -- was just looking how this turned out! I was wondering if we considered re-using the ignore_malformed boolean flag here instead of introducing a new parameter? That feels simple and consistent to me, and avoids introducing a new enum parameter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Julie, good question. It all started from "let's support some ignore_malformed behaviour" but then we decided to make it specific to scripts especially as we were not convinced that the two would have the same default values, as far as I recall. Another idea could be to support the new parameter as part of the definition of the script:

"field" : {
  "script" : {
    "source" : "here goes the script",
    "on_error" : "continue|fail"
  }
}

There is still time to change this if we want to, so let's discuss this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did discuss re-using ignore_malformed but there are some important differences in the semantics of the two parameters. In particular, ignore_malformed is specifically targeted at handling input data that cannot be converted into a number; because the scripts are typed, there is no way that they can return a malformed object, and so the same logic doesn't really apply. In addition, a script could throw an error for any number of reasons (eg logic errors, array index out of bounds exceptions) and ignore_malformed feels too specific to cover all of these.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice that we are reusing the _ignored meta field though. 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks everyone for the context. I agree the name would feel a bit off, maybe if it had been called ignore_parse_errors we could have reused it!

throws an error at indexing time. Accepts `reject` (default), which
will cause the entire document to be rejected, and `ignore`, which
will register the field in the document's
<<mapping-ignored-field,`_ignored`>> metadata field and continue
indexing. This parameter can only be set if the `script` field is
also set.

`script`::

If this parameter is set, then the field will index values generated
by this script, rather than reading the values directly from the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rather suggests that values that are set on the document would always be ignored, is it correct? I wonder if we should make it more explicit.

Do we have tests for this case (I couldn't find them from a quick look but I might have just missed them), as well as for the case when the script computes values based on content of the document under the same field name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We reject documents that have a value for the field, if the field declares a script. We should probably clarify that in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to explicitly documenting this, I will open a followup

source. Scripts are in the same format as their
<<runtime-mapping-fields,runtime equivalent>>. Scripts can only be
configured on `long` and `double` field types.

<<mapping-store,`store`>>::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static class TokenCountFieldType extends NumberFieldMapper.NumberFieldType {

TokenCountFieldType(String name, boolean isSearchable, boolean isStored,
boolean hasDocValues, Number nullValue, Map<String, String> meta) {
super(name, NumberFieldMapper.NumberType.INTEGER, isSearchable, isStored, hasDocValues, false, nullValue, meta);
super(name, NumberFieldMapper.NumberType.INTEGER, isSearchable, isStored, hasDocValues, false, nullValue, meta, null);
}

@Override
Expand Down
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}
Loading