我正在使用spring-data-elasticsearch 2.1.4.RELEASE,如何使用ElasticsearchOperations更新类型的字段映射?
当我再次尝试operations.putMapping(EsJob.class);时,出现了异常:因为字段createdBy已经存在,但我想要更新它。有人有更好的解决方案吗?
Servlet.service() for servlet [dispatcher] in context with path [/api] threw exception [Request processing failed; nested exception is java.lang.IllegalgumentException: Mapper for [createdBy] conflicts with existing mapping in other types:
[mapper [createdBy] has different [store] values, mapper [createdBy] has different [analyzer]]] with root cause
java.lang.IllegalArgumentException: Mapper for [createdBy] conflicts with existing mapping in other types:
[mapper [createdBy] has different [store] values, mapper [createdBy] has different [analyzer]]
at org.elasticsearch.index.mapper.FieldTypeLookup.checkCompatibility(FieldTypeLookup.java:153)
at org.elasticsearch.index.mapper.FieldTypeLookup.copyAndAddAll(FieldTypeLookup.java:115)
at org.elasticsearch.index.mapper.MapperService.merge(MapperService.java:381)
at org.elasticsearch.index.mapper.MapperService.merge(MapperService.java:320)
at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.applyRequest(MetaDataMappingService.java:306)
at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.execute(MetaDataMappingService.java:230)
at org.elasticsearch.cluster.service.InternalClusterService.runTasksForExecutor(InternalClusterService.java:468)
at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:772)
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:231)
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
发布于 2017-07-12 07:22:59
一般来说,您不能更新现有索引上的映射。这就是为什么ElasticsearchOperations
-Interface不提供此功能的原因。
您可以为新索引应用新映射或在现有映射中添加新字段,也可以通过删除索引来删除映射。根据这一点,当将另一个映射放入更新现有映射时,您会收到一个错误。
如果需要进行重大更改,则必须使用此新映射重新索引数据。有关在不停机的情况下执行此操作的信息,请参阅此post。
https://stackoverflow.com/questions/45050478
复制相似问题