I am evaluating whether I can safely use painless scripting for one of our applications. We only feel comfortable with very strict contexts. The "Field" context seems the safest because it only allows read-only against the document. However, I would like to be able to include queries against text fields but "doc values are not available as text fields by default". Does anyone know how to loosen this context slightly to allow text fields?
Thanks
CodePudding user response:
You can access text
fields in scripts (within "Field" context) by going through params['_source']
instead of doc values which are not available for text
fields.
For example, to compute the length of a text
field you can use the following script:
params._source['my-text-field'].length()
i.e. params._source['my-text-field']
is actually the raw string that is present in your source document.