0

I want to delete data in ElasticSearch that matches query. Im using ElasticSeach 1.5 and Im doing this query to achieve this:

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

And when I do this, I get this result:

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

Every time I run the query, the _version numbers gets +1. Then I query the terms deleted, to check that there're no more results:

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

And Im still getting results! What Im doing wrong? Do I need to refresh ElasticSearch? Im missing some step?

2
  • This answer will help: stackoverflow.com/questions/36563687/… Commented Apr 17, 2017 at 19:19
  • Im working with version 1.5.2 so I think it's already a core function, then they removed it, and then they wrote another api to this... Im wrong? Commented Apr 17, 2017 at 19:37

1 Answer 1

1

The correct way of using the delete-by-query API is as follows, i.e. you need to hit the _query endpoint using the DELETE HTTP method:

DELETE employee/report/_query
{
   "query": {
      "bool": {
         "must": [
           [                 
                   { "match_phrase" : { "year_month" : "2016-8" }  },
                   { "term" : { "status" : "Inactive" }  }
            ]
         ]
      }
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.