Spring Data ES 3.2.0.M1仍然使用old TransportClient而不是HighLevelRestClient
TransportClient
HighLevelRestClient
Spring Data ES 3.2.0.M1支持High Level Rest Client,请参阅 添加对Java High Level REST Client的支持。我已经将Spring Data ES 3.2.0.M1添加到SB2应用程序中:
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-elasticsearch</artifactId> <version>3.2.0.M1</version> </dependency>
但是,仍然TransportClient被使用。有两种指示:启动例外:
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]
和调用时的异常stacktrace ElasticsearchTemplate:
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)
是否有任何配置参数告诉Spring Data ES切换到新的High Level Rest Client?文档对此一言不发。
PS Spring Data ES 3.2.0.M1具有 6.4.3 ES客户端版本:
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
后端运行 6.4.2 版本:
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" }
如您所提到的问题中所述,高级REST客户端位于ElasticsearchRestTemplate(参见PR#216)中ElasticsearchTemplate,而不位于中,出于向后兼容的原因,它们将保留到ES 7。
ElasticsearchRestTemplate
您可以使用以下配置创建一个:
<bean name="elasticsearchTemplate" class="org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate"> <constructor-arg name="client" ref="restClient"/> </bean> <elasticsearch:rest-client id="restClient"/>