0

Here is a custom api to delete an index using a transport client and the import statement using admin and it is working fine.

I am writing the same using Java High Level Rest Client, but not able to find the appropriate import statement there. According to what I have read admin not to be used for Java High Level Rest Client as it seems to be deprecated.

import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;

public IndexResponse deleteIndex(String index){
     DeleteIndexResponse response = client.admin().indices().prepareDelete(index).get();
}

There are new imports which should be used when working with High Level Rest Client. I am able to create index with this but can't find the same import for Delete Request or Response.

import org.elasticsearch.client.indices.CreateIndexRequest;
public IndexResponse createIndexWithCustomMappings(String indexName, String fieldsMapping){
   CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);}

import org.elasticsearch.client.indices.CreateIndexRequest is the one that is recommended.

I have gone through this documentation https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-delete-index.html# , but couldn't find anything related to this.

Is this not available with High Level Rest Client. These two imports seem to be confusing. Does someone know what is concrete difference between both these?

Aditya
  • 950
  • 8
  • 37

1 Answers1

0

Have a look at the index lifecycle javadoc. You can probably use DeleteAction.

Octavian Theodor
  • 537
  • 6
  • 14
  • These two imports seem to be confusing. Do you know what is concrete difference between both these? – Aditya Sep 24 '21 at 09:53
  • Not clear to me as I haven't tried that API yet. However, if you search the Elasticsearch GitHub repo, 7.15 branch at https://github.com/elastic/elasticsearch/tree/7.15, you can find `DeleteIndexRequest` under the server/src/main/java/org/elasticsearch/action/admin/indices/delete/ directory (hence, the package), which I assume it's the actual *server* implementation. The `DeleteAction.java` file is located under /client/rest-high-level, and I assume you're using the client to interact with the server. – Octavian Theodor Sep 24 '21 at 10:22