Spring Data Elasticsearch: Can't merge because of conflicts: [Cannot update enabled setting for [_source]]
Asked Answered
D

1

6

I'm trying to disable the _source field with Spring Data Elasticsearch, in order to add this property:

"_source": {
    "enabled": false
}

I'm doing the following in a @Configuration class:

    @Bean
    public ElasticsearchTemplate elasticsearchTemplate() throws IOException {
        ElasticsearchTemplate template = new ElasticsearchTemplate(getNodeClient());
        Map<Object, Object> mapping = new LinkedHashMap<Object, Object>();
        if (template.indexExists(Computer.class)){
            mapping = template.getMapping(Computer.class);                  
        } else {
            template.createIndex(Computer.class);
        }
        LinkedHashMap<String, Boolean> hashMap = new LinkedHashMap<String, Boolean>();
        hashMap.put("enabled", false);
        mapping.put("_source", hashMap);
        template.putMapping(Computer.class, mapping);
        return template;
    }

But I obtain the following exception:

java.lang.IllegalArgumentException: Can't merge because of conflicts: [Cannot update enabled setting for [_source]]
    at org.elasticsearch.index.mapper.internal.SourceFieldMapper.doMerge(SourceFieldMapper.java:458) ~[elasticsearch-2.2.0.jar:2.2.0]
    at org.elasticsearch.index.mapper.FieldMapper.merge(FieldMapper.java:380) ~[elasticsearch-2.2.0.jar:2.2.0]
    at org.elasticsearch.index.mapper.MetadataFieldMapper.merge(MetadataFieldMapper.java:75) ~[elasticsearch-2.2.0.jar:2.2.0]
    at org.elasticsearch.index.mapper.Mapping.merge(Mapping.java:120) ~[elasticsearch-2.2.0.jar:2.2.0]
    at org.elasticsearch.index.mapper.DocumentMapper.merge(DocumentMapper.java:392) ~[elasticsearch-2.2.0.jar:2.2.0]
    at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.applyRequest(MetaDataMappingService.java:261) ~[elasticsearch-2.2.0.jar:2.2.0]
    at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.execute(MetaDataMappingService.java:230) ~[elasticsearch-2.2.0.jar:2.2.0]
    at org.elasticsearch.cluster.service.InternalClusterService.runTasksForExecutor(InternalClusterService.java:458) ~[elasticsearch-2.2.0.jar:2.2.0]
    at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:762) ~[elasticsearch-2.2.0.jar:2.2.0]
    at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:231) ~[elasticsearch-2.2.0.jar:2.2.0]
    at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:194) ~[elasticsearch-2.2.0.jar:2.2.0]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_102]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_102]
    at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_102]

The error happens because with that configuration I'm trying to set the enabled variable of the org.elasticsearch.index.mapper.internal.SourceFieldMapper to false, but for some strange reason it's being checked with an instance that has that property already setted to true.

How can I do to configure that field to false?

Thanks.

Dishpan answered 5/8, 2016 at 13:42 Comment(1)
Can you share your entity class ?Sharie
D
0

This error only happens when you try to update the mapping for an existing index. In your case there's already 'computer' index with _source set to true. You can check that by running

GET /computer/_mapping

This would return

{
  "computer": {
    "mappings": {
      "_source": {
        "enabled": true
      }
    }
  }
} 

The mapping value of _source filed cannot be updated.

If you need to change the mapping, create a new index with the correct mapping and reindex your data into that index.

Alternatively you can delete the computer index with

DELETE /computer

and Spring Data will create the index with correct mapping on startup.

Dixon answered 11/6, 2020 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.