cluis92
cluis92

Reputation: 932

Attempting to delete all the data for an Index in Elasticsearch

I am trying to delete all the documents, i.e. data from an index. I am using v6.6 along with the dev tools in Kibana.

In the past, I have done this operation successfully but now it is saying 'not found'

{
  "_index" : "new-index",
  "_type" : "doc",
  "_id" : "_query",
  "_version" : 1,
  "result" : "not_found",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 313,
  "_primary_term" : 7
}

Here is my kibana statement

DELETE /new-index/doc/_query
   {
      "query": {
        "match_all": {}
      }
    }

Also, the index GET operation which verified the index has data and exists:

GET new-index/doc/_search

I verified the type is doc but I can post the whole mapping, if needed.

Upvotes: 4

Views: 13243

Answers (5)

Gene
Gene

Reputation: 11267

My guess is that someone changed a field's name and now the DB (NoSQL) and Elasticsearch string name for that field doesn't match. So Elasticsearch tried to delete that field, but the field was "not found".

It's not an error I would lose sleep over.

Upvotes: 0

Atur
Atur

Reputation: 1770

Only solutions currently are to either delete the index itself (faster), or delete-by-query (slower)

https://www.elastic.co/guide/en/elasticsearch/reference/7.4/docs-delete-by-query.html

POST new-index/_delete_by_query?conflicts=proceed
{
  "query": {
    "match_all": {}
  }
}

Delete API only removes a single document https://www.elastic.co/guide/en/elasticsearch/reference/7.4/docs-delete.html

Upvotes: 2

Kamil Witkowski
Kamil Witkowski

Reputation: 2083

Easier way is to navigate in Kibana to Management->Elasticsearch index mapping then select indexes you would like to delete via checkboxes, and click on Manage index -> delete index or flush index depending on your need.

enter image description here

Upvotes: 3

ozlevka
ozlevka

Reputation: 2146

Delete documents is a problematic way to clear data.

Preferable delete index:

DELETE [your-index]

From kibana console.

And recreate from scratch.

And more preferable way is to make a template for an index that creates index as well with the first indexed document.

Upvotes: 0

cluis92
cluis92

Reputation: 932

I was able to resolve the issue by using a delete by query:

POST new-index/_delete_by_query
{
  "query": {
    "match_all": {}
  }
}

Upvotes: 3

Related Questions