Elasticsearch Parent-Child 映射和索引

Elasticsearch Parent-Child Mapping and Indexing

我正在关注《Elasticsearch:权威指南》这本书。这本书已经过时了,当某些东西不起作用时,我正在互联网上搜索它并使其适用于较新的版本。但是我找不到任何对 Parent-Child 映射和索引有用的东西。

例如:

{
    "mappings": {
        "branch": {},
        "employee": {
            "_parent": {
                "type": "branch" 
            }
        }
    }
 }

如何在新版本的 Elasticsearch 中表示以下映射。 我如何索引以下 parent:

{ "name": "London Westminster", "city": "London", "country": "UK" }

和以下孩子:

PUT company/employee/1?parent=London
{
    "name": "Alice Smith",
    "dob": "1970-10-24",
    "hobby": "hiking"
}

此外,我正在使用 elasticsearch python 客户端并在其中提供示例,我们将不胜感激。

The _parent field has been removed in favor of the join field.

The join data type is a special field that creates parent/child relation within documents of the same index. The relations section defines a set of possible relations within the documents, each relation being a parent name and a child name.

company 视为父项,将 employee 视为其子项

索引映射:

{
  "mappings": {
    "properties": {
      "my_join_field": { 
        "type": "join",
        "relations": {
          "company": "employee" 
        }
      }
    }
  }
}

company 上下文中的父文档

PUT /index-name/_doc/1
{
  "name": "London Westminster",
  "city": "London",
  "country": "UK",
  "my_join_field": {
    "name": "company"
  }
}

子文档

PUT /index-name/_doc/2?routing=1&refresh
{
  "name": "Alice Smith",
  "dob": "1970-10-24",
  "hobby": "hiking",
  "my_join_field": {
    "name": "employee",
    "parent": "1"
  }
}