# Delete by Query - Based on time

**URL:** <https://discuss.elastic.co/t/delete-by-query-based-on-time/117456>\
**Category:** Kibana\
**Created:** [January 29, 2018, 12:36pm UTC](https://discuss.elastic.co/t/delete-by-query-based-on-time/117456 "2018-01-29T12:36:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ganeshmuralidhar](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@ganeshmuralidhar](https://discuss.elastic.co/u/ganeshmuralidhar)\
**Post date:** [January 29, 2018, 12:36pm UTC](https://discuss.elastic.co/t/delete-by-query-based-on-time/117456/1 "2018-01-29T12:36:08Z")

</div>

Hello,

I am trying to delete data from Elastic Search based on timestamp. I could not find a way to do it after giving multiple tries with the below:

POST index\_name/\_delete\_by\_query  
_{_  
_"query": {_  
_"range" : {_  
_"@timestamp" : {_  
_"gte" : "01/01/2016",_  
_"lte" : "05/01/2017",_  
_"format": "dd/MM/yyyy||yyyy"_  
_}_  
_}_  
_}_  
_}_

Just want to understand what am I missing here? 🤔🤔

---

<div class="post-metadata">

**Author:** ![krsna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krsna/32/30919_2.png) [@krsna](https://discuss.elastic.co/u/krsna)\
**Post date:** [January 29, 2018, 2:54pm UTC](https://discuss.elastic.co/t/delete-by-query-based-on-time/117456/2 "2018-01-29T14:54:39Z")

</div>

Hi Ganesh,

The query seems to be correct. What is the response that you are getting?  
Also, can you try the below query

GET index\_name/\_search  
{  
"query": {  
"range" : {  
"@timestamp" : {  
"gte" : "01/01/2016",  
"lte" : "05/01/2017",  
"format": "dd/MM/yyyy||yyyy"  
}  
}  
}  
}

and see if you can retrieve any results?

---

<div class="post-metadata">

**Author:** ![ganeshmuralidhar](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@ganeshmuralidhar](https://discuss.elastic.co/u/ganeshmuralidhar)\
**Post date:** [January 30, 2018, 3:47am UTC](https://discuss.elastic.co/t/delete-by-query-based-on-time/117456/3 "2018-01-30T03:47:59Z")

</div>

Hi Krishna,

I get the below response

![image](https://us1.discourse-cdn.com/elastic/original/3X/6/9/69283d769c1fecda2f4b200cbc71dffb310f9bd9.png)

---

<div class="post-metadata">

**Author:** ![krsna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krsna/32/30919_2.png) [@krsna](https://discuss.elastic.co/u/krsna)\
**Post date:** [January 30, 2018, 8:00am UTC](https://discuss.elastic.co/t/delete-by-query-based-on-time/117456/4 "2018-01-30T08:00:20Z")

</div>

Hi Ganesh,

The output that you got explains it. There is no data in the given range of timestamp. hits -\> total = 0. As there is no data in the given timestamp range you were not able to delete.

---

<div class="post-metadata">

**Author:** ![ganeshmuralidhar](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@ganeshmuralidhar](https://discuss.elastic.co/u/ganeshmuralidhar)\
**Post date:** [January 30, 2018, 8:18am UTC](https://discuss.elastic.co/t/delete-by-query-based-on-time/117456/5 "2018-01-30T08:18:03Z")

</div>

Hi Krishna,

Yes, I understood that too. But was wondering why does this query not show me data when I actually have some data that I see on my graph for dates ranging between 1st Jan to 21st Jan.

Now, I am quite embarrassed to say this 😆😆🙄🙄 But the problem is with the query that I wrote which refers to year 2017, where as we are in 2018.

But your inputs helped me figure that out 🙂. Thanks a lot for your support.

---

<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:** [February 27, 2018, 8:18am UTC](https://discuss.elastic.co/t/delete-by-query-based-on-time/117456/6 "2018-02-27T08:18:31Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
