elasticsearch update api - script不会更改索引文档

时间:2015-03-02 17:14:24

标签: elasticsearch

我正在尝试在elasticsearch 1.3.5中使用update api。我有以下文档,我正在尝试更新:

{
  "_index": "geocode",
  "_type": "google",
  "_id": "kolb dfsafa 303 46546456 z ",
  "_version": 8,
  "_score": 1,
  "_source": {
    "results": [
      {"formatted_address": "kolb 303, 46546456 dfsafa-dfsafa-d",
        "geometry": {
          "location": {
            "lat": 35.0360533,
            "lng": 14.5632209
          },
          "location_type": "ROOFTOP"
        },
        "types": [
          "street_address"
        ]
      }
    ],
    "status": "OK"
  }
}

我有以下脚本:

POST  /geocode/google/kolb%20dfsafa%20303%2046546456%20z%20/_update
{
    "script":"ctx._source.results.geometry.location.lat==latitude",
    "lang": "groovy",
    "params":{
        "latitude" : 0.0
    }
}

我想将lat位置更新为0.0。 Api调用成功完成(版本增加等),但没有更新。

{
   "_index": "geocode",
   "_type": "google",
   "_id": "kolb dfsafa 303 46546456 z ",
   "_version": 9
}

任何提示在哪里看?

1 个答案:

答案 0 :(得分:1)

由于结果是数组,您需要将其作为数组进行处理。请记住,您正在处理原始_source而不是字段数据缓存中的数据。这意味着您需要使用正确的JSON路径。

POST  /geocode/google/kolb%20dfsafa%20303%2046546456%20z%20/_update
{
    "script":"ctx._source.results[0].geometry.location.lat=latitude",
    "lang": "groovy",
    "params":{
        "latitude" : 0.0
    }
}

有关此用例的更多信息以及有关Update API的更多示例,请参阅此link

相关问题