Query Parent and Child at the same time

Hello,

I have a parent document "lead" with a child document "lead_contact".

I am trying to query a "name" field on the parent while using the has_child query at the same time to search through the fields "name", "telephone_number", "cellphone_number" and "email" on the "lead_contact" document.

This is my query so far:
POST leads/_search
{
"query": {
"bool": {
"should": {
"match": {
"name" : "test",
},
},
"should": {
"has_child": {
"type": "lead_contact",
"query": {
"multi_match": {
"query": "test",
"fields": ["name", "telephone_number", "cellphone_number", "email"],
"operator": "or"
}
}
}
}
}
}
}

The above query will not always search the "name" of the "lead" correctly. Any assistance will be much appreciated, thank you in advance.

Please take the additional time to properly format your code samples using markdown, as this will make it much easier for the reader to follow your code sample - which in turn will increase the likelihood of getting an answer. Thank you!

Can you please be more exact what you mean with not searching always correctly? Are some searches working as expected and others are not? Are no searches working? How did you index that field? Is everything working all the time when you remove the has_child part from your query?

Can you provide a fully reproducible example?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.