尝试在Elasticsearch中更新嵌套的Geoip位置字段

问题描述 投票:0回答:1

这是我尝试过的:

POST orders/_update_by_query
{
    "script" : "ctx._source.geoip += newElement",
    "params": {
        "newElement": {
           "location" : "[40.730610, -73.935242]"
        }
    },
  "query": {
    "term": {
      "CITY": {
        "value": "nyc"
      }
    }
  }
}

上面抛出错误[params]中START_OBJECT的未知键。

第二次尝试:

POST orders/_update_by_query
{
  "script":{
    "source":
      "for (item in ctx._source.geoip){item.location = '[40.730610, -73.935242]'}",
      "lang":"painless"
  },
  "query": {
    "term": {
      "CITY": {
        "value": "nyc"
      }
    }
  }
}

以上抛出空指针异常,并指向source.geoip的句点

我还尝试将location的值更改为test,但收到相同的错误。

这是我的映射:

{
  "orders" : {
    "mappings" : {
      "properties" : {
        "geoip" : {
          "dynamic" : "true",
          "properties" : {
            "location" : {
              "type" : "geo_point"
            }
          }
        }
     }
}

我正在使用ES v7.2和Kibana v7.2

elasticsearch geolocation kibana elasticsearch-painless
1个回答
0
投票

第一种方法中的几个问题:

  • [params需要在脚本对象内定义,而不是在其下定义
  • [newElement需要使用params.newElement进行访问
  • 您不能将+= params.newElement附加到不存在的ctx._source.geoip
  • 您不能将对象附加到单值字段上,只能分配它
  • [locationgeo_point类型,因此,[40.730610, -73.935242][lon, lat])或"-73.935242,40.730610""lat,lon"),但不能同时包含两者]]
  • 工作命令:

POST orders/_update_by_query
{
  "script": {
    "inline": "ctx._source.geoip = params.newElement",
    "params": {
      "newElement": {
        "location": [
          40.73061,
          -73.935242
        ]
      }
    }
  },
  "query": {
    "term": {
      "CITY": {
        "value": "nyc"
      }
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.