Skip to content

Commit dec7f83

Browse files
Hrlc compat doc (#228) (#230)
Co-authored-by: Sylvain Wallez <sylvain@elastic.co>
1 parent 0caac27 commit dec7f83

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

docs/migrate.asciidoc

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@ Migrating from the HLRC therefore requires some code rewrite in your
1010
application. This transition can however happen progressively as the two client
1111
libraries can coexist in a single application with no operational overhead.
1212

13+
[discrete]
14+
=== Compatibility mode: using a 7.17 client with {es} 8.x
15+
The HLRC version `7.17` can be used with {es} version `8.x` by enabling
16+
HLRC's compatibility mode (see code sample below). In this mode HLRC sends
17+
additional headers that instruct {es} `8.x` to behave like a `7.x` server.
18+
19+
The {java-client} doesn't need this setting as compatibility mode is always
20+
enabled.
21+
22+
[discrete]
23+
=== Using the same http client with the HLRC and the Java API Client
24+
25+
To avoid any operational overhead during the transition phase where an
26+
application would use both the HLRC and the new Java API Client, both clients
27+
can share the same Low Level Rest Client, which is the network layer that
28+
manages all connections, round-robin strategies, node sniffing, and so on.
29+
30+
The code below shows how to initialize both clients with the same HTTP client:
31+
32+
["source","java"]
33+
--------------------------------------------------
34+
include-tagged::{doc-tests}/MigrateHlrcTest.java[migrate]
35+
--------------------------------------------------
36+
<1> Enables compatibility mode that allows HLRC `7.17` to work with {es} `8.x`.
37+
1338
[discrete]
1439
=== Transition strategies
1540

@@ -26,18 +51,3 @@ For example:
2651
leveraging the tight integration of the new Java API Client with JSON object
2752
mappers.
2853

29-
30-
[discrete]
31-
=== Using the same transport with the HLRC and the Java API Client
32-
33-
To avoid any operational overhead during the transition phase where an
34-
application would use both the HLRC and the new Java API Client, both clients
35-
can share the same Low Level Rest Client, which is the network layer that
36-
manages all connections, round-robin strategies, node sniffing, and so on.
37-
38-
The code below shows how to initialize both clients with the same HTTP client:
39-
40-
["source","java"]
41-
--------------------------------------------------
42-
include-tagged::{doc-tests}/MigrateHlrcTest.java[migrate]
43-
--------------------------------------------------

java-client/src/test/java/co/elastic/clients/documentation/MigrateHlrcTest.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,44 @@
2525
import co.elastic.clients.transport.rest_client.RestClientTransport;
2626
import org.apache.http.HttpHost;
2727
import org.elasticsearch.client.RestClient;
28-
import org.elasticsearch.client.RestClientBuilder;
2928
import org.junit.Test;
3029

3130
public class MigrateHlrcTest {
3231

3332
// Fake HLRC -- we don't want to import it for just one example
3433
public static class RestHighLevelClient {
35-
public RestHighLevelClient(RestClientBuilder builder) {
34+
}
35+
36+
public static class RestHighLevelClientBuilder {
37+
38+
public RestHighLevelClientBuilder(RestClient restClient) {
3639
}
3740

38-
public RestClient getLowLevelClient() {
39-
return null;
41+
public RestHighLevelClientBuilder setApiCompatibilityMode(Boolean enabled) {
42+
return this;
43+
}
44+
45+
public RestHighLevelClient build() {
46+
return new RestHighLevelClient();
4047
}
4148
}
4249

4350
@Test
4451
public void migrate() {
4552
//tag::migrate
4653
// Create the low-level client
47-
RestClientBuilder httpClientBuilder = RestClient.builder(
54+
RestClient httpClient = RestClient.builder(
4855
new HttpHost("localhost", 9200)
49-
);
56+
).build();
5057

5158
// Create the HLRC
52-
RestHighLevelClient hlrc = new RestHighLevelClient(httpClientBuilder);
59+
RestHighLevelClient hlrc = new RestHighLevelClientBuilder(httpClient)
60+
.setApiCompatibilityMode(true) // <1>
61+
.build();
5362

54-
// Create the new Java Client with the same low level client
63+
// Create the Java API Client with the same low level client
5564
ElasticsearchTransport transport = new RestClientTransport(
56-
hlrc.getLowLevelClient(),
65+
httpClient,
5766
new JacksonJsonpMapper()
5867
);
5968

0 commit comments

Comments
 (0)