说来惭愧,这本是一个不应该出现的错误:
pojo类中的部分代码:让composeGoodName使用ik分词器。
@Document(indexName = "seasonal",type = "escomposegood", shards = 4, replicas = 0)
public class ESComposeGood {
@Id
private Long id;
@Field(type = FieldType.Text,analyzer = "ik_max_word")
private String composeGoodName;
@Field(type = FieldType.Integer)
private Integer composeGoodPrice;
@Field(type = FieldType.Long)
private Long composeGoodType;
@Field(type = FieldType.Integer)
private Integer composeGoodStatus;
@Field(type = FieldType.Integer)
private Integer composeGoodWeight;
@Field(type = FieldType.Keyword)
private String composeGoodIcon;
@Field(type = FieldType.Integer)
private Integer composeGoodSales;
}
意外发生了,程序跑不起来了,他告诉我:
[mapper [composeGoodName] has different [analyzer]]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ESComposeGoodResitory': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.data.elasticsearch.repository.support.NumberKeyedRepository]: Constructor threw exception; nested exception is
java.lang.IllegalArgumentException:
Mapper for [composeGoodName] conflicts with existing mapping in other types:(这句才是错误的核心)
一番查找后发现如果在使用分词器之前将数据插入了Elasticsearch那么就会发生Elasticsearch无法解析的问题,也就是上述错误所以说:
解决方案:
在向Elasticsearch中插入数据之前就要给需要的进行分词的属性标记好解析,然后再插入数据即可解决问题!