elasticsearch kibana 更新文档 space 使用查询更新

elasticsearch kibana update document which has space using update by query

我有一个要更新的字段,其中包含 space。

POST /index/type/_update_by_query
{
  "query": {
      "match_phrase":{
        "field": "value"
      }
  },
  "script":{
    "lang": "painless",
    "inline": "ctx._source.Existing Field = New_Value"
  }
}

但是我得到这个错误。

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "compile error",
        "script_stack": [
          "ctx._source.Existing Field = New_Value",
          "                     ^---- HERE"
        ],
        "script": "ctx._source.Existing Field = New_Value",
        "lang": "painless"
      }
    ],
    "type": "script_exception",
    "reason": "compile error",
    "script_stack": [
      "ctx._source.Existing Field = New_Value",
      "                     ^---- HERE"
    ],
    "script": "ctx._source.Existing Field = New_Value",
    "lang": "painless",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "unexpected token ['Field'] was expecting one of [{<EOF>, ';'}]."
    }
  },
  "status": 500
}

当我在没有 space 的字段上执行此查询时,它工作正常。 如何处理字段名称中有 space 的情况?

ELK 版本 = 5.4.3 我在文档中读到不建议在字段名称中使用 spaces,但这些字段是从某个服务器动态创建的,每天大约有 1M 数据条目。因此,我想对所有匹配的条目执行 update_by_query。

试试这个:

POST index/type/_update_by_query
{
  "script":{
    "lang": "painless",
    "inline": "ctx._source['Existing Field'] = 'New Value'"
  }
}

这是可能的,因为 ctx._source 是无痛 Map, which is a normal Java HashMap. It allows you to access fields with weird characters and also add and remove fields in update 查询的一个实例。

希望对您有所帮助!