elasticsearch 5.1 java api DeleteByQuery

354 views Asked by At

Elasticsearch version: 5.1.1

OS version: centos 7

Description of the problem including expected versus actual behavior: ES 5.1 version does not support delete-by-query plugin. so i need to change the javaAPI code.

The following code is from the previous 2.3 version.

    new DeleteByQueryRequestBuilder(ElasticConnector.getInstance().getJavaClient(), DeleteByQueryAction.INSTANCE) 
.setIndices(GLOBAL_ID) 
    .setTypes(MessageService.DEVICE) 
    .setQuery(QueryBuilders.boolQuery().should(QueryBuilders.termQuery("user_id", user_id)) 
    .should(QueryBuilders.termQuery("device_id", device_id) 
    .mustNot(QueryBuilders.boolQuery()
    .must(QueryBuilders.termQuery("user_id", user_id)) 
    .must(QueryBuilders.termQuery("device_id", device_id)) ))
    .execute().actionGet();

This code has a problem with

DeleteByQueryRequestBuilder cannot be resolved to a type

How do I change?

1

There are 1 answers

0
Alain Gauthey On

I think this can solve your problem

BulkIndexByScrollResponse response =
  DeleteByQueryAction.INSTANCE
    .newRequestBuilder(ESClient)
    .filter(yourQuery)
    .source(your index)
    .get();

regards