I'm working on setting up an Elasticsearch index and would like it to behave (return results) a certain way. I've got a parent / child relationship set up.
curl -XPUT 'http://127.0.0.1:9200/parent/' -d '
{
"mappings": {
"parent": {},
"child": {
"_parent": {
"type": "parent"
}
}
}
} '
And I've populated it with some "parent" documents, and a bunch of "child" documents whose parent is correctly set.
When I search the content using with a normal search query I, of course, get back all documents that match. Parent and child documents but no tie between then. If I search the content using the has_child filter it correctly searches the child documents and returns to me the parent document that matches:
curl -XGET 'http://127.0.0.1:9200/parent/_search' -d '
{
"query": {
"has_child": {
"type": "child",
"query": {
"match": {
"detail": "Stuff I Want To Match"
}
}
}
}
}'
The thing is, I want to search the children and get back the parent AND the children in a single document. Is there a way to accomplish this? Is the parent-child relationship the wrong one?
This could be the most efficient way to do it, using "inner_hits" for parent/child relationship
Refer:https://github.com/elastic/elasticsearch/pull/8153