我尝试使用 Spring Data Elasticsearch 禁用_source
字段,以便添加此属性:
"_source": {
"enabled": false
}
我在@Configuration
课程中执行以下操作:
@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;
}
但我获得以下例外:
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]
发生错误是因为在配置中我试图将enabled
的{{1}}变量设置为 false ,但出于某种奇怪的原因,它会出现#39}是的
使用已将该属性设置为 true 的实例进行检查。
如何将该字段配置为false?
感谢。
答案 0 :(得分:0)
仅当您尝试更新现有索引的映射时,才会发生此错误。在您的情况下,已经有“ 计算机”索引,其中_source
设置为 true 。您可以通过运行
GET /computer/_mapping
这将返回
{
"computer": {
"mappings": {
"_source": {
"enabled": true
}
}
}
}
{strong}提交的_source
的映射值无法。
如果需要更改映射,请使用正确的映射创建一个新索引,然后将数据重新索引到该索引中。
或者,您可以使用
删除计算机索引。DELETE /computer
Spring数据将在启动时创建具有正确映射的索引。