2

I have an index called event which has around 250 records. I want to delete this 250 records without deleting the full mapping.

DeleteIndex delete = new DeleteIndex.Builder("events").build();
client.execute(delete);

the above code deletes the full event index. How can to only delete the content?

2 Answers 2

2

Based on ElasticSearch documentation Delete By Query API, you can delete all documents within an index using a query as following :

POST twitter/tweet/_delete_by_query
{
  "query": {
    "match_all": {}
  }
}

With ElasticSearch Java API "Delete By Query API" documentation :

BulkByScrollResponse response =
    DeleteByQueryAction.INSTANCE.newRequestBuilder(client)
        .filter(QueryBuilders.matchQuery("gender", "male")) 
        .source("persons")                                  
        .get();                                             

long deleted = response.getDeleted(); 

Please note that this answer is suitable for ElasticSearch 6.1 but may differ for other versions of ElasticSearch.

I hope this will help you.

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

Comments

1

Since I am using spring data I was able to resolve this issue using deleteAll funtion.

eventRepo.deleteAll();

did the trick for me.

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.