2017-04-17 51 views
0

我想刪除ElasticSearch中與查詢匹配的數據。使用im ElasticSeach 1.5和Im做這個查詢來實現這一點:刪除ElasticSearch中的數據

POST employee/report/_delete_by_query 
{ 
    "query": { 
     "bool": { 
     "must": [ 
      [     
        { "match_phrase" : { "year_month" : "2016-8" } }, 
        { "term" : { "status" : "Inactive" } } 
      ] 
     ] 
     } 
    } 
} 

而且我這樣做的時候,我得到這樣的結果:

{ 
    "_index": "employee", 
    "_type": "report", 
    "_id": "_delete_by_query", 
    "_version": 6, 
    "created": false 
} 

我每次運行查詢時,_version數得+ 1。 後來我查詢刪除的條款,以檢查是否有是沒有更多的結果:

GET employee/report/_search 
{ 
    "query": { 
     "bool": { 
     "must": [ 
      [     
        { "match_phrase" : { "year_month" : "2016-8" } }, 
        { "term" : { "status" : "Inactive" } } 
      ] 
     ] 
     } 
    } 
} 

和IM仍然得到的結果!我做什麼錯了?我需要刷新ElasticSearch嗎?我錯過了一些步驟?

+0

這個答案將幫助:HTTP://計算器.com/questions/36563687/elasticsearch-2-3-delete-documents-by-query/36564375#36564375 – Val

+0

我正在使用1.5.2版本,所以我認爲它已經是一個核心功能,然後他們刪除它,然後他們寫另一個API ...我錯了嗎? –

回答

1

使用delete-通過查詢API如下正確的方法,也就是你需要使用DELETE HTTP方法打_query端點:

DELETE employee/report/_query 
{ 
    "query": { 
     "bool": { 
     "must": [ 
      [     
        { "match_phrase" : { "year_month" : "2016-8" } }, 
        { "term" : { "status" : "Inactive" } } 
      ] 
     ] 
     } 
    } 
}