special3220
special3220

Reputation: 103

ElasticSearch Date Range for future date

I am trying to create a query that will give me accounts that was created before a certain future date. I would like delete those account that were created 30 days before that future date. I am not sure how to write that range. Currently I have a query that gives me account that was created 30 days before today.

            range: {
                updatedAt: {
                  lte: "now-2592000/s",
                },
              },

Some guidance will be highly appreciated.

Upvotes: 0

Views: 273

Answers (1)

jaspreet chahal
jaspreet chahal

Reputation: 9099

You can use _delete_by_query

POST <index-name>/_delete_by_query
{
  "query": {
    "range": {
      "createdAt": {
        "lte": "2022-10-31||-30d" --> any future date
      }
    }
  }
}

Pass any date with "||" at end.

My createdAt field is indexed using type "date"

Upvotes: 2

Related Questions