重新索引Elasticsearch,忽略不在映射中的字段 [英] Re-Index Elasticsearch, ignore fields not in mapping
本文介绍了重新索引Elasticsearch,忽略不在映射中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试在Elasticsearch中测试重新索引API,并遇到以下问题:现有数据包含新索引的严格映射中不存在的字段.有没有办法告诉Elasticsearch简单地忽略这些字段并继续进行下去?
Trying to test out re-index API in elasticsearch and running into issues where existing data contains fields not present in the new index's strict mapping. Is there a way to tell elasticsearch to simply ignore those fields and carry on?
为澄清起见,通过忽略,我的意思是在重新索引过程中不要包括这些字段.
To clarify, by ignore I meant not to include those fields during the re-index process.
推荐答案
如果在运行 reindex
之前可以访问索引设置,则可以执行以下操作:
If you have access to the index settings before running reindex
you can just do:
PUT test/_mapping
{
"dynamic": "false"
}
然后在重新索引完成后将其更改回 strict
.
then change it back to strict
once reindexing is done.
根据您的评论更新
POST _reindex
{
"source": {
"index": "src"
},
"dest": {
"index": "dst"
},
"script": {
"lang": "painless",
"source": """
ctx['_source'].remove('email');
ctx['_source'].remove('username');
ctx['_source'].remove('name');
// removing from nested:
for(item in ctx['_source'].Groups){
item.remove('GroupName');
item.remove('IsActive');
}
"""
}
}
这篇关于重新索引Elasticsearch,忽略不在映射中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文