How to convert KQL to curl command in bash

How can I run this KQL in the bash command

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

Thank you in advance!

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.

1 Like

How about in a shell script?

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

1 Like

Hello, this works for me.

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!

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