-
-
Save matthiasg/2b8748cfdf919ce77c3fd0438613cee6 to your computer and use it in GitHub Desktop.
sample elasticsearch query to sort parent based on child field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"query":{ | |
"has_child":{ | |
"query":{ | |
"function_score":{ | |
"functions":[ | |
{ | |
"field_value_factor":{ | |
"factor":1, | |
"field":"count" | |
} | |
} | |
] | |
} | |
}, | |
"score_mode":"avg", | |
"type":"my_child_doc_type" | |
} | |
} | |
} |
what if we needed to have results where filter needs to apply to both parent and child ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Brilliant, Thanks. This worked like a charm for a POC I was working on that needed parents sorted based by children field... I also needed to:
This has fall short on 1. With any sort of query resulting to "nested: QueryParsingException...No query registered for [functions]]".
Any Idea on how to expand this to take say a "query_string"?
Cheers.