1

我无法使用以下方式连接到由 Elastic Cloud 托管的集群RestHighLevelClient

org.apache.http.ProtocolException: Not a valid protocol version: [0x1e][0x1f][0x20]*ÿÿÿÿ[0x26][0x27][0x28][0x2a][0x2b][0x2c][0x2d]No acceptable header received.

我可以使用连接org.elasticsearch.client.Client但不能使用org.elasticsearch.client.RestHighLevelClient.

这是我的代码:

// this does not work
fun restHighLevelClient(): RestHighLevelClient {
  val builder = RestClient.builder(HttpHost("https://xxxxxx.eu-central-1.aws.cloud.es.io:9343"))
  builder.setHttpClientConfigCallback { callback ->
    val provider = BasicCredentialsProvider()
    provider.setCredentials(AuthScope.ANY, UsernamePasswordCredentials("my-user", "my-password"))
    callback.setDefaultCredentialsProvider(provider)
  }
  return RestHighLevelClient(builder)
}

// this works
fun client(): Client {
  val settings = Settings.builder()
      .put("client.transport.nodes_sampler_interval", "5s")
      .put("transport.tcp.compress", true)
      .put("cluster.name", "xxxxxx")
      .put("xpack.security.transport.ssl.enabled", true)
      .put("request.headers.X-Found-Cluster", "\${cluster.name}")
      .put("xpack.security.user", "my-user:my-password")
      .build()
  val client = PreBuiltXPackTransportClient(settings)
  for (address in InetAddress.getAllByName("xxxxxx.eu-central-1.aws.cloud.es.io")) {
    client.addTransportAddress(TransportAddress(address, 9343))
  }
  return client
}

这是完整的堆栈跟踪:

2019-04-04 10:24:46.977  WARN 13025 --- [on(3)-127.0.0.1] s.b.a.e.ElasticsearchRestHealthIndicator : Elasticsearch health check failed
java.lang.RuntimeException: error while performing request
at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:959) ~[elasticsearch-rest-client-6.5.4.jar:6.5.4]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:229) ~[elasticsearch-rest-client-6.5.4.jar:6.5.4]
at org.springframework.boot.actuate.elasticsearch.ElasticsearchRestHealthIndicator.doHealthCheck(ElasticsearchRestHealthIndicator.java:61) ~[spring-boot-actuator-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:84) ~[spring-boot-actuator-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:98) ~[spring-boot-actuator-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:50) ~[spring-boot-actuator-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:246) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(ReflectiveOperationInvoker.java:76) ~[spring-boot-actuator-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(AbstractDiscoveredOperation.java:61) ~[spring-boot-actuator-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:126) ~[spring-boot-actuator-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:99) ~[spring-boot-actuator-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809) ~[na:na]
at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[na:na]
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466) ~[na:na]
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307) ~[na:na]
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399) ~[na:na]
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827) ~[na:na]
at java.base/jdk.internal.reflect.GeneratedMethodAccessor125.invoke(Unknown Source) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) ~[na:na]
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) ~[na:na]
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) ~[na:na]
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562) ~[na:na]
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796) ~[na:na]
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: org.apache.http.ProtocolException: Not a valid protocol version: [0x1e][0x1f][0x20]*ÿÿÿÿ[0x26][0x27][0x28][0x2a][0x2b][0x2c][0x2d]No acceptable header received.
at org.apache.http.impl.nio.codecs.AbstractMessageParser.parse(AbstractMessageParser.java:209) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:245) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) ~[httpasyncclient-4.1.4.jar:4.1.4]
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) ~[httpasyncclient-4.1.4.jar:4.1.4]
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:121) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591) ~[httpcore-nio-4.4.11.jar:4.4.11]
... 1 common frames omitted
Caused by: org.apache.http.ParseException: Not a valid protocol version:    *ÿÿÿÿ     No acceptable header received.
at org.apache.http.message.BasicLineParser.parseProtocolVersion(BasicLineParser.java:148) ~[httpcore-4.4.11.jar:4.4.11]
at org.apache.http.message.BasicLineParser.parseStatusLine(BasicLineParser.java:366) ~[httpcore-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.codecs.DefaultHttpResponseParser.createMessage(DefaultHttpResponseParser.java:112) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.codecs.DefaultHttpResponseParser.createMessage(DefaultHttpResponseParser.java:50) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.codecs.AbstractMessageParser.parseHeadLine(AbstractMessageParser.java:156) ~[httpcore-nio-4.4.11.jar:4.4.11]
at org.apache.http.impl.nio.codecs.AbstractMessageParser.parse(AbstractMessageParser.java:207) ~[httpcore-nio-4.4.11.jar:4.4.11]
... 11 common frames omitted

我正在使用 Elasticsearch 6.5.4。

构建.gradle

ext['elasticsearch.version'] = 6.5.4
dependencyManagement {
  imports {
    mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.3.RELEASE"
  }
}

dependencies {
  compile "com.unboundid:unboundid-ldapsdk:4.0.9"
  compile "org.elasticsearch.client:elasticsearch-rest-client:6.5.4"
  compile "org.elasticsearch.client:elasticsearch-rest-high-level-client:6.5.4"
  compile "org.elasticsearch.client:transport:6.5.4"
  compile "org.elasticsearch.client:x-pack-transport:6.5.4"
  compile "org.elasticsearch.plugin:transport-netty4-client:6.5.4"
  compile "org.elasticsearch:elasticsearch:6.5.4"
  compile "org.springframework.boot:spring-boot"
  compile "org.springframework.boot:spring-boot-autoconfigure"
  compile "org.springframework.data:spring-data-elasticsearch:3.2.0.M2"
}

这是相关的依赖报告:

+--- com.unboundid:unboundid-ldapsdk:4.0.9
+--- org.elasticsearch.client:elasticsearch-rest-client:6.5.4
|    +--- org.apache.httpcomponents:httpclient:4.5.2 -> 4.5.7 (*)
|    +--- org.apache.httpcomponents:httpcore:4.4.5 -> 4.4.11
|    +--- org.apache.httpcomponents:httpasyncclient:4.1.2 -> 4.1.4
|    +--- org.apache.httpcomponents:httpcore-nio:4.4.5 -> 4.4.11
|    \--- commons-codec:commons-codec:1.10 -> 1.11
+--- org.elasticsearch.client:elasticsearch-rest-high-level-client:6.5.4
|    +--- org.elasticsearch:elasticsearch:6.5.4
|    |    +--- org.elasticsearch:elasticsearch-core:6.5.4
|    |    +--- org.elasticsearch:elasticsearch-secure-sm:6.5.4
|    |    +--- org.elasticsearch:elasticsearch-x-content:6.5.4
|    |    |    +--- org.elasticsearch:elasticsearch-core:6.5.4
|    |    |    +--- org.yaml:snakeyaml:1.17 -> 1.23
|    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.8.11 -> 2.9.8
|    |    |    +--- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.8.11 -> 2.9.8
|    |    |    +--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.11 -> 2.9.8
|    |    |    \--- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.8.11 -> 2.9.8 (*)
|    |    +--- org.apache.lucene:lucene-core:7.5.0
|    |    +--- org.apache.lucene:lucene-analyzers-common:7.5.0
|    |    +--- org.apache.lucene:lucene-backward-codecs:7.5.0
|    |    +--- org.apache.lucene:lucene-grouping:7.5.0
|    |    +--- org.apache.lucene:lucene-highlighter:7.5.0
|    |    +--- org.apache.lucene:lucene-join:7.5.0
|    |    +--- org.apache.lucene:lucene-memory:7.5.0
|    |    +--- org.apache.lucene:lucene-misc:7.5.0
|    |    +--- org.apache.lucene:lucene-queries:7.5.0
|    |    +--- org.apache.lucene:lucene-queryparser:7.5.0
|    |    +--- org.apache.lucene:lucene-sandbox:7.5.0
|    |    +--- org.apache.lucene:lucene-spatial:7.5.0
|    |    +--- org.apache.lucene:lucene-spatial-extras:7.5.0
|    |    +--- org.apache.lucene:lucene-spatial3d:7.5.0
|    |    +--- org.apache.lucene:lucene-suggest:7.5.0
|    |    +--- org.elasticsearch:elasticsearch-cli:6.5.4
|    |    |    +--- net.sf.jopt-simple:jopt-simple:5.0.2
|    |    |    \--- org.elasticsearch:elasticsearch-core:6.5.4
|    |    +--- com.carrotsearch:hppc:0.7.1
|    |    +--- joda-time:joda-time:2.10.1
|    |    +--- com.tdunning:t-digest:3.2
|    |    +--- org.hdrhistogram:HdrHistogram:2.1.9
|    |    +--- org.apache.logging.log4j:log4j-api:2.11.1 -> 2.11.2
|    |    \--- org.elasticsearch:jna:4.5.1
|    +--- org.elasticsearch.client:elasticsearch-rest-client:6.5.4 (*)
|    +--- org.elasticsearch.plugin:parent-join-client:6.5.4
|    +--- org.elasticsearch.plugin:aggs-matrix-stats-client:6.5.4
|    +--- org.elasticsearch.plugin:rank-eval-client:6.5.4
|    \--- org.elasticsearch.plugin:lang-mustache-client:6.5.4
|         \--- com.github.spullara.mustache.java:compiler:0.9.3
+--- org.elasticsearch.client:transport:6.5.4
|    +--- org.elasticsearch:elasticsearch:6.5.4 (*)
|    +--- org.elasticsearch.plugin:transport-netty4-client:6.5.4
|    |    +--- io.netty:netty-buffer:4.1.30.Final -> 4.1.33.Final
|    |    +--- io.netty:netty-codec:4.1.30.Final -> 4.1.33.Final
|    |    +--- io.netty:netty-codec-http:4.1.30.Final -> 4.1.33.Final
|    |    +--- io.netty:netty-common:4.1.30.Final -> 4.1.33.Final
|    |    +--- io.netty:netty-handler:4.1.30.Final -> 4.1.33.Final
|    |    +--- io.netty:netty-resolver:4.1.30.Final -> 4.1.33.Final
|    |    \--- io.netty:netty-transport:4.1.30.Final -> 4.1.33.Final
|    +--- org.elasticsearch.plugin:reindex-client:6.5.4
|    |    \--- org.elasticsearch.client:elasticsearch-rest-client:6.5.4 (*)
|    +--- org.elasticsearch.plugin:lang-mustache-client:6.5.4 (*)
|    +--- org.elasticsearch.plugin:percolator-client:6.5.4
|    +--- org.elasticsearch.plugin:parent-join-client:6.5.4
|    \--- org.elasticsearch.plugin:rank-eval-client:6.5.4
+--- org.elasticsearch.client:x-pack-transport:6.5.4
|    +--- org.elasticsearch.plugin:x-pack-core:6.5.4
|    \--- org.elasticsearch.client:transport:6.5.4 (*)
+--- org.elasticsearch.plugin:transport-netty4-client:6.5.4 (*)
+--- org.elasticsearch:elasticsearch:6.5.4 (*)
+--- org.springframework.boot:spring-boot:2.1.3.RELEASE (*)
+--- org.springframework.boot:spring-boot-autoconfigure:2.1.3.RELEASE (*)
\--- org.springframework.data:spring-data-elasticsearch:3.2.0.M1 -> 3.2.0.M2
     +--- org.springframework:spring-context:5.1.5.RELEASE (*)
     +--- org.springframework:spring-tx:5.1.5.RELEASE (*)
     +--- org.springframework.data:spring-data-commons:2.2.0.M2 -> 2.1.5.RELEASE (*)
     +--- joda-time:joda-time:2.10.1
     +--- org.elasticsearch.client:transport:6.6.1 -> 6.5.4 (*)
     +--- org.elasticsearch.plugin:transport-netty4-client:6.6.1 -> 6.5.4 (*)
     +--- org.elasticsearch.client:elasticsearch-rest-high-level-client:6.6.1 -> 6.5.4 (*)
     +--- com.fasterxml.jackson.core:jackson-core:2.9.8
     +--- com.fasterxml.jackson.core:jackson-databind:2.9.8 (*)
     \--- org.slf4j:slf4j-api:1.7.25

知道我做错了什么吗?提前致谢!

4

1 回答 1

4

我的错,我使用了错误的 Elasticsearch Rest 端口 :-(

以下是 Elastic Cloud 的端口:

  • 运输港口:9343
  • 休息端口:9243
于 2019-04-12T13:47:42.763 回答