Skip to content

Instantly share code, notes, and snippets.

@thomasm0
Last active September 19, 2016 19:22
Show Gist options
  • Save thomasm0/e62be0d41f0b0053ec2015e4460e11e4 to your computer and use it in GitHub Desktop.
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
{
"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