0

I have a code that find records what I need:

curl -XGET "http://localhost:9200/one/two/_search" -d '
{
  "query" : {
    "range" : {
        "timestamp" : { "gte" : "2014-09-01T00:00:00.000Z", "lt" : "2014-09-01T00:00:00.000Z||+1M"}
    }
  }
}'

Now I want to transform it to code that will delete these records.

According to this doc I tried to change _search to query and got:

{"_index":"one","_type":"two","_id":"_query","found":false}

I tried to change XGET to XDELETE:

{"found":false,"_index":"one","_type":"two","_id":"_search","_version":1}

Elasticsearch version:

"version" : {
    "number" : "1.0.3",
    "build_hash" : "61bfb72d845a59a58cd9910e47515665f6478a5c",
    "build_timestamp" : "2014-04-16T14:43:11Z",
    "build_snapshot" : false,
    "lucene_version" : "4.6"
  }

What is the right query to delete these records?

1 Answer 1

3

Yes you can use delete by query to delete documents which match your query, but instead of using _search you need to say _query

curl -XDELETE "http://localhost:9200/one/two/_query" -d '
{
  "query" : {
    "range" : {
        "timestamp" : { "gte" : "2014-09-01T00:00:00.000Z", "lt" : "2014-09-01T00:00:00.000Z||+1M"}
    }
  }
}'
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I spent an hour staring at it and not noticing _query vs _search.

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.