2015-03-02 59 views
0

我想在elasticsearch 1.3.5中使用更新API。我有以下文件我試圖更新:elasticsearch更新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 
    } 
} 

我哪裏想更新緯度位置爲0.0。 Api調用成功完成(版本增加等),但沒有更新。

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

任何提示在哪裏看?

+0

哥們,改變==爲=。腳本應該是「ctx._source.results.geometry.location.lat =緯度」 – 2015-03-02 18:31:26

+0

@vineeth老兄,我試過既沒有賦值也沒有加+ +沒有工作,所以這就是發佈在SO – jaksky 2015-03-02 18:35:27

回答

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

您可以參考這個link更多的例子這個用例的詳細信息和更新的API

+0

Thx上的原因。只需要==需要一個放置任務= – jaksky 2015-03-03 10:28:41

+0

是否可以使用*將其應用於數組的所有元素?這是有效的JSON路徑,但得到GroovyScriptExecutionException [IllegalArgumentException [參數類型不匹配]] – jaksky 2015-03-03 13:10:48

+0

您將需要循環所有元素,*不受支持 – 2015-03-03 13:19:15