0

We want to have a solution to compare a nested key value with root level field. Can we access a nested key value for filter(script)? We can get value from script field(parms), but we can't use parms in filter function. Only doc can be used from my knowledge, but doc in filter script we can't access nested structure. If doc under nested path, the meanwhile we can't access root level field.

1 Answer 1

0

You could leverage the copy_to / include_in_root parameters in order to allow _source access in a script, as I've outlined in my answer to How to iterate through a nested array in elasticsearch with filter script?

Alternatively, you could hijack a function_score query which, unlike standard filters, still has access to params._source without any mapping adjustments. Discussed in more detail in this thread.

Sign up to request clarification or add additional context in comments.

3 Comments

I have go through your solution,I need to filter not only value. for example key==name and value==John not only value==John.
Re-read the 2nd suggestion then. It allows you to iterate objects in an array and achieve the AND query you're after.
Nice, you got it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.