2016-11-27 102 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。 –