versions used:
Spring Data Elasticsearch = 5.0.1
Elasticsearch = 8.5.3
Spring Boot = 3.0.5
ElasticProduct Doc type:
@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;
}
elastic Mapping: 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"
}
}
}
}
}
}
Getting below error for above setup:
[es/indices.create] failed: [illegal_argument_exception] unknown setting [index.mappings.properties.productCategory2.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
The @Setting
annotation is to provide the settings for the index, not the mapping. You pass in the mapping as part of the settings by adding it there - and your settings from the file would en up under "settings.settings".
Split your file into the part that contains the setting and one that contains the mapping and pass these in with the @Setting
and @Mapping
annotation. As an alternative, for the mappping you can define the values with the corresponding annotations on the properties of the entity class.