# Delete by datetime range query

**URL:** <https://discuss.elastic.co/t/delete-by-datetime-range-query/8040>\
**Category:** Elasticsearch\
**Created:** [June 11, 2012, 9:46am UTC](https://discuss.elastic.co/t/delete-by-datetime-range-query/8040 "2012-06-11T09:46:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkoum](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dkoum](https://discuss.elastic.co/u/dkoum)\
**Post date:** [June 11, 2012, 9:46am UTC](https://discuss.elastic.co/t/delete-by-datetime-range-query/8040/1 "2012-06-11T09:46:57Z")

</div>

Hi all,

I am trying to delete documents based on their datetime.

datetime field is defined in the mapping as:  
"dt":{"type":"date","format":"basic\_date\_time\_no\_millis"}

when I query for documents in a specific date range, es answers correctly

curl -XGET '[http://myserver:9200/webindex/result/\_search](http://myserver:9200/webindex/result/_search)' -d '{"query":{"query\_string":{"query":"dt:["20120608T000000+0200" TO "20120608T235959+0200"]"}}}'

when I try to delete the documents, this query fails

curl -XDELETE '[http://myserver:9200/webindex/result/\_query](http://myserver:9200/webindex/result/_query)' -d '{"query":{"query\_string":{"query":"dt:["20120608T000000+0200" TO "20120608T235959+0200"]"}}}'

response is  
{"ok":true,"\_indices":{"webindex":{"\_shards":{"total":5,"successful":0,"failed":5}}}}

elasticsearch.log says:

[2012-06-11 09:29:04,738][DEBUG][action.deletebyquery] [Blue Shield] [webindex][4], node[Ad-TT9ENRH-UaUB1DC2OHw], [P], s[STARTED]: Failed to execute [delete\_by\_query {[webindex][result], query [{"query":{"query\_string":{"query":"dt:["20120608T000000+0200" TO "20120608T235959+0200"]"}}}]}]  
org.elasticsearch.index.query.QueryParsingException: [webindex] No query registered for [query]  
at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:190)  
at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:243)  
at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:193)  
at org.elasticsearch.index.shard.service.InternalIndexShard.prepareDeleteByQuery(InternalIndexShard.java:363)  
at org.elasticsearch.action.deletebyquery.TransportShardDeleteByQueryAction.shardOperationOnPrimary(TransportShardDeleteByQueryAction.java:95)  
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:532)  
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:430)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)  
at java.lang.Thread.run(Thread.java:679)

Are we restricted to simple term queries when using Delete By Query API? Or am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [June 12, 2012, 9:32am UTC](https://discuss.elastic.co/t/delete-by-datetime-range-query/8040/2 "2012-06-12T09:32:17Z")

</div>

> when I try to delete the documents, this query fails
> 
> curl -XDELETE '[http://myserver:9200/webindex/result/\_query](http://myserver:9200/webindex/result/_query)' -d  
> '{"query":{"query\_string":{"query":"dt:["20120608T000000+0200" TO  
> "20120608T235959+0200"]"}}}'

delete-by-query doesn't take the top-level 'query' param. So just pass  
it the query\_string part

clint

---

<div class="post-metadata">

**Author:** ![dkoum](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dkoum](https://discuss.elastic.co/u/dkoum)\
**Post date:** [June 12, 2012, 9:52am UTC](https://discuss.elastic.co/t/delete-by-datetime-range-query/8040/3 "2012-06-12T09:52:30Z")

</div>

thx Clint, it's good to know.  
In the meantime, I overcame the problem using "range" query.

Dionysis

On Tue, Jun 12, 2012 at 12:32 PM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> > when I try to delete the documents, this query fails
> > 
> > curl -XDELETE '[http://myserver:9200/webindex/result/\_query](http://myserver:9200/webindex/result/_query)' -d  
> > '{"query":{"query\_string":{"query":"dt:["20120608T000000+0200" TO  
> > "20120608T235959+0200"]"}}}'
> 
> delete-by-query doesn't take the top-level 'query' param. So just pass  
> it the query\_string part
> 
> clint

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:24am UTC](https://discuss.elastic.co/t/delete-by-datetime-range-query/8040/4 "2017-07-06T03:24:50Z")

</div>


