elasticsearch笔记(6) 删除文档delete-by-query

根据term, match等查询方式去删除大量的文档.

ps:如果是大量的删除,不推荐这个方式,太耗时了,因为是根据查询的id一个一个删除,而查询本身也很消耗性能,推荐新建一个index,把保留的部分保留到新的index

elasticsearch笔记(6) 删除文档delete-by-query

 

 在java中用索引删除

 

 1     @Test
 2     public void deletByQueryTest() throws IOException {
 3         //创建DeleteByQueryRequest对象
 4     String index = "sms-logs-index";
 5     String type = "sms-logs-type";
 6     DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(index);
 7     deleteByQueryRequest.types(type);
 8    //指定删除条件
 9     RangeQueryBuilder fee = QueryBuilders.rangeQuery("fee").lt(20).gt(10);
10     deleteByQueryRequest.setQuery(fee);
11    //创建查询对象
12     HttpHost httpHost = new HttpHost("192.168.43.30", 9200);
13     RestClientBuilder restClientBuilder = RestClient.builder(httpHost);
14     RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
15     //执行删除
16     BulkByScrollResponse bulkByScrollResponse = restHighLevelClient.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT);
17     System.out.println(bulkByScrollResponse);
18 
19 }

 

上一篇:AUTOSAR-MemIf模块


下一篇:普通用户的EIP1559