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.
Asked
Active
Viewed 284 times
1 Answers
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.

Joe - GMapsBook.com
- 15,787
- 4
- 23
- 68
-
I have go through your solution,I need to filter not only value. for example key==name and value==John not only value==John. – Jeff Mar 21 '21 at 10:22
-
Re-read the 2nd suggestion then. It allows you to iterate objects in an array and achieve the `AND` query you're after. – Joe - GMapsBook.com Mar 21 '21 at 10:25
-
Nice, you got it! – Joe - GMapsBook.com Mar 21 '21 at 10:52