mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Painless: add fielddata accessors (.value/.values/.distance()/etc)
This gives better coverage and consistency with the scripting APIs, by whitelisting the primary search scripting API classes and using them instead of only Map and List methods. For example, accessing fields can now be done with `.value` instead of `.0` because `getValue()` is whitelisted. For now, access to a document's fields in this way (loads) are fast-pathed in the code, to avoid dynamic overhead. Access to geo fields and geo distance functions is now supported. TODO: date support (e.g. whitelist ReadableDateTime methods as a start) TODO: improve docs (like expressions and groovy have for document's fields) TODO: remove fast-path hack Closes #18169 Squashed commit of the following: commitec9f24b242
Author: Robert Muir <rmuir@apache.org> Date: Thu May 5 17:59:37 2016 -0400 cutover to <Def> instead of <Object> here commit9edb155043
Author: Robert Muir <rmuir@apache.org> Date: Thu May 5 17:03:02 2016 -0400 add fast-path for docvalues field loads commitf8e38c0932
Author: Robert Muir <rmuir@apache.org> Date: Thu May 5 16:47:31 2016 -0400 Painless: add fielddata accessors (.value/.values/.distance()/etc)
This commit is contained in:
parent
c4090a1841
commit
e3ce6c9048
6 changed files with 126 additions and 17 deletions
|
@ -115,9 +115,8 @@ GET hockey/_search
|
|||
----------------------------------------------------------------
|
||||
// AUTOSENSE
|
||||
|
||||
You must always specify the index of the field value you want, even if there's only a single item in the field.
|
||||
All fields in Elasticsearch are multi-valued and Painless does not provide a `.value` shortcut. The following example uses a Painless script to sort the players by their combined first and last names. The names are accessed using
|
||||
`input.doc['first'].0` and `input.doc['last'].0`.
|
||||
The following example uses a Painless script to sort the players by their combined first and last names. The names are accessed using
|
||||
`input.doc['first'].value` and `input.doc['last'].value`.
|
||||
|
||||
[source,js]
|
||||
----------------------------------------------------------------
|
||||
|
@ -132,7 +131,7 @@ GET hockey/_search
|
|||
"order": "asc",
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"inline": "input.doc['first'].0 + ' ' + input.doc['last'].0"
|
||||
"inline": "input.doc['first'].value + ' ' + input.doc['last'].value"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +217,7 @@ GET hockey/_search
|
|||
"full_name_dynamic": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"inline": "def first = input.doc['first'].0; def last = input.doc['last'].0; return first + ' ' + last;"
|
||||
"inline": "def first = input.doc['first'].value; def last = input.doc['last'].value; return first + ' ' + last;"
|
||||
}
|
||||
},
|
||||
"full_name_static": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue