2017-03-16 11 views
0

私はelastic-repositoryを使用しようとしていますが、spring-data-elasticが付属しています。私のelasticsearchサーバーのバージョンは5.2.2です。 xpackは有効になっています。つまり、接続するにはユーザー名とパスワードが必要です。私は適切にユーザー名とパスワードを設定する方法を見つけることができませんでしたはxpackに接続していますelasticsearch 5.x via spring-data-elasticsearch

のpom.xml

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.1.RELEASE</version> 
</parent> 
<dependencies> 
    <dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-elasticsearch</artifactId> 
    </dependency> 
</dependencies> 

application.yml

spring: 
    data: 
    elasticsearch: 
     cluster-nodes: localhost:9200 
     properties: 
     shield: 
      user: "elastic:changeme" 

。私はいつも次のエラーを取得する:

2017-03-16 16:54:53.222 INFO 4005 --- [   main] org.elasticsearch.client.transport  : [Fixx] failed to get node info for {#transport#-1}{127.0.0.1}{127.0.0.1:9200}, disconnecting... 

org.elasticsearch.transport.ReceiveTimeoutTransportException: [][127.0.0.1:9200][cluster:monitor/nodes/liveness] request_id [0] timed out after [5006ms] 
    at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:698) ~[elasticsearch-2.4.4.jar:2.4.4] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_111] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_111] 
    at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_111] 

答えて

0

~[elasticsearch-2.4.4.jar:2.4.4]

これはES 5.2.2に接続するために2.4.4クライアントを使用していると信じて私をリード。 APIの多くは互換性がありますが、いくつかは互換性がありません(breaking changes in release notes参照)。クライアントライブラリを5.2にアップグレードすると、ここに情報があります:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html

+0

はい、そうです。私はバージョンの競合を逃した。しかし、現時点では、spring-data-elasticsaerchは残念ながらelasticsearch 5.xをサポートしていません。したがって、elasticsearchクライアントのみを5.xにアップグレードしても問題は解決しません。私はspring-data-elasticsearchをあきらめて、むしろ裸のクライアントを使うつもりです。 – Muatik

0

x-pack-transportを使用してください。

1、更新のpom.xml

... 
<!-- add the elasticsearch repo --> 
<repository> 
    <id>elasticsearch-releases</id> 
    <url>https://artifacts.elastic.co/maven</url> 
    <releases> 
     <enabled>true</enabled> 
    </releases> 
    <snapshots> 
     <enabled>false</enabled> 
    </snapshots> 
</repository> 
... 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-data-elasticsearch</artifactId> 
    <exclusions> 
     <exclusion> 
      <groupId>org.elasticsearch.client</groupId> 
      <artifactId>transport</artifactId> 
     </exclusion> 
    </exclusions> 
</dependency> 
<dependency> 
    <groupId>org.elasticsearch.client</groupId> 
    <artifactId>x-pack-transport</artifactId> 
    <version>5.2.2</version> 
</dependency> 
... 

2、ReがのtransportClientすべてだ

@Bean 
public TransportClient transportClient() throws UnknownHostException { 
    return new PreBuiltXPackTransportClient(Settings.builder() 
      .put("cluster.name", "es-cluster") 
      .put("xpack.security.user", "elastic:changeme") 
      .build()) 
      .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300)); 
} 

をインスタンス化します。

関連する問題