简体   繁体   English

带有弹性 8.3.0 java api 客户端的 DeleteRequest 示例

[英]DeleteRequest example with elastic 8.3.0 java api client

I need examples for DeleteRequest with respect to ES 8.3.0 Java Api client.我需要关于 ES 8.3.0 Java Api 客户端的 DeleteRequest 示例。 I am looking for code reference where I want to delete one particular document by passing index name and the condition to delete the document.我正在寻找代码参考,我想通过传递索引名称和删除文档的条件来删除一个特定的文档。 I have found only Java High Level Rest Client (Deprecated in 7.15.0), and Transport Client (Deprecated in 7.0.0).我发现只有Java High Level Rest Client (7.15.0 中已弃用)和Transport Client (7.0.0 中已弃用)。

You can use below code for delete specific document using id :您可以使用以下代码使用id删除特定文档:

DeleteRequest request = DeleteRequest.of(d -> d.index("index_name").id("doc_id"));
DeleteResponse response = esClient.delete(request);

If you want to do DeleteByQuery then you can use below code (it will delete document where country is india):如果您想做 DeleteByQuery,那么您可以使用以下代码(它将删除国家/地区为印度的文档):

DeleteByQueryRequest dbyquery = DeleteByQueryRequest
                .of(fn -> fn.query(TermQuery.of(tq -> tq.field("country").value("india"))._toQuery()).index("index_name"));
        
DeleteByQueryResponse dqr = esClient.deleteByQuery(dbyquery);

There is no details document available for above.上面没有可用的详细文件。 You can see open github issue for same here你可以在这里看到同样的开放 github 问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM