2016-11-27 47 views
0

我想更新elasticsearch中的多個文檔。 更新應該對應的SQL查詢更新多個文檔

UPDATE tablename SET expired=true where id not in (list_of_ids) 

是否有可能,還是你推薦跟蹤的活動和非活動文件的不同的解決方案?

我想保留並使用不活動的文檔進行統計。

感謝

回答

1

這可以用update by query API很容易做到,像這樣:

POST index/_update_by_query 
{ 
    "script": { 
    "inline": "ctx._source.expired = true" 
    }, 
    "query": { 
    "bool": { 
     "must_not": { 
     "ids": { 
      "values": [1, 2, 3, 4] 
     } 
     } 
    } 
    } 
} 
+0

謝謝,這就是解決方案。在使用elasticsearch的Python中,我只需執行 'es.update_by_query(index,doctype,body)',其中body是您提供的json。 –