在kibana控制台中不断出现此错误“dynamic method[java.util.hashmap,add/1]not found”

xesrikrc  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(816)

我是新来的ElasticSearch堆栈。。。每当我试图在kibana开发工具控制台中执行下面的查询时,总是会遇到下面提到的错误
在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
        }
      }
]

使用的版本
kibana:7.9.3ElasticSearch:7.9.3
提前感谢:)

o75abkj4

o75abkj41#

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
      }
    }
  }
}

相关问题