【问题标题】:Elasticsearch Parent-Child Mapping and IndexingElasticsearch 父子映射和索引
【发布时间】:2021-03-23 22:28:21
【问题描述】:

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

例如:

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

如何在新版本的 Elasticsearch 中表示以下映射。 以及如何索引以下父级:

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

和跟随的孩子:

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

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

【问题讨论】:

    标签: python elasticsearch elasticsearch-py elasticsearch-mapping


    【解决方案1】:

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

    连接数据类型是创建父/子的特殊字段 同一索引的文档之间的关系。关系部分 在文档中定义一组可能的关系,每个 关系是父名和子名。

    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"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 2016-01-21
      • 1970-01-01
      相关资源
      最近更新 更多