我想删除ElasticSearch中与查询匹配的数据。我正在使用ElasticSeach 1.5和Im执行此查询来实现此目的:
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" } }
]
]
}
}
}
我仍然得到了结果!我做错了什么?我需要刷新ElasticSearch吗?我错过了一些步骤?
答案 0 :(得分:1)
使用按查询删除API的正确方法如下,即您需要使用_query
HTTP方法点击DELETE
端点:
DELETE employee/report/_query
{
"query": {
"bool": {
"must": [
[
{ "match_phrase" : { "year_month" : "2016-8" } },
{ "term" : { "status" : "Inactive" } }
]
]
}
}
}