【ES异常】mapper [sortNum] of different type, current_type [long], merged_type [keyword]
本文目录
一、报错信息
报错信息如下:
Caused by: java.lang.IllegalArgumentException: mapper [sortNum] of different type, current_type [long], merged_type [keyword]
at org.elasticsearch.index.mapper.FieldMapper.doMerge(FieldMapper.java:347)
at org.elasticsearch.index.mapper.NumberFieldMapper.doMerge(NumberFieldMapper.java:1111)
at org.elasticsearch.index.mapper.FieldMapper.merge(FieldMapper.java:333)
at org.elasticsearch.index.mapper.FieldMapper.merge(FieldMapper.java:49)
at org.elasticsearch.index.mapper.ObjectMapper.doMerge(ObjectMapper.java:476)
at org.elasticsearch.index.mapper.RootObjectMapper.doMerge(RootObjectMapper.java:248)
at org.elasticsearch.index.mapper.ObjectMapper.merge(ObjectMapper.java:448)
at org.elasticsearch.index.mapper.RootObjectMapper.merge(RootObjectMapper.java:243)
at org.elasticsearch.index.mapper.Mapping.merge(Mapping.java:88)
at org.elasticsearch.index.mapper.DocumentMapper.merge(DocumentMapper.java:320)
at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.applyRequest(MetaDataMappingService.java:267)
at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.execute(MetaDataMappingService.java:230)
at org.elasticsearch.cluster.service.ClusterService.executeTasks(ClusterService.java:634)
at org.elasticsearch.cluster.service.ClusterService.calculateTaskOutputs(ClusterService.java:612)
at org.elasticsearch.cluster.service.ClusterService.runTasks(ClusterService.java:571)
at org.elasticsearch.cluster.service.ClusterService$ClusterServiceTaskBatcher.run(ClusterService.java:263)
at org.elasticsearch.cluster.service.TaskBatcher.runIfNotProcessed(TaskBatcher.java:150)
at org.elasticsearch.cluster.service.TaskBatcher$BatchedTask.run(TaskBatcher.java:188)
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:575)
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:247)
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:210)
... 3 more
二、错误原因
ES字段类型与Document实体类里的字段类型不一致
三、解决方案
把index.json文件里的ES字段类型与Java代码里的字段类型修改为一致即可。
例如我的index.json修改后的文件如下:
{
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"keywords": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"description": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"url": {
"type": "keyword"
},
"imageUrl": {
"type": "keyword"
},
"siteId": {
"type": "long"
},
"siteType": {
"type": "keyword"
},
"inputdate": {
"type": "date"
},
"popularity": {
"type": "long"
},
"district": {
"type": "keyword"
},
"community": {
"type": "text"
},
"sortNum": {
"type": "long"
}
}
}
对应的Java实体Document如下:
@Data
@Document(indexName = "hot_estate", type = "hot_estate")
@Mapping(mappingPath = "hotEstateIndex.json")
public class HotEstateDocument{
@Id
private String contentId;
/**
* 标题
*/
private String title;
/**
* 关键字
*/
private String keywords;
/**
* 描述
*/
private String description;
/**
* 内容url
*/
private String url;
/**
* 封面多图
*/
private String imageUrl;
/**
* 发布时间
*/
private Date inputdate;
/**
* 站点id
*/
private Long siteId;
/**
* 站点类型
*/
private String siteType;
/**
* 人气
*/
private Integer popularity;
/**
* 排序号
*/
private Integer sortNum;
/**
* 行政区
*/
private String district;
/**
* 小区
*/
private String community;
public static HotEstateDocument content2Document(TCmsContentVo content) {
HotEstateDocument hotEstateDocument=new HotEstateDocument();
BeanUtils.copyProperties(content,hotEstateDocument);
return hotEstateDocument;
}
}
完结!