Elasticsearch作成結合フィールド(Nodejs)

Nov 21 2020

私は次のドキュメントを持っています:

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

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

フィールドとのCustomerServiceResultType関係を持ちたいCustomerTypecustomerRelation

これは私のマッピングです:

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

このエラーについての詳細はありません...

ありがとう

回答

1 JoeSorocin Nov 26 2020 at 20:54

リクエスト自体には何の問題もありませんinclude_type_name: true。追加のオプションが1つ必要だと思います。

それはだundefined、デフォルトでnodejsではなく、中に必要とされるES 7.xのサーバー側で。この背後にあるより多くの理由はここにあります。

したがって、これでうまくいくはずです。

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

ところで:ESはJSONのみのインターフェースであり、typeESには非推奨の側面がありますが、2つの概念は非常に遠いため、ここではタイプスクリプトタイプは実際には役割を果たしません。