# Delete by query with dynamic values

**URL:** <https://discuss.elastic.co/t/delete-by-query-with-dynamic-values/6345>\
**Category:** Elasticsearch\
**Created:** [January 11, 2012, 12:29pm UTC](https://discuss.elastic.co/t/delete-by-query-with-dynamic-values/6345 "2012-01-11T12:29:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [January 11, 2012, 12:29pm UTC](https://discuss.elastic.co/t/delete-by-query-with-dynamic-values/6345/1 "2012-01-11T12:29:28Z")

</div>

Hi all,

And wondering if I could do something like:

curl -XDELETE '[http://localhost:9200/my\_index/my\_type/\_query](http://localhost:9200/my_index/my_type/_query)?  
q=creationDate:[\* TO now-interval]'

in which "now" should dynamically represent the timestamp of query  
execution and "interval" a date like "1d".

With this, I want to implement a process that executes a delete by  
query of all documents in which creationDate is 1 day older than the-  
moment-of-query-execution (kinda aging).

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [January 11, 2012, 12:53pm UTC](https://discuss.elastic.co/t/delete-by-query-with-dynamic-values/6345/2 "2012-01-11T12:53:57Z")

</div>

Have a look at TimeToLive:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

I think date math like in Solr is not supported directly in ES. Only  
via scripting:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Peter.

On 11 Jan., 13:29, vannya [vann...@gmail.com](mailto:vann...@gmail.com) wrote:

> Hi all,
> 
> And wondering if I could do something like:
> 
> curl -XDELETE '[http://localhost:9200/my\_index/my\_type/\_query](http://localhost:9200/my_index/my_type/_query)?  
> q=creationDate:[\* TO now-interval]'
> 
> in which "now" should dynamically represent the timestamp of query  
> execution and "interval" a date like "1d".
> 
> With this, I want to implement a process that executes a delete by  
> query of all documents in which creationDate is 1 day older than the-  
> moment-of-query-execution (kinda aging).
> 
> Thanks in advance!

---

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [January 11, 2012, 2:34pm UTC](https://discuss.elastic.co/t/delete-by-query-with-dynamic-values/6345/3 "2012-01-11T14:34:21Z")

</div>

Hi Karussel, thanks for your reply!

Yes, I already knew ttl, but is not exactly what I'm looking (I need  
to set the interval as an regular expression, and be able to change  
ttl at any time and see the change reflected in all indexed  
documents)...

Thanks!

On Jan 11, 12:53 pm, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:

> Have a look at TimeToLive:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/ttl-field.html)
> 
> I think date math like in Solr is not supported directly in ES. Only  
> via scripting:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/modules/scripting.html)
> 
> Peter.
> 
> On 11 Jan., 13:29, vannya [vann...@gmail.com](mailto:vann...@gmail.com) wrote:
> 
> > Hi all,
> 
> > And wondering if I could do something like:
> 
> > curl -XDELETE '[http://localhost:9200/my\_index/my\_type/\_query](http://localhost:9200/my_index/my_type/_query)?  
> > q=creationDate:[\* TO now-interval]'
> 
> > in which "now" should dynamically represent the timestamp of query  
> > execution and "interval" a date like "1d".
> 
> > With this, I want to implement a process that executes a delete by  
> > query of all documents in which creationDate is 1 day older than the-  
> > moment-of-query-execution (kinda aging).
> 
> > Thanks in advance!

---

<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:43am UTC](https://discuss.elastic.co/t/delete-by-query-with-dynamic-values/6345/4 "2017-07-06T03:43:08Z")

</div>


