簡體   English   中英

在 ElasticSearch 中刪除整個索引

[英]Delete entire index in ElasticSearch

我正在使用 Java 客戶端接近 ElastichSearch。 我正在嘗試刪除整個索引。 我可以使用以下代碼刪除單個文檔:

DeleteResponse response = client.prepareDelete("twitter", "tweet", "1").get();

我想在一條指令中刪除給定索引的所有文檔。 請注意,我使用的是 2.2 版。

謝謝

編輯:我發現了一個類似的問題,但它指的是舊的 API 版本。 我目前正在使用 2.2 版。

最簡單的方法是刪除索引,然后重新創建它。

DeleteIndexResponse deleteResponse = client.admin().indices().delete(new DeleteIndexRequest("your-index")).actionGet()

然后

client.admin().indices().prepareCreate("your-index").get();

這將與2.2 API一起使用

與 maximede 的答案相同的解決方案,但使用較新版本的RestHighLevelClient (未折舊):

// delete current index
var deleteRequest = new DeleteIndexRequest("index-name");
client.indices().delete(deleteRequest, RequestOptions.DEFAULT);

// create new one
CreateIndexRequest request = new CreateIndexRequest("index-name");
client.indices().create(request, RequestOptions.DEFAULT);

請確保從正確的包中導入:

org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest
org.elasticsearch.client.indices.CreateIndexRequest;

適用於 micronaut 框架io.micronaut.elasticsearch:micronaut-elasticsearch:4.0.0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM