Last active
September 19, 2016 19:22
-
-
Save thomasm0/e62be0d41f0b0053ec2015e4460e11e4 to your computer and use it in GitHub Desktop.
A simple Elasticsearch query to return a parent document with a children for a specific user id
This file contains 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
{ | |
"index": "INDEX_NAME", | |
"type": "PARENT_TYPE_NAME", | |
"body": { | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"query_string": { | |
"default_field": "title", | |
"query": "SEARCH_QUERY" | |
} | |
}, | |
{ | |
"term": { | |
"user_id": 1 | |
} | |
} | |
], | |
"should": [ | |
{ | |
"has_child": { | |
"type": "CHILD_TYPE_NAME", | |
"query": { | |
"filtered": { | |
"query": { | |
"bool": { | |
"must": { | |
"term": { | |
"user_id": 1 | |
} | |
} | |
} | |
} | |
} | |
}, | |
"inner_hits": {} | |
} | |
} | |
] | |
} | |
}, | |
"from": 0, | |
"size": 200, | |
"sort": { | |
"title.sort": { | |
"order": "desc" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment