0

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.

1
  • what format date? Could give example of document? Commented Oct 28, 2022 at 1:01

1 Answer 1

3

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"

Sign up to request clarification or add additional context in comments.

2 Comments

He do not want to delete account created in last 30 days. Instead he has some future date. And want to delete all account 30 days less than that future that.
@AmanMehta I have corrected the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.