Давайте возьмем данные сопоставления и выборки из https://www.elastic.co/guide/en/elasticsearch/reference/5.5/mapping-parent-field.html:
PUT my_index
{
"mappings": {
"my_parent": {},
"my_child": {
"_parent": {
"type": "my_parent"
}
}
}
}
PUT my_index/my_parent/1
{
"text": "This is a parent document"
}
PUT my_index/my_child/2?parent=1
{
"text": "This is a child document"
}
PUT my_index/my_child/3?parent=1&refresh=true
{
"text": "This is another child document"
}
Запрос на той же странице получает один родительский документ, поскольку оба дочерних документа совпадают:
GET my_index/my_parent/_search
{
"query": {
"has_child": {
"type": "my_child",
"query": {
"match": {
"text": "child document"
}
}
}
}
}
С некоторыми небольшими изменениями вы сможете искать на has_parent
:
GET my_index/my_child/_search
{
"query": {
"has_parent": {
"parent_type": "my_parent",
"query": {
"match": {
"text": "parent"
}
}
}
}
}
PS: В 6.x это немного меняется. Если возможно, я бы сейчас перешел на 6, чтобы избежать боли при обновлении.