2017-04-17 56 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" } } 
      ] 
     ] 
     } 
    } 
}