RestHighLevelClient批量删除满足某些条件的数据

2022-03-29 14:43:49 浏览数 (1)

这个可以通过DeleteByQueryRequest来实现,实例代码如下

代码语言:javascript复制
	/**
	 * 批量删除文档
	 * @throws IOException
	 */
	@Test
	public void deleteByQueryRequest() throws IOException {
		DeleteByQueryRequest request = new DeleteByQueryRequest("sub_bank1031");
		request.setDocTypes("sub_bank");
		request.setQuery(new TermQueryBuilder("unionNumber", "104663451012"));
		request.setSize(1);
		BulkByScrollResponse resp = highLevelClient.deleteByQuery(request, RequestOptions.DEFAULT);
		println(resp);
	}

pom文件es相关依赖如下:

代码语言:javascript复制
         <dependency>
             <groupId>org.elasticsearch</groupId>
             <artifactId>elasticsearch</artifactId>
             <version>6.8.0</version>
         </dependency>
         <!-- elasticsearch high level -->    
         <dependency>
             <groupId>org.elasticsearch.client</groupId>
             <artifactId>elasticsearch-rest-high-level-client</artifactId>
             <exclusions>
                 <exclusion>
                     <groupId>org.elasticsearch</groupId>
                     <artifactId>elasticsearch</artifactId>                
                 </exclusion>
             </exclusions>
             <version>6.8.0</version>
         </dependency>
es

0 人点赞