Search code examples
javaelasticsearchspring-dataspring-data-elasticsearch

How to delete index using Spring Data Elasticsearch?


I am trying to delete indices in Elasticseach instance by code instead of native query. So I want to do this request:

DELETE /index-name

  public void deleteFoo(){
    DeleteRequest deleteRequest = new DeleteRequest("Foo");
    Request delete = RequestConverters.delete(deleteRequest);
    elasticsearchTemplate.delete(delete);
  }

But I get exception org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: 'org.elasticsearch.core.TimeValue org.elasticsearch.action.delete.DeleteRequest.timeout()'

What I am doing wrong?

I try to delete it by name, but would be nice to be able to delete all indices by one query.


Solution

  • Since Spring Data Elasticsearch 4.0 this is possible with

    elasticsearchTemplate.indexOps(IndexCoordinates.of("indexname")).delete();