9

What would be the equivalent operation in elasticsearchfor doing:

TRUNCATE mytable

The index that I want to truncate is called 'myindex'. In other words, after the operation, I want to have zero documents in the index 'myindex'.

2 Answers 2

9

You would need to delete the index and then recreate it. While this will require you to setup your mapping again.

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

There are other options such as deleting by query, but this will mark records as deleted in the lucene index and, while merged out over time, will not free up space.

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

Comments

-4

It seems that the easiest way to do this would be to delete the actual index and re-create it afterwards. For example:

def clear_index(self, index=None):
    '''
    This will remove all objects from the index
    by deleting the index and re-creating it.
    '''
    index = index or self.index
    self.delete_index(index=index) # self.es.indices.delete(index)
    self.create_index(index=index) # self.es.indices.create(index=index, body=body)

Comments

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.