Delete

How the heck do I delete records form an index?
index: test_index

This is not working:

DELETE test_index/myType
{
  "query":{
    "match_all": {
      
    }
  }
}

Why not deleting the index in that case?

I find that I have to fool around with the previously made dashboards + visualizations.
Whenever I delete the whole index, those items become buggy, no data, errors, etc..

I tried to wait for the data to become available after re-indexing, but after a few minutes, I get impatient.

This works:

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

POST my_index/_delete_by_query
{
  "query":{
    "match_all": {}
  }
}

This is really not efficient.

DELETE index

Is much much much better.

Explain, please.

The delete by query will have to write new segments telling Lucene that docs X,Y,Z have been removed. Well, all docs basically.
Then at some point a merge segments operation will happen and those files will be removed.

Look at the disk space, then try the delete by query and just after, look at the disk space.

Removing an index will immediately remove all files "like a rm -r". No merge of segments. Space is immediately released.

Gotcha!

I decided to go with automating the workflow.

  1. Delete Index
  2. Reload Index with Mapping in an external file (easier than writing in code)
  3. Reload data

Definitely better. Note that you can use aliases so your users won't ever notice that you reindexed.

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