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
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.
3 Comments
Jeff
I have go through your solution,I need to filter not only value. for example key==name and value==John not only value==John.
Jozef - Spatialized.io
Re-read the 2nd suggestion then. It allows you to iterate objects in an array and achieve the
AND query you're after.Jozef - Spatialized.io
Nice, you got it!