在kibana控制台中不断收到此错误“找不到动态方法[java.util.HashMap,添加/ 1]”

时间:2020-10-30 07:17:31

标签: elasticsearch kibana elastic-stack

我是Elasticsearch堆栈的新手...每当我尝试在Kibana Dev Tool Console中执行以下查询时,都会遇到以下提到的错误

  • 在Kibana控制台中执行的查询
POST employees-details/_update_by_query
{
  "query": {
    "match": {
      "EmpName": "Arvind"
    }
  },
  "script": {
    "source": "ctx._source.Address.add(params.tag)",
    "lang": "painless",
    "params": {
      "tag":{
        "AddressID":144,
        "AddressNumber":458
      }
    }
  }
}

在执行上述查询^^

时保持此错误\/
"caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "dynamic method [java.util.HashMap, add/1] not found"
    }
  • 样本数据
[
      {
        "_index" : "employees-details",
        "_type" : "_doc",
        "_id" : "101",
        "_score" : 1.0,
        "_source" : {
          "EmpUserID" : 101,
          "Gender" : "Male",
          "EmpName" : "John",
          "Age" : 35
        }
      },
      {
        "_index" : "employees-details",
        "_type" : "_doc",
        "_id" : "106",
        "_score" : 1.0,
        "_source" : {
          "EmpUserID" : 106,
          "Address" : {
            "AddressNumber" : 201,
            "AddressID" : 200
          },
          "Gender" : "Male",
          "EmpName" : "Arvind",
          "Age" : 30
        }
      }
]

  • 使用的版本

木假名:7.9.3 elasticsearch:7.9.3

先谢谢了:)

1 个答案:

答案 0 :(得分:1)

由于Address是一个哈希,因此不能使用add()方法(适用于数组,列表等集合)。相反,您需要先将Address转换为列表,然后调用add()

POST employees-details/_update_by_query
{
  "query": {
    "match": {
      "EmpName": "Arvind"
    }
  },
  "script": {
    "source": "if (!(ctx._source.Address instanceof Collection)) {ctx._source.Address = [ctx._source.Address];} ctx._source.Address.add(params.tag)",
    "lang": "painless",
    "params": {
      "tag":{
        "AddressID":144,
        "AddressNumber":458
      }
    }
  }
}