I'm trying to migrate elasticsearch:5.6.15
to elasticsearch:7.17.18
. I have the following issues:
TransportClient client;
DeleteByQueryRequestBuilder deleteRequestBuilder = DeleteByQueryAction.INSTANCE.newRequestBuilder(client);
deleteRequestBuilder.source().setIndices(index);
Error:
Cannot resolve method 'newRequestBuilder' in 'DeleteByQueryAction'
Second issues is:
Retry retryRequest = Retry.on(Exception.class)
Error:
Cannot resolve method 'on' in 'Retry'
Third issue:
Map<String, Object> indexMapping;
CreateIndexRequest request = new CreateIndexRequest(index);
request.source(indexMapping);
Required type: XContentBuilder
Provided:Map<java.lang.String,java.lang.Object>
Do you know how I can migrate the code accordingly?
P.S I created this test project to show migration issues:
Please clone it and run it.
Elasticsearch has already deprecated Java REST Client
in favor of Java API Client. So you should migrate to Java API Client.
For your code, you can use the following code update for the issues.
newRequestBuilder
DeleteByQueryRequestBuilder delete = new DeleteByQueryRequestBuilder(client, DeleteByQueryAction.INSTANCE);
Retry.on
BackoffPolicy backoff = BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(firstRetryWaitTimeInMillis), noOfRetries);
Retry retryBulkRequest = new Retry(backoff, client.threadPool());
BulkResponse response = retryBulkRequest.withBackoff(
(bulkReq, bulkResponseActionListener) -> client.bulk(bulkReq, bulkResponseActionListener),
bulkRequest.request()).actionGet();
BulkResponseDto responseDto = new BulkResponseDto();
responseDto.setTimeTakenInMilli(response.getIngestTookInMillis());
DeprecationHandler
as the second argument.request.source(indexMapping, DeprecationHandler.IGNORE_DEPRECATIONS);
The above changes will solve the compilation issues. You can look for a migration guide or Elasticsearch Github for changes in different versions.