【问题标题】:Elasticsearch create join field (Nodejs)Elasticsearch 创建连接字段(Nodejs)
【发布时间】:2020-11-27 04:54:52
【问题描述】:

我有以下文档:

export class CustomerServiceResultType{
  id: string;
  body:{customerRelation: string};
}

export class CustomerType{
  id: string;
  body:{name: string};
}

我希望 CustomerServiceResultTypeCustomerType 的字段相关:customerRelation

这是我的映射:

await this.elasticsearchService.indices.putMapping({
  "index": "db",
  "type": "CustomerServiceResultType",
  "body" : {
      "properties": {
        "customerRelation": {
          "type": "join",
          "relations": {
            "CustomerServiceResultType": "CustomerType"
          }
      }
    }
  }
});

这是我得到的错误:

[Nest] 421512   - 11/21/2020, 6:40:42 PM   [ExceptionsHandler] illegal_argument_exception +96414ms
ResponseError: illegal_argument_exception

没有关于此错误的详细信息...

谢谢

【问题讨论】:

    标签: node.js elasticsearch


    【解决方案1】:

    您的请求本身没有任何问题——我认为它只需要一个额外的选项:include_type_name: true

    它在 nodejs 中是 undefined by default,但在服务器端的 ES 7.x 中是必需的。这背后的更多理由是here

    所以这应该可以解决问题:

    await client.indices.putMapping({
      include_type_name: true,
      index: "db",
      type: "CustomerServiceResultType",
      body : {
          properties: {
            customerRelation: {
              type: "join",
              relations: {
                CustomerServiceResultType: "CustomerType"
              }
          }
        }
      }
    });
    

    类型化索引将在 8.x 中删除,因此最好的方法实际上是:

    await client.indices.putMapping({
      index: "db",
      body : {
          properties: {
            customerRelation: {
              type: "join",
              relations: {
                CustomerServiceResultType: "CustomerType"
              }
          }
        }
      }
    });
    

    顺便说一句:你的 typescript 类型在这里并没有真正发挥作用,因为 ES 是一个仅 JSON 的接口,虽然 ES 有已弃用的 type 方面,但这两个概念非常遥远。

    【讨论】:

    • 这个@SexyMF 运气好吗?
    猜你喜欢
    • 2019-02-20
    • 2022-01-07
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 2021-09-15
    相关资源
    最近更新 更多