Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete by query does not work with range query #7259

Closed
dan-s1 opened this issue Aug 13, 2014 · 12 comments
Closed

Delete by query does not work with range query #7259

dan-s1 opened this issue Aug 13, 2014 · 12 comments

Comments

@dan-s1
Copy link

dan-s1 commented Aug 13, 2014

I have a corpus of 1000 documents which have 3 _timestamp ranges between 0-30, 30-60 and 60-90
days. The 0-30 range has 334 documents, and both the 30-60 and the 60-90 each have 333 documents.I attempted to trim the index down by using the Delete by Query API with a range query.to get rid of those documents in range 60-90. When running the query as a search:

{
"query" :
{
"range" :
{
"_timestamp" :
{
"lt" : "now-1440h"
}
}
}
}

I get 333 documents yet when I run as a Delete by Query using ElasticSearch Head or using the Jest client no documents are deleted. I tried using the refresh endpoint and that did not help.
I am running this on ElasticSearch 1.1.0

@clintongormley
Copy link

This is likely a problem with these clients not being able to send a body with a DELETE request. You could try passing the body as the source query string parameter instead.

@dan-s1
Copy link
Author

dan-s1 commented Aug 13, 2014

Can you please provide an example using the query I have above?

@clintongormley
Copy link

curl -XDELETE 'http://localhost:9200/myindex/_query?source=%7B%22query%22%3A%7B%22range%22%3A%7B%22timestamp%22%3A%7B%22lt%22%3A%22now-1440h%22%7D%7D%7D%7D'

@dan-s1
Copy link
Author

dan-s1 commented Aug 13, 2014

That still did not work in those clients.
What I am surprised with your original response is that I can get ElasticSearch Head to delete when I submit a query_string query using a range for example:

{
"query":
{
"query_string":
{
"query":"dt:["2014-05-14T00:00:00+0000" TO "2014-06-13T00:00:00+0000"]"
}
}
}

@dan-s1
Copy link
Author

dan-s1 commented Aug 13, 2014

I also can use these clients to delete with match_all and ids queries in the body.

@clintongormley
Copy link

In which case you probably don't have any data in the _timestamp field. Either way this is not a bug. The best place to ask for help with questions like this is in the google groups forum: https://groups.google.com/forum/#!forum/elasticsearch

@dan-s1
Copy link
Author

dan-s1 commented Aug 13, 2014

Actually we have data in the _timestamp field as _timestamp is enabled in our mapping file and sorry for the typo before but this query worked:
{
"query":
{
"query_string":
{
"query":"_timestamp:["2014-05-14T00:00:00+0000" TO "2014-06-13T00:00:00+0000"]"
}
}
}

@dan-s1
Copy link
Author

dan-s1 commented Aug 13, 2014

and this did not:
{
"query" :
{
"range" :
{
"_timestamp" :
{
"lt" : "now-1440h"
}
}
}

}

which would indicate something in the Delete by Query API does not accept all queries.

@dan-s1
Copy link
Author

dan-s1 commented Aug 13, 2014

Also one more thing. I ran the same query against a field named ingestDate which is a defined as a dateOptionalTime type in the mapping file and it always has a value and the range query in a search returned 333 documents but with delete on query it failed. The query is below:

{
"query" :
{
"range" :
{
"ingestDate" :
{
"lt" : "now-1440h"
}
}
}

}

@clintongormley
Copy link

This works for me:

PUT /test 
{
  "mappings": {
    "test": {
      "_timestamp": {
        "format": "yyyy-MM-dd",
        "enabled": true
      }
    }
  }
}
PUT /test/test/1?timestamp=2015-01-01
{}

PUT /test/test/2?timestamp=2014-01-01
{}

PUT /test/test/3?timestamp=2013-01-01
{}

This search returns the 2nd and 3rd docs:

GET /_search
{
  "query": {
    "range": {
      "_timestamp": {
        "lt": "now-1440h"
      }
    }
  }
}

DELETE /test/_query 
{
  "query": {
    "range": {
      "_timestamp": {
        "lt": "now-1440h"
      }
    }
  }
}

This returns only the first doc:

GET /_search

@rahst12
Copy link

rahst12 commented Aug 13, 2014

@clintongormley What version of elasticsearch are you testing with?

@clintongormley
Copy link

Originally on master - I went back and tested this on 1.3.1, 1.2.1 and 1.1.2.... turns out this was indeed broken in the 1.1.x branch!

Looks like it was fixed by #5540

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants