使用 spring-data-elasticsearch,如何更新字段映射?

using spring-data-elasticsearch, how to update a field mapping?

我正在使用 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)

您通常无法更新现有索引的映射。这就是 ElasticsearchOperations-Interface 也没有提供的原因。

您可以为新索引应用新映射或将新字段添加到现有映射中 - 或者也可以通过删除索引来删除映射。据此,您在使用另一个映射更新现有映射时会收到错误消息。

如果需要进行重大更改,您将必须使用此新映射重新编制数据索引。请参阅此 post 了解如何在不停机的情况下执行此操作。