-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Description
Runtime fields allow you to create a synthetic field derived from the values of other document properties at query time, which prioritises flexibility (you can change these fields at any time) over speed. This issue will address generating these synthetic fields at index time, trading off some of that flexibility for better query performance.
There should be as little impedance mismatch as possible between the scripts used for runtime fields and those used for index time calculations. Ideally, making a runtime field indexed should be as simple as moving the field definition from the runtime section of mappings into the properties section, eg:
"mappings" : {
"runtime" : {
"my_field" : {
"type" : "long",
"script" : " ... some script ... "
}
}
}
becomes:
"mappings" : {
"properties" : {
"my_field" : {
"type" : "long",
"script" : " ... some script ... "
}
}
}
In particular, we will need to reproduce the typed emit functions currently used by runtime scripts, and make _doc, _source and _fields available in the same way (although _fields is probably not a priority here as it essentially duplicates _source at index time).
Now that runtime fields have been moved to core, we can re-use their script factory implementations by mocking a lucene LeafReader over the contents of the parsed lucene Document that is to be indexed.
The steps to take are anticipated to be:
- Build an index time Lookup that presents
_source(from the index request bytes) and_doc(from mappings and value fetchers built against the same lookup) to scripts (Add calculated numeric fields #69531) - Implement a
scriptparameter for each of the mapping types currently built for runtime fields- long (Add calculated numeric fields #69531)
- double (Add calculated numeric fields #69531)
- boolean (Add support for script to boolean field mapper #71454)
- date (Add index-time scripts to date field mapper #71633)
- keyword (Add scripts to keyword field mapper #71555)
- ip (Add index-time scripts to IP field mapper #71617)
- geo_point (Add index-time scripts to geo_point field mapper #71861)