[英]Delete entire index in ElasticSearch
I'm approaching ElastichSearch with a Java client.我正在使用 Java 客户端接近 ElastichSearch。 I'm trying to delete an entire index.
我正在尝试删除整个索引。 I'm able to delete a single document with the following code:
我可以使用以下代码删除单个文档:
DeleteResponse response = client.prepareDelete("twitter", "tweet", "1").get();
I would like to delete all documents for a given index in a single instruction.我想在一条指令中删除给定索引的所有文档。 Note that I'm using the version 2.2.
请注意,我使用的是 2.2 版。
Thanks谢谢
EDIT: I've found a similar question but it refers to an old API version.编辑:我发现了一个类似的问题,但它指的是旧的 API 版本。 I'm currently working with version 2.2.
我目前正在使用 2.2 版。
The easiest way would be to delete your index, then recreate it. 最简单的方法是删除索引,然后重新创建它。
DeleteIndexResponse deleteResponse = client.admin().indices().delete(new DeleteIndexRequest("your-index")).actionGet()
then 然后
client.admin().indices().prepareCreate("your-index").get();
This will work with the 2.2 api 这将与2.2 API一起使用
Same solution as in maximede's answer but using newer version of RestHighLevelClient
(non depreciated):与 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);
Please make sure to import from the right package:请确保从正确的包中导入:
org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest
org.elasticsearch.client.indices.CreateIndexRequest;
Works fine with micronaut framework io.micronaut.elasticsearch:micronaut-elasticsearch:4.0.0
适用于 micronaut 框架
io.micronaut.elasticsearch:micronaut-elasticsearch:4.0.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.