# Parsing variable to Curl delete command

**URL:** <https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397>\
**Category:** Elasticsearch\
**Created:** [July 13, 2016, 10:34am UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397 "2016-07-13T10:34:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)\
**Post date:** [July 13, 2016, 10:34am UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/1 "2016-07-13T10:34:00Z")

</div>

HI Team,  
Actually im work in autopurge script in linux. I dont have enough storage in my disk. i planned to purge the old data from my index and keep last 15 day live records in index.. I can perform this operation by manually like passing this code as shown below,

curl -XDELETE '[http://XXX/logstash-dd.notifychange\_log\_v1/\_query](http://XXX/logstash-dd.notifychange_log_v1/_query)' -d '  
{  
"query":  
{  
"range":  
{  
"eventType\_timestamp":  
{  
"gte": "2016-05-30T07:00:00.000Z",  
"lte": "2016-06-15T06:59:59.999Z"  
}  
}  
}  
}'

In automation im trying to pass the from and to date automatically by script . I stored the from and to date value in variable and then passing the variable to curl command as shown below,  
from\_dataset\_date=2016-05-30T07:00:00.000Z  
to\_dataset\_date=2016-06-15T06:59:59.999Z  
curl -XDELETE '[http://XXXX/logstash-dd.notifychange\_log\_v1/\_query](http://XXXX/logstash-dd.notifychange_log_v1/_query)' -d '  
{  
"query":  
{  
"range":  
{  
"eventType\_timestamp":  
{   
"gte": "$from\_dataset\_date",  
"lte": "$to\_dataset\_date"

```
  }
}

```

}  
}'

In this scenario im getting error.  
error :{"error":{"root\_cause":[{"type":"parse\_exception","reason":"failed to parse date field [$from\_dataset\_date] with format [strict\_date\_optional\_time||epoch\_millis]"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"logstash-dd.notifychange\_log\_v1","node":"ze7WyKOcRRu0e5iAgA0ueQ","reason":{"type":"parse\_exception","reason":"failed to parse date field [$from\_dataset\_date] with format [strict\_date\_optional\_time||epoch\_millis]","caused\_by":{"type":"illegal\_argument\_exception","reason":"Invalid format: "$from\_dataset\_date""}}}]},"status":400}

Please anyone help me to resolve is it possible to pass variable in curl command as i shown above?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 13, 2016, 10:41am UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/2 "2016-07-13T10:41:30Z")

</div>

Variable references aren't expanded inside single quotes. They will be expanded inside _double_ quotes, but then you need to make sure to escape the double quotes in the JSON string.

Deleting data like this is a bad idea. You should use time-series indexes instead and use Curator to drop indexes older than a certain age.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 13, 2016, 10:44am UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/3 "2016-07-13T10:44:14Z")

</div>

> [@magnusbaeck](#):
>
> Deleting data like this is a bad idea. You should use time-series indexes instead and use Curator to drop indexes older than a certain age.

This X 100000000000000.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [July 13, 2016, 10:48am UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/4 "2016-07-13T10:48:42Z")

</div>

You are much better off inserting documents into an index named with the  
current date and deleting the index when you don't need it any more. You  
can use an alias to query them all. That way the delete frees up space.

---

<div class="post-metadata">

**Author:** ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)\
**Post date:** [July 13, 2016, 10:52am UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/5 "2016-07-13T10:52:49Z")

</div>

Hi Magnusbaeck/warkolm,  
In kibana while creating index with time-series its show time series will be deprecated . so that only we just go up with this method.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 13, 2016, 1:41pm UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/6 "2016-07-13T13:41:53Z")

</div>

No, the concept of time-series indexes will not be deprecated. What's deprecated is Kibana's use of date patterns in the index names, i.e. "prefix-\*" works just as well as an index pattern as "[prefix-]YYYY.MM.DD".

---

<div class="post-metadata">

**Author:** ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)\
**Post date:** [July 14, 2016, 6:41am UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/7 "2016-07-14T06:41:58Z")

</div>

Thank you so much for your reply magnus 🙂

---

<div class="post-metadata">

**Author:** ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)\
**Post date:** [July 14, 2016, 6:43am UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/8 "2016-07-14T06:43:50Z")

</div>

I will go up with your point before that i want to know is it possible to pass the value stored variable in curl query as i mentioned above code? Can you explain that to me.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 14, 2016, 6:47am UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/9 "2016-07-14T06:47:24Z")

</div>

Did you read my previous response? Note that this is a general Unix shell quoting problem, unrelated to Elasticsearch.

---

<div class="post-metadata">

**Author:** ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)\
**Post date:** [July 14, 2016, 6:48am UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/10 "2016-07-14T06:48:01Z")

</div>

Ok got it.. Thank you for your response.

---

<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 5, 2017, 10:35pm UTC](https://discuss.elastic.co/t/parsing-variable-to-curl-delete-command/55397/11 "2017-07-05T22:35:51Z")

</div>


