Referring to the examples mentioned in the official documentation of building a parent-child relationship - https://www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html
The link has provided question-answer join relationship where question is a parent and answer is a child type.
If you need to search for all parents matching some text along with their children matching some text specific to children in one query, how would you do that?
Let's say they have key-value pairs in the json document as below and we search for parents matching a text in the question and children matching a value in answer-text.
Parent --> question --> "question-text" : "Geography: Where is Mt. Everest?"
Child --> answer --> "answer-text" : "Nepal?"
We do not want just parents or just children in the result but all parents with their associated children which matched the query.
I know inner hits is an option but could not figure out the usage - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html
I hope the question is clear, can add more details if needed.
I also tried the example mentioned here for parent-child inner hits:
Example:
POST labelling_index/_search
{
"query": {
"has_child": {
"type": "child",
"query": {
"match": {
"number": 2
}
},
"inner_hits": {}
}
}
}
This gives me the matching children of all parents. How do I add a filter to the parent and query only for specific parents in the same query (along with the child filter)? Is it possible to filter parent records on a specific field in the same query?
Something like this -
POST test_index/_search
{
"query": {
--match parents first on number:1 and then match the children below--
"has_child": {
"type": "child",
"query": {
"match": {
"number": 2
}
},
"inner_hits": {}
}
}
}