Elasticsearch6+ Java API之DeleteByQUery操作

Elaticsearch分类传送门

  1. Elasticsearch6+ Java API之连接Client操作
  2. Elasticsearch6+ Java API之Upsert操作

最近刚做了flink更新/删除Elasticsearch数据的项目,这里做个笔记给大家借鉴下,避免大家踩坑。

transport client:

DeleteByQueryAction.INSTANCE.newRequestBuilder(client)
      .filter(QueryBuilders.boolQuery().must(termQuery1).must(termQuery2))
      .source("bigdata_flink_main_query")
      //es的监听器 -> 回调函数
      .execute(new ActionListener[BulkByScrollResponse]() {
        override def onResponse(response: BulkByScrollResponse): Unit = {
          response.getDeleted
        }

        override def onFailure(e: Exception): Unit = {
          logger.info("========> es delete by query failed!!")
        }
      })

rest-high-level-client:

 client.deleteByQueryAsync(deleteByQueryRequest,RequestOptions.DEFAULT,new ActionListener[BulkByScrollResponse] {
            override def onResponse(response: BulkByScrollResponse): Unit = {
              response.getDeleted
            }
            override def onFailure(e: Exception): Unit = {
              logger.info(s" es delete by query failed: sysNo:$sysNo | sosyNo:$sosysNo")
            }
          })
        }

点滴积累,写作不易,如果有用就点个关注吧
您的点赞关注,是我长期写作的动力!!

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页