In the case of nested search, you view nested objects without a parent . Unfortunately, there is no hidden connection that can be applied with nested
objects.
At least for the time being, this means that you are not getting both the "parent" and the attached document in the script. You can confirm this by replacing your script with both of them and checking the result:
# Parent Document does not exist "script": { "script": "doc['primary_content_type_id'].value == 12" } # Nested Document should exist "script": { "script": "doc['content.content_type_id'].value == 12" }
You can do this with the least performance metric by going through object
(instead of essentially using ES for you with nested
). This means that you will need to re-index the documents and nested
documents as one document for this to work. Given how you try to use it, it probably won't be too different and may even improve (especially considering the lack of an alternative).
# This assumes that your default scripting language is Groovy (default in 1.4)
I cached the result because nothing happens here (for example, not comparing dates with now
), so it is safe enough for caching, thereby greatly speeding up the search in the future. Most filters are cached by default, but scripts are one of the few exceptions .
Since it must compare both values โโto make sure it finds the correct internal object, you are duplicating some work, but this is almost inevitable. The term
filter is likely to be better than just doing this check without it.
source share