[英]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.