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.