Upgrade elasticsearch-rest-client to 6.4.0

In this version several variants of the RestClient's performRequest
method are deprecated [1].

Adjust the implementation to use the recommended variant instead.

[1] https://www.elastic.co/guide/en/elasticsearch/reference/6.x/breaking_64_rest_client_changes.html

Change-Id: Ib09ab0a0800ed6957060c6e04352605ac5424062
This commit is contained in:
David Pursehouse
2018-09-04 08:56:26 +09:00
parent 0753f99d13
commit f624784344
4 changed files with 16 additions and 12 deletions

View File

@@ -874,8 +874,8 @@ maven_jar(
maven_jar(
name = "elasticsearch-rest-client",
artifact = "org.elasticsearch.client:elasticsearch-rest-client:6.3.2",
sha1 = "2077ea5f00fdd2d6af85223b730ba8047303297f",
artifact = "org.elasticsearch.client:elasticsearch-rest-client:6.4.0",
sha1 = "0eaa13decb9796eb671c5841d0770ae68b348da5",
)
JACKSON_VERSION = "2.6.6"

View File

@@ -48,6 +48,7 @@ import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.entity.NStringEntity;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
@@ -146,10 +147,10 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
public void deleteAll() throws IOException {
// Delete the index, if it exists.
String endpoint = indexName + client.adapter().indicesExistParam();
Response response = client.get().performRequest("HEAD", endpoint);
Response response = client.get().performRequest(new Request("HEAD", endpoint));
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
response = client.get().performRequest("DELETE", indexName);
response = client.get().performRequest(new Request("DELETE", indexName));
statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
throw new IOException(
@@ -238,8 +239,12 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
private Response performRequest(
String method, Object payload, String uri, Map<String, String> params) throws IOException {
Request request = new Request(method, uri);
String payloadStr = payload instanceof String ? (String) payload : payload.toString();
HttpEntity entity = new NStringEntity(payloadStr, ContentType.APPLICATION_JSON);
return client.get().performRequest(method, uri, params, entity);
request.setEntity(new NStringEntity(payloadStr, ContentType.APPLICATION_JSON));
for (Map.Entry<String, String> entry : params.entrySet()) {
request.addParameter(entry.getKey(), entry.getValue());
}
return client.get().performRequest(request);
}
}

View File

@@ -23,7 +23,7 @@ import java.io.IOException;
import java.util.List;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpGet;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,10 +41,8 @@ class ElasticIndexVersionDiscovery {
List<String> discover(String prefix, String indexName) throws IOException {
String name = prefix + indexName + "_";
Response response =
client
.get()
.performRequest(HttpGet.METHOD_NAME, client.adapter().getVersionDiscoveryUrl(name));
Request request = new Request("GET", client.adapter().getVersionDiscoveryUrl(name));
Response response = client.get().performRequest(request);
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() != HttpStatus.SC_OK) {

View File

@@ -28,6 +28,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
@@ -106,7 +107,7 @@ class ElasticRestClientProvider implements Provider<RestClient>, LifecycleListen
private ElasticVersion getVersion() throws ElasticException {
try {
Response response = client.performRequest("GET", "");
Response response = client.performRequest(new Request("GET", ""));
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
throw new FailedToGetVersion(statusLine);