es 删除数据的三种方法
1 因为高版本的es并不支持批量删除,所以第一个方法思路,首先查询es 获取主键id,然后根据id逐个删除
def scrollScanDeleteByTopic(client:TransportClient,index:String,topic:String)= { var searchResponse = client.prepareSearch(index).setTypes("docs") .setQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("topicName",topic))) .setSearchType(SearchType.DEFAULT) .addStoredField("id") .setSize(1000).setScroll(TimeValue.timeValueMinutes(5)) .execute().actionGet() var num = searchResponse.getHits.getHits.length // 循环直到遍历所有数据 //loop.breakable{ while (num != 0) { println(" num " + num) val res = searchResponse.getHits.getHits res.foreach { x => val response = client.prepareDelete(index, "docs", x.getId).execute().actionGet() // println(response) } println(s"====================&