Springboot中Map的ElasticSearch问题

t30tvxxf  于 2023-05-06  发布在  ElasticSearch
关注(0)|答案(1)|浏览(146)

使用的版本:
Spring Data Elasticsearch = 5.0.1
Elasticsearch = 8.5.3
Sping Boot = 3.0.5
ElasticProduct单据类型:

@Setting(settingPath = "product-settings.json")
public class ElasticProduct {
    @Id
    @Field
    public String id;
    @Field
    public String productId;
    @Field
    public String productName;
    @Field
    public String productCategory1;
    @Field
    public String productCategory2;
    @Field(type = FieldType.Nested)
    public List<ElasticProductVariant> productVariantList;

}

public class ElasticProductVariant {
    public String productVariantId;
    public String productVariantName;
    public String productBrand;
}

弹性Map:product-settings.json

{
  "settings": {
    "analysis": {
      "filter": {
        "english_stop": {
          "type": "stop",
          "stopwords": "_english_"
        },
        "english_stemmer": {
          "type": "stemmer",
          "language": "english"
        },
        "edgeNGram_filter": {
          "type": "edge_ngram",
          "min_gram": 2,
          "max_gram": 20,
          "side": "front"
        }
      },
      "analyzer": {
        "edge_nGram_analyzer": {
          "type": "custom",
          "tokenizer": "edge_ngram_tokenizer",
          "filter": [
            "lowercase",
            "asciifolding",
            "english_stop",
            "english_stemmer",
            "edgeNGram_filter"
          ]
        }
      },
      "tokenizer": {
        "edge_ngram_tokenizer": {
          "type": "edge_ngram",
          "min_gram": "2",
          "max_gram": "20",
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "productName": {
        "type": "text",
        "analyzer": "edge_nGram_analyzer",
        "search_analyzer": "standard"
      },
      "productDescription": {
        "type": "text",
        "analyzer": "edge_nGram_analyzer",
        "search_analyzer": "standard"
      },
      "productCategory1": {
        "type": "text",
        "analyzer": "edge_nGram_analyzer",
        "search_analyzer": "standard"
      },
      "productCategory2": {
        "type": "text",
        "analyzer": "edge_nGram_analyzer",
        "search_analyzer": "standard"
      },
      "productVariantList": {
        "type": "nested",
        "properties": {
          "productBrand": {
            "type": "text",
            "analyzer": "edge_nGram_analyzer",
            "search_analyzer": "standard"
          }
        }
      }
    }
  }
}

上述设置出现以下错误:
[es/index.create]失败:[illegal_argument_exception]未知设置[index.mappings.properties.productCategory2.type]请检查是否安装了任何必需的插件,或检查重大更改文档以了解已删除的设置

cbjzeqam

cbjzeqam1#

@Setting注解提供索引的设置,而不是Map。你可以通过在这里添加Map作为设置的一部分来传递它-并且你的设置文件将出现在“settings.settings”下。
将文件拆分为包含设置的部分和包含Map的部分,并将它们与@Setting@Mapping注解一起传递。作为替代方案,对于Map,您可以在实体类的属性上定义具有相应注解的值。

相关问题