# How to curl this query to shell script

**URL:** <https://discuss.elastic.co/t/how-to-curl-this-query-to-shell-script/299292>\
**Category:** Kibana\
**Created:** [March 10, 2022, 5:04am UTC](https://discuss.elastic.co/t/how-to-curl-this-query-to-shell-script/299292 "2022-03-10T05:04:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![leyleynewt](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@leyleynewt](https://discuss.elastic.co/u/leyleynewt)\
**Post date:** [March 10, 2022, 5:04am UTC](https://discuss.elastic.co/t/how-to-curl-this-query-to-shell-script/299292/1 "2022-03-10T05:04:49Z")

</div>

I want to delete the 5 days old data of all my indexes. How to curl this query to shell script

```auto
POST _all/_delete_by_query
{
 "query": {
   "range": {
     "@timestamp": {
       "lte": "now-5d"
      }
    }
  }
}

```

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)\
**Post date:** [March 10, 2022, 7:47am UTC](https://discuss.elastic.co/t/how-to-curl-this-query-to-shell-script/299292/2 "2022-03-10T07:47:59Z")

</div>

> [@leyleynewt](#):
>
> ```auto
> POST _all/_delete_by_query
> {
> "query": {
> "range": {
> "@timestamp": {
> "lte": "now-5d"
> }
> }
> }
> }
> 
> ```

Hi  
Have a look into Kibana's Console

 ![Bildschirmfoto 2022-03-10 um 08.45.20](https://us1.discourse-cdn.com/elastic/original/3X/5/1/518955dc0daad358ddb21e7f2dd3b53aeb657dd6.png)

```auto
curl -XPOST "{Elasticsearch}/_all/_delete_by_query" -H 'Content-Type: application/json' -d'
{
 "query": {
   "range": {
     "@timestamp": {
       "lte": "now-5d"
      }
    }
  }
}'

```

Best,  
Matthias

---

<div class="post-metadata">

**Author:** ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)\
**Post date:** [March 10, 2022, 2:00pm UTC](https://discuss.elastic.co/t/how-to-curl-this-query-to-shell-script/299292/4 "2022-03-10T14:00:39Z")

</div>

You're welcome!

---

<div class="post-metadata">

**Author:** ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)\
**Post date:** [March 10, 2022, 2:01pm UTC](https://discuss.elastic.co/t/how-to-curl-this-query-to-shell-script/299292/5 "2022-03-10T14:01:35Z")

</div>

Hope these aren't your real credentials 🙂

---

<div class="post-metadata">

**Author:** ![leyleynewt](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@leyleynewt](https://discuss.elastic.co/u/leyleynewt)\
**Post date:** [March 14, 2022, 2:30am UTC](https://discuss.elastic.co/t/how-to-curl-this-query-to-shell-script/299292/6 "2022-03-14T02:30:03Z")

</div>

Good day, the updated solution that works for me.

```auto
curl -XPOST "YourLocalhost:9200/YourIndexName/_delete_by_query" -H 'Content-Type: application/json' -d' { "query": { "range": { "@timestamp": { "lte": "now-5d" } } } }' -u YourElasticUsername:AndPassword

```

I added my Elastic Username and Password to the last of the command.  
Thank you!

---

<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:** [April 11, 2022, 2:30am UTC](https://discuss.elastic.co/t/how-to-curl-this-query-to-shell-script/299292/7 "2022-04-11T02:30:30Z")

</div>

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