How to use High Level Rest Client in Spring Data ES 3.2.0.M1
Asked Answered
D

1

3

Spring Data ES 3.2.0.M1 still uses old TransportClient instead of HighLevelRestClient

Spring Data ES 3.2.0.M1 supports High Level Rest Client, see Add support for Java High Level REST Client. I've added Spring Data ES 3.2.0.M1 to the SB2 app:

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>3.2.0.M1</version>
        </dependency>

However, still TransportClient is used. There are two indication of that: exceptions on start-up:

o.e.transport.netty4.Netty4Transport     : exception caught on transport layer [NettyTcpChannel{localAddress=/127.0.0.1:61171, remoteAddress=localhost/127.0.0.1:8085}], closing connection

io.netty.handler.codec.DecoderException: java.io.StreamCorruptedException: invalid internal transport message format, got (48,54,54,50)
    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:472) ~[netty-codec-4.1.33.Final.jar:4.1.33.Final]

and exception stacktrace when calling ElasticsearchTemplate:

    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:349)
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:247)
    at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:60)
    at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:382)
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:395)
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:384)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:46)
    at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.getSearchResponse(ElasticsearchTemplate.java:947)

Are there any config param to tell Spring Data ES to switch to new High Level Rest Client? The docs say nothing about it.

P.S. Spring Data ES 3.2.0.M1 has 6.4.3 ES client version:

Caused by: java.io.StreamCorruptedException: invalid internal transport message format, got (48,54,54,50)
    at org.elasticsearch.transport.TcpTransport.validateMessageHeader(TcpTransport.java:1327) ~[elasticsearch-6.4.3.jar:6.4.3]
    at org.elasticsearch.transport.netty4.Netty4SizeHeaderFrameDecoder.decode(Netty4SizeHeaderFrameDecoder.java:36) ~[transport-netty4-client-6.4.3.jar:6.4.3]
    at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:502) ~[netty-codec-4.1.33.Final.jar:4.1.33.Final]
    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:441) ~[netty-codec-4.1.33.Final.jar:4.1.33.Final]
    ... 20 common frames omitted

back-end runs 6.4.2 version:

bash-4.4$ curl http://127.0.0.1:8085
{
  "name" : "NA17WWR",
  "cluster_name" : "494164851665",
  "cluster_uuid" : "7t3LoK7PRp-ur6FyxSmHwQ",
  "version" : {
    "number" : "6.4.2",
    "build_flavor" : "oss",
    "build_type" : "zip",
    "build_hash" : "04711c2",
    "build_date" : "2018-10-16T09:16:35.059415Z",
    "build_snapshot" : false,
    "lucene_version" : "7.4.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
Driven answered 18/2, 2019 at 20:21 Comment(0)
P
1

As mentioned in the issue you're referring to, the high level REST client is available in ElasticsearchRestTemplate (see PR #216) not in ElasticsearchTemplate, which they'll keep until ES 7 for backward compatibility reasons.

You can create one with the configuration below:

<bean name="elasticsearchTemplate"
      class="org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate">
    <constructor-arg name="client" ref="restClient"/>
</bean>

<elasticsearch:rest-client id="restClient"/>
Postliminy answered 19/2, 2019 at 5:0 Comment(4)
Indeed, switching to ElasticsearchRestTemplate helps to access ES 6.4. Thanks! Makes sense to put it into docs: docs.spring.io/spring-data/elasticsearch/docs/3.2.0.M1/… However, there are still WARN logs from Netty. ES version on the client elasticsearch-6.4.3.jar and back-end match each other. Any hint about that?Driven
You sure need to make sure to use the right version of Spring Data ES with the same version of your ES server.Postliminy
I've updated the question with client and back-end ES versions. ES versions are almost match each other: 6.4.3 on client and 6.4.2 on back-endDriven
Are all your nodes using the same version? The problem is not the REST client but the TransportClient which doesn't use the same version as the ES server it is talking to.Postliminy

© 2022 - 2024 — McMap. All rights reserved.