2017-04-11 18 views
0

我有一個腳本,調用Elasticsearch的一些update_by_query「通過查詢更新」不能按預期的方式直接調用

在這裏,我與id=299966更新項目並改變垃圾桶標誌,trash=0

_update_by_query 
{ 
    "query": { 
    "query": { 
     "bool": { 
     "must": [ 
      { 
      "terms": { 
       "_id": [ 
       299966 
       ] 
      } 
      } 
     ], 
     "should": [ 

     ] 
     } 
    } 
    }, 
    "script": { 
    "inline": "ctx._source.trash=0" 
    } 
} 

然後,我id=299966(同一項目)的項目trash=1

_update_by_query 
{ 
    "query": { 
    "query": { 
     "bool": { 
     "must": [ 
      { 
      "terms": { 
       "_id": [ 
       299966 
       ] 
      } 
      } 
     ], 
     "should": [ 

     ] 
     } 
    } 
    }, 
    "script": { 
    "inline": "ctx._source.trash=1" 
    } 
} 

事情是這樣做的這兩個操作後,如果我搜索的項目與id=299966,我得到trash=0,當它應該是trash=1,因爲它是最後一個執行編輯。我總是遵守命令,而我自己的日誌顯示trash=0是第一次執行,然後是trash=1

update_by_query邏輯中是否有任何東西避免進行兩個調用?我是否需要等待幾秒鐘才能創建第二個update_by_query?

PS:Nervemind那些雙重query上的代碼。它工作正常。

在此先感謝。

+0

端點被稱爲'_update_by_query'而不是'update_by_query',你能否確認你使用的是正確的?你有哪個版本的ES? – Val

+0

是的,我使用的是正確的。我正在使用ES 2.3。 –

回答

0

我發現的解決方案是在每_update或每_update_by_query之後使用_flush

myindex/_update_by_query 
{ 
    "query": { 
    "query": { 
     "bool": { 
     "must": [ 
      { 
      "terms": { 
       "_id": [ 
       299966 
       ] 
      } 
      } 
     ], 
     "should": [ 

     ] 
     } 
    } 
    }, 
    "script": { 
    "inline": "ctx._source.trash=0" 
    } 
} 

myindex/_flush 

myindex/_update_by_query 
{ 
    "query": { 
    "query": { 
     "bool": { 
     "must": [ 
      { 
      "terms": { 
       "_id": [ 
       299966 
       ] 
      } 
      } 
     ], 
     "should": [ 

     ] 
     } 
    } 
    }, 
    "script": { 
    "inline": "ctx._source.trash=1" 
    } 
} 
相關問題