elasticsearch - Elasticsearch 在重新索引所有记录时删除数组列表
问题描述
所以我试图将我的一个索引重新索引为一个临时索引并删除一个数组列表:platform.platforms。*
这就是我的 Kibana 查询的样子:
POST /_reindex
{
"source": {
"index": "devops-ucd-000001"
},
"dest": {
"index": "temp-ucd"
},
"conflicts": "proceed",
"script": {
"lang": "painless",
"inline": "ctx._source.platform.platforms.removeAll(Collections.singleton('1'))"
}
}
但是我得到的是一个空指针异常:
"script_stack": [
"ctx._source.platform.platforms.removeAll(Collections.singleton('1'))",
" ^---- HERE"
],
"script": "ctx._source.platform.platforms.removeAll(Collections.singleton('1'))",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
我尝试关注这个问题:如何使用 curl 在弹性搜索中删除 arraylist 值?无济于事。
任何帮助将不胜感激。
解决方案
这可能是由于某些文档没有平台字段。您需要在脚本中添加额外的检查以忽略此类文档
"script": {
"lang": "painless",
"inline": """
if(ctx._source.platform!=null && ctx._source.platform.platforms!=null && ctx._source.platform.platforms instanceof List)
{
ctx._source.platform.platforms.removeAll(Collections.singleton('1'))
}
"""
}
如果平台是列表类型,上面也对平台和平台进行了空检查
推荐阅读
- c# - JSON deserializeobject 对象列表始终为空
- runtime-error - 轻量级渲染管道错误
- android - 尝试使用 Android Studio 检索用户位置时出错
- javascript - 查找一个字段与数组中另一个字段进行比较的文档
- java - 大型事务的 Cassandra 连接异常
- html - 如何将字符串转换为角度的双精度
- javascript - 是否有针对 HTML 中的换行行为的 W3C 规范
- android - Android Firebase 电话身份验证第二次未收到短信
- node.js - 如何使用 node 进行代理,使用 express-http-proxy 去除最后的休息
- git - 将 git repo 与现有文件同步