I'm attempting perform a bulk delete of documents whose id's are derived from a previous search. The query to determine the documents that are candidates for deletion is producing desired results (thousands of records) however the bulk delete only deletes 10 records at a time, even though I'm feeding it all of the results of the original query;
Client client = node.client();
BulkRequestBuilder bulkRequest = client.prepareBulk();
SearchResponse deletes = client.prepareSearch("my_index")
.setTypes("my_doc_type")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(boolQuery().mustNot(termQuery("tId", transactionId)))
.execute()
.actionGet();
long deleteHits = deletes.getHits().getTotalHits();
if (deleteHits > 0) {
logger.info("Preparing to delete (" + deleteHits + ") " +
"documents from index");
Arrays.asList(deletes.getHits().getHits()).stream().forEach(h ->
bulkRequest.add(client.prepareDelete()
.setIndex("my_index")
.setType("my_doc_type")
.setId(h.getId())));
}
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
throw new RuntimeException(bulkResponse.buildFailureMessage());
}
}