Skip to content

Commit 7987866

Browse files
authored
Revert "Enable HLRC compatibility mode by default (#86517)" (#86873)
This reverts commit 0cb5108.
1 parent 4276aad commit 7987866

File tree

9 files changed

+27
-102
lines changed

9 files changed

+27
-102
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,7 @@ protected RestHighLevelClient(
347347
.flatMap(Function.identity())
348348
.collect(toList())
349349
);
350-
351-
// Compatibility mode is on by default, then env variable has precedence over builder setting
352-
String apiVersioningEnv = System.getenv(API_VERSIONING_ENV_VARIABLE);
353-
if (useAPICompatibility == null && apiVersioningEnv == null) {
354-
this.useAPICompatibility = true;
355-
} else if (useAPICompatibility == null && "true".equals(System.getenv(API_VERSIONING_ENV_VARIABLE))) {
350+
if (useAPICompatibility == null && "true".equals(System.getenv(API_VERSIONING_ENV_VARIABLE))) {
356351
this.useAPICompatibility = true;
357352
} else {
358353
this.useAPICompatibility = Boolean.TRUE.equals(useAPICompatibility);

client/rest-high-level/src/test/java/org/elasticsearch/client/CustomRestHighLevelClientTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ private Void mockPerformRequestAsync(Request request, ResponseListener responseL
147147
* Mocks the synchronous request execution like if it was executed by Elasticsearch.
148148
*/
149149
private Response mockPerformRequest(Request request) throws IOException {
150-
// Headers contain 'node_name' set by optionsForNodeName and 'Accept' from HLRC compatibility mode
151-
assertThat(request.getOptions().getHeaders(), hasSize(2));
150+
assertThat(request.getOptions().getHeaders(), hasSize(1));
152151
Header httpHeader = request.getOptions().getHeaders().get(0);
153152
final Response mockResponse = mock(Response.class);
154153
when(mockResponse.getHost()).thenReturn(new HttpHost("localhost", 9200));

client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import org.elasticsearch.action.ActionListener;
3434
import org.elasticsearch.action.ActionRequest;
3535
import org.elasticsearch.action.ActionRequestValidationException;
36-
import org.elasticsearch.action.get.GetRequest;
37-
import org.elasticsearch.action.get.GetResponse;
3836
import org.elasticsearch.action.search.ClearScrollRequest;
3937
import org.elasticsearch.action.search.ClearScrollResponse;
4038
import org.elasticsearch.action.search.SearchResponse;
@@ -97,7 +95,6 @@
9795
import org.elasticsearch.common.util.set.Sets;
9896
import org.elasticsearch.core.CheckedFunction;
9997
import org.elasticsearch.core.Tuple;
100-
import org.elasticsearch.index.get.GetResult;
10198
import org.elasticsearch.index.rankeval.DiscountedCumulativeGain;
10299
import org.elasticsearch.index.rankeval.EvaluationMetric;
103100
import org.elasticsearch.index.rankeval.ExpectedReciprocalRank;
@@ -1504,30 +1501,6 @@ public void testModifyForCompatibility() {
15041501

15051502
}
15061503

1507-
public void testCompatibilityModeDefault() throws Exception {
1508-
mockResponse(new GetResponse(new GetResult("foo", "bar", "1", 1, 1, 1, true, null, null, null)));
1509-
restHighLevelClient.get(new GetRequest("foo", "bar"), RequestOptions.DEFAULT);
1510-
1511-
verify(restClient).performRequest(argThat(req -> {
1512-
List<Header> headers = req.getOptions().getHeaders();
1513-
Header accept = headers.stream().filter(h -> h.getName().equals("Accept")).findFirst().get();
1514-
return accept.getValue().equals("application/vnd.elasticsearch+json; compatible-with=7");
1515-
}));
1516-
}
1517-
1518-
public void testDisableCompatibilityMode() throws Exception {
1519-
RestHighLevelClient client = new RestHighLevelClientBuilder(restClient).setApiCompatibilityMode(false).build();
1520-
1521-
mockResponse(new GetResponse(new GetResult("foo", "bar", "1", 1, 1, 1, true, null, null, null)));
1522-
client.get(new GetRequest("foo", "bar"), RequestOptions.DEFAULT);
1523-
1524-
verify(restClient).performRequest(argThat(req -> {
1525-
List<Header> headers = req.getOptions().getHeaders();
1526-
Optional<Header> accept = headers.stream().filter(h -> h.getName().equals("Accept")).findFirst();
1527-
return accept.isPresent() == false;
1528-
}));
1529-
}
1530-
15311504
private static void assertSyncMethod(Method method, String apiName, List<String> booleanReturnMethods) {
15321505
// A few methods return a boolean rather than a response object
15331506
if (apiName.equals("ping") || apiName.contains("exist") || booleanReturnMethods.contains(apiName)) {

docs/changelog/86517.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/java-rest/high-level/getting-started.asciidoc

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ doesn't need to be in the same minor version as the Elasticsearch nodes it
1818
communicates with, as it is forward compatible meaning that it supports
1919
communicating with later versions of Elasticsearch than the one it was developed for.
2020

21-
The 7.0 client is able to communicate with any 7.x Elasticsearch node, while the 7.1
22-
client is for sure able to communicate with 7.1, 7.2 and any later 7.x version, but
21+
The 6.0 client is able to communicate with any 6.x Elasticsearch node, while the 6.1
22+
client is for sure able to communicate with 6.1, 6.2 and any later 6.x version, but
2323
there may be incompatibility issues when communicating with a previous Elasticsearch
24-
node version, for instance between 7.1 and 7.0, in case the 7.1 client supports new
25-
request body fields for some APIs that are not known by the 7.0 node(s).
24+
node version, for instance between 6.1 and 6.0, in case the 6.1 client supports new
25+
request body fields for some APIs that are not known by the 6.0 node(s).
2626

2727
It is recommended to upgrade the High Level Client when upgrading the Elasticsearch
2828
cluster to a new major version, as REST API breaking changes may cause unexpected
@@ -31,23 +31,6 @@ only be supported by the newer version of the client. The client should always b
3131
updated last, once all of the nodes in the cluster have been upgraded to the new
3232
major version.
3333

34-
*Compatibility with Elasticsearch 8.x*
35-
36-
The High Level Client version 7.16 and higher can communicate with Elasticsearch version 8.x after enabling API compatibility mode. When this mode enabled, the client will send HTTP headers that instruct Elasticsearch 8.x to honor 7.x request/responses.
37-
38-
Compatibility mode is enabled as follows:
39-
40-
["source","java",subs="attributes"]
41-
--------------------------------------------------
42-
RestHighLevelClient esClient = new RestHighLevelClientBuilder(restClient)
43-
.setApiCompatibilityMode(true)
44-
.build()
45-
--------------------------------------------------
46-
47-
When compatibility mode is enabled, the client can also communicate with Elasticsearch version 7.11 and higher.
48-
49-
NOTE: Starting with version 7.17.4, compatibility mode is enabled by default.
50-
5134
[[java-rest-high-javadoc]]
5235
=== Javadoc
5336

@@ -158,7 +141,7 @@ transitive dependencies:
158141
[[java-rest-high-getting-started-initialization]]
159142
=== Initialization
160143

161-
A `RestHighLevelClient` instance needs a
144+
A `RestHighLevelClient` instance needs a
162145
{java-api-client}/java-rest-low-usage-initialization.html[REST low-level client builder]
163146
to be built as follows:
164147

@@ -189,27 +172,27 @@ All APIs in the `RestHighLevelClient` accept a `RequestOptions` which you can
189172
use to customize the request in ways that won't change how Elasticsearch
190173
executes the request. For example, this is the place where you'd specify a
191174
`NodeSelector` to control which node receives the request. See the
192-
{java-api-client}/java-rest-low-usage-requests.html#java-rest-low-usage-request-options[low level client documentation]
175+
{java-api-client}/java-rest-low-usage-requests.html#java-rest-low-usage-request-options[low level client documentation]
193176
for more examples of customizing the options.
194177

195178
[[java-rest-high-getting-started-asynchronous-usage]]
196179
=== Asynchronous usage
197180

198-
All of the methods across the different clients exist in a traditional synchronous and
199-
asynchronous variant. The difference is that the asynchronous ones use asynchronous requests
181+
All of the methods across the different clients exist in a traditional synchronous and
182+
asynchronous variant. The difference is that the asynchronous ones use asynchronous requests
200183
in the REST Low Level Client. This is useful if you are doing multiple requests or are using e.g.
201184
rx java, Kotlin co-routines, or similar frameworks.
202185

203-
The asynchronous methods are recognizable by the fact that they have the word "Async" in their name
204-
and return a `Cancellable` instance. The asynchronous methods accept the same request object
205-
as the synchronous variant and accept a generic `ActionListener<T>` where `T` is the return
206-
type of the synchronous method.
186+
The asynchronous methods are recognizable by the fact that they have the word "Async" in their name
187+
and return a `Cancellable` instance. The asynchronous methods accept the same request object
188+
as the synchronous variant and accept a generic `ActionListener<T>` where `T` is the return
189+
type of the synchronous method.
207190

208-
All asynchronous methods return a `Cancellable` object with a `cancel` method that you may call
191+
All asynchronous methods return a `Cancellable` object with a `cancel` method that you may call
209192
in case you want to abort the request. Cancelling
210-
no longer needed requests is a good way to avoid putting unnecessary
193+
no longer needed requests is a good way to avoid putting unnecessary
211194
load on Elasticsearch.
212195

213-
Using the `Cancellable` instance is optional and you can safely ignore this if you have
214-
no need for this. A use case for this would be using this with e.g. Kotlin's `suspendCancellableCoRoutine`.
196+
Using the `Cancellable` instance is optional and you can safely ignore this if you have
197+
no need for this. A use case for this would be using this with e.g. Kotlin's `suspendCancellableCoRoutine`.
215198

docs/java-rest/high-level/index.asciidoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
deprecated[7.15.0, The High Level REST Client is deprecated in favour of the {java-api-client}/index.html[Java API Client].]
1010

11-
NOTE: The High Level Rest Client version 7.17 can work with {es} `8.x` with <<java-rest-high-compatibility,compatibility mode enabled>>.
12-
1311
The Java High Level REST Client works on top of the Java Low Level REST client.
1412
Its main goal is to expose API specific methods, that accept request objects as
1513
an argument and return response objects, so that request marshalling and

qa/ccs-old-version-remote-cluster/src/test/java/org/elasticsearch/upgrades/CCSFieldsOptionEmulationIT.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.elasticsearch.client.ResponseException;
4141
import org.elasticsearch.client.RestClient;
4242
import org.elasticsearch.client.RestHighLevelClient;
43-
import org.elasticsearch.client.RestHighLevelClientBuilder;
4443
import org.elasticsearch.client.indices.CreateIndexRequest;
4544
import org.elasticsearch.cluster.metadata.IndexMetadata;
4645
import org.elasticsearch.common.document.DocumentField;
@@ -90,13 +89,11 @@ static RestHighLevelClient newLocalClient(Logger logger) {
9089
final List<HttpHost> hosts = parseHosts("tests.rest.cluster");
9190
final int index = random().nextInt(hosts.size());
9291
logger.info("Using client node {}", index);
93-
return new RestHighLevelClientBuilder(RestClient.builder(hosts.get(index)).build()).setApiCompatibilityMode(false).build();
92+
return new RestHighLevelClient(RestClient.builder(hosts.get(index)));
9493
}
9594

9695
static RestHighLevelClient newRemoteClient() {
97-
return new RestHighLevelClientBuilder(RestClient.builder(randomFrom(parseHosts("tests.rest.remote_cluster"))).build())
98-
.setApiCompatibilityMode(false)
99-
.build();
96+
return new RestHighLevelClient(RestClient.builder(randomFrom(parseHosts("tests.rest.remote_cluster"))));
10097
}
10198

10299
public void testFieldsOptionEmulation() throws Exception {

qa/ccs-rolling-upgrade-remote-cluster/src/test/java/org/elasticsearch/upgrades/SearchStatesIT.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.elasticsearch.client.Response;
4040
import org.elasticsearch.client.RestClient;
4141
import org.elasticsearch.client.RestHighLevelClient;
42-
import org.elasticsearch.client.RestHighLevelClientBuilder;
4342
import org.elasticsearch.client.indices.CreateIndexRequest;
4443
import org.elasticsearch.cluster.metadata.IndexMetadata;
4544
import org.elasticsearch.common.settings.Settings;
@@ -73,13 +72,11 @@ protected static RestHighLevelClient newLocalClient(Logger logger) {
7372
final List<HttpHost> hosts = parseHosts("tests.rest.cluster");
7473
final int index = random().nextInt(hosts.size());
7574
logger.info("Using client node {}", index);
76-
return new RestHighLevelClientBuilder(RestClient.builder(hosts.get(index)).build()).setApiCompatibilityMode(false).build();
75+
return new RestHighLevelClient(RestClient.builder(hosts.get(index)));
7776
}
7877

7978
protected static RestHighLevelClient newRemoteClient() {
80-
return new RestHighLevelClientBuilder(RestClient.builder(randomFrom(parseHosts("tests.rest.remote_cluster"))).build())
81-
.setApiCompatibilityMode(false)
82-
.build();
79+
return new RestHighLevelClient(RestClient.builder(randomFrom(parseHosts("tests.rest.remote_cluster"))));
8380
}
8481

8582
static int indexDocs(RestHighLevelClient client, String index, int numDocs) throws IOException {

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlJobSnapshotUpgradeIT.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.client.ResponseException;
1616
import org.elasticsearch.client.RestClient;
1717
import org.elasticsearch.client.RestHighLevelClient;
18-
import org.elasticsearch.client.RestHighLevelClientBuilder;
1918
import org.elasticsearch.client.ml.CloseJobRequest;
2019
import org.elasticsearch.client.ml.CloseJobResponse;
2120
import org.elasticsearch.client.ml.FlushJobRequest;
@@ -70,8 +69,10 @@ public class MlJobSnapshotUpgradeIT extends AbstractUpgradeTestCase {
7069
// min version in upgraded 7.series is 7.11.0
7170
private static final Version CPP_COMPATIBILTIY_VERSION = Version.V_7_11_0;
7271

73-
private static RestHighLevelClient HLRC(RestClient restClient) {
74-
return new RestHighLevelClientBuilder(restClient).setApiCompatibilityMode(false).build();
72+
private static class HLRC extends RestHighLevelClient {
73+
HLRC(RestClient restClient) {
74+
super(restClient, RestClient::close, new ArrayList<>());
75+
}
7576
}
7677

7778
private MachineLearningClient hlrc;
@@ -97,7 +98,7 @@ protected static void waitForPendingUpgraderTasks() throws Exception {
9798
* index mappings when it is assigned to an upgraded node even if no other ML endpoint is called after the upgrade
9899
*/
99100
public void testSnapshotUpgrader() throws Exception {
100-
hlrc = HLRC(client()).machineLearning();
101+
hlrc = new HLRC(client()).machineLearning();
101102
Request adjustLoggingLevels = new Request("PUT", "/_cluster/settings");
102103
adjustLoggingLevels.setJsonEntity("{\"persistent\": {" + "\"logger.org.elasticsearch.xpack.ml\": \"trace\"" + "}}");
103104
client().performRequest(adjustLoggingLevels);

0 commit comments

Comments
 (0)