Как указано в документации к типу Join , вы можете not создавать отношения родитель-ребенок по нескольким индексам:
Тип соединенияспециальное поле, которое создает отношения родитель / потомок в документах с одинаковым индексом .
Если вы хотите использовать тип данных соединения, вы должны смоделировать его в один индекс .
ОБНОВЛЕНИЕ
Вот как будет выглядеть ваше отображение и индексирование документов:
PUT profiles-purchases-index
{
"mappings": {
"properties": {
"user":{
"type": "keyword"
},
"product":{
"type": "keyword"
},
"profile":{
"type": "join",
"relations":{
"profiles": "purchases"
}
}
}
}
}
Индекс родительского документа:
PUT profiles-purchases-index/_doc/1
{
"user": "abc",
"profile": "profiles"
}
Индекс дочерних документов:
PUT profiles-purchases-index/_doc/2?routing=1
{
"product": "tomato",
"profile":{
"name": "purchases",
"parent": 1
}
}
PUT profiles-purchases-index/_doc/3?routing=1
{
"product": "tomato 2",
"profile":{
"name": "purchases",
"parent": 1
}
}
Выполнить запрос:
GET profiles-purchases-index/_search
{
"query": {
"has_parent": {
"parent_type": "profiles",
"query": {
"match": {
"user": "abc"
}
}
}
}
}
Ответ:
{
...
"hits" : [
{
"_index" : "profiles-purchases-index",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_routing" : "1",
"_source" : {
"product" : "tomato",
"profile" : {
"name" : "purchases",
"parent" : 1
}
}
},
{
"_index" : "profiles-purchases-index",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_routing" : "1",
"_source" : {
"product" : "tomato 2",
"profile" : {
"name" : "purchases",
"parent" : 1
}
}
}
]
}
}
Обратите внимание, что необходимо настроить параметр маршрутизации для индексирования дочерних документов.Но, пожалуйста, обратитесь к документации для этого.