# How to convert KQL to curl command in bash

**URL:** <https://discuss.elastic.co/t/how-to-convert-kql-to-curl-command-in-bash/299207>\
**Category:** Kibana\
**Tags:** kql-kibana-query-language\
**Created:** [March 9, 2022, 12:03pm UTC](https://discuss.elastic.co/t/how-to-convert-kql-to-curl-command-in-bash/299207 "2022-03-09T12:03:14Z")\
**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 9, 2022, 12:03pm UTC](https://discuss.elastic.co/t/how-to-convert-kql-to-curl-command-in-bash/299207/1 "2022-03-09T12:03:14Z")

</div>

How can I run this KQL in the bash command

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

```

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![majagrubic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/majagrubic/32/74459_2.png) [@majagrubic](https://discuss.elastic.co/u/majagrubic)\
**Post date:** [March 9, 2022, 4:03pm UTC](https://discuss.elastic.co/t/how-to-convert-kql-to-curl-command-in-bash/299207/2 "2022-03-09T16:03:43Z")

</div>

```auto
curl --user name:password -X POST "localhost:9200/my-index-000001/_delete_by_query?conflicts=proceed&pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
   "range": {
     "@timestamp": {
       "lte": "now-5d"
      }
    }
  }
}

```

Replace with the appropriate authentication and your hostname.

---

<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, 2:57am UTC](https://discuss.elastic.co/t/how-to-convert-kql-to-curl-command-in-bash/299207/3 "2022-03-10T02:57:03Z")

</div>

How about in a shell script?

---

<div class="post-metadata">

**Author:** ![majagrubic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/majagrubic/32/74459_2.png) [@majagrubic](https://discuss.elastic.co/u/majagrubic)\
**Post date:** [March 10, 2022, 5:56am UTC](https://discuss.elastic.co/t/how-to-convert-kql-to-curl-command-in-bash/299207/4 "2022-03-10T05:56:51Z")

</div>

We don't provide official guidance for shell scripting, so this is something for you to play around with.

---

<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:26am UTC](https://discuss.elastic.co/t/how-to-convert-kql-to-curl-command-in-bash/299207/6 "2022-03-14T02:26:18Z")

</div>

Hello, this 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:26am UTC](https://discuss.elastic.co/t/how-to-convert-kql-to-curl-command-in-bash/299207/7 "2022-04-11T02:26:29Z")

</div>

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