0
votes

I am new to elasticsearch and I have an document in elasticsearch and document contain thosands of user views and now I want to delete those view that are older than 3Hours for this purpose I write following query in elasticsearch

POST {INDEX}/_delete_by_query
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "type": "box_views"
          }
        },
        {
          "query": {
            "range": {
              "@created_at": {
                "gte": "now-3h"
              }
            }
          }
        }
      ]
    }
  }
}

When I execute this query I receive following error

{ "error": { "root_cause": [ { "type": "parsing_exception", "reason": "no [query] registered for [query]", "line": 1, "col": 66 } ], "type": "parsing_exception", "reason": "no [query] registered for [query]", "line": 1, "col": 66 }, "status": 400 }

1

1 Answers

2
votes

Your query should look like this:

POST {INDEX}/_delete_by_query
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "type": "box_views"
          }
        },
        {
          "range": {
            "@created_at": {
              "gte": "now-3h"
            }
          }
        }
      ]
    }
  }
}

Besides, if you're looking for older documents, I think you should use lte instead of gte.