2

I am usign spring-data-elasticsearch 2.1.4.RELEASE , How can I update a field mapping for a type using ElasticsearchOperations?

when I try operations.putMapping(EsJob.class); again ,there is exception: because the field createdBy already exist, but I want to update it . Anyone have a better solution for this?

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)

1 Answer 1

2

You can't update mappings on existing indices in general. That's why this is also not provided by the ElasticsearchOperations-Interface.

You can apply a new mapping for a new index or add new fields into an existing mapping - or you can delete mappings by deleting the index as well. According to this, you receive an error when putting another mapping in terms to update the existing one.

If major changes are required, you'll have to reindex your data with this new mapping. See this post for doing this without downtime.

Sign up to request clarification or add additional context in comments.

4 Comments

What? You can use PUT /abc/_mapping
I am not sure if this has changed over the years: According to the documentation (e.g. elastic.co/guide/en/elasticsearch/reference/current/…), you still can't change the mapping of an already existing field type.
You can add new mapping, but "Except for supported mapping parameters, you can’t change the mapping or field type of an existing field. Changing an existing field could invalidate data that’s already indexed." source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.