首页 > 解决方案 > 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 值?无济于事。

任何帮助将不胜感激。

标签: elasticsearchkibanareindex

解决方案


这可能是由于某些文档没有平台字段。您需要在脚本中添加额外的检查以忽略此类文档

"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'))
                  }
              """
  }

如果平台是列表类型,上面也对平台和平台进行了空检查


推荐阅读