【问题标题】:Create a parent-child relationship after the parent type already exists在父类型已经存在后创建父子关系
【发布时间】:2016-01-28 18:57:54
【问题描述】:

我正在尝试将新类型添加为现有类型的子类型。从ElasticSearch documentation,看起来这是可能的,但没有关于如何做到这一点的详细信息。

文档是这样说的:

这必须在创建索引时完成,或者在创建子类型之前使用更新映射 API 完成。

update-mapping API documentation 中没有关于设置父子关系的详细信息。

直觉上,我认为应该允许在父母已经存在之后建立父子关系,因为父母不需要知道孩子的任何事情。

这是我小时候创建新类型时遇到的错误:

{
"error": {
  "root_cause": [
    {
      "type": "illegal_argument_exception",
      "reason": "can't add a _parent field that points to an already existing type"
    }
  ],
  "type": "illegal_argument_exception",
  "reason": "can't add a _parent field that points to an already existing type"
},
"status": 400
}

【问题讨论】:

  • 你试过了吗?发生了什么?
  • 这是错误:{ "type": "illegal_argument_exception", "reason": "can't add a _parent field that point to an already existing type" }

标签: elasticsearch


【解决方案1】:

这在 ElasticSearch 中是不允许的,因此它要求在同一个请求或调用中同时创建父级和子级。

【讨论】:

    【解决方案2】:

    回答我自己的问题。找到this post 解释了为什么这是不可能的。该文档仍然具有误导性,因为它声称这是可能的。

    【讨论】:

      【解决方案3】:

      对于使用 Spring Data Elasticsearch 3.0.x (ES 5.x) 的任何人:当您有单独的父子实体(文档)存储库并且父存储库被实例化时,可能会发生此错误首先(它反过来首先定义父映射)。

      解决方法是修复创建存储库的顺序,例如像这样:

      /**
       * Workaround: Child ES type must be defined before the parent. The order matters!
       */
      @Configuration
      @DependsOn({"childRepository", "parentRepository"})
      public class ElasticConfig {
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-02
        相关资源
        最近更新 更多