Painless scripts don't work the same in filter and field contexts

We created a scripted field, we debugged it until it returns the correct value (true or false).

It was extremely hard to discover things, e.g. the documentation never specifies how to access the data in a scripted field context using painless, all the documented examples use doc, but none uses painless.

We figured out we could access the data in the field context with params._source.

Once we got it right, we moved to the filters section of the query since we want to filter on that.

Now the script does not work at all!!!

params._source no longer exists, we changed it to doc with .value, but it cannot access any nested field. Our script depends on multiple nested fields, so it is not like we can apply a filter on a single nested path.

Why is that we cannot use the same script in the field context as in the filter context?
Why this has to be too painful?

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.