es踩坑之deleteByQuery
背景由于es增删改操作有延迟,所以在某些业务场景如:先删除,在新增这种db下的场景就不适用于es了(es删除后在新增),毕竟db会有事务保证,所以在es层面只适合用deleteByQuery
代码场景通过canal订阅mysql的数据变动,投递到mq中,mq消费同步至es中,es做deleteByQuery的代码如下
1234567DeleteByQueryRequest request = new DeleteByQueryRequest("你的index");request.types("_doc");BoolQueryBuilder builder = QueryBuilders.boolQuery();builder.filter(QueryBuilders.termQuery("promotionId", promotionId)); // 条件一builder.filter(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("sh ...