【问题标题】:Migrating from Elastic 2 to 5从 Elastic 2 迁移到 5
【发布时间】:2018-10-24 22:43:22
【问题描述】:

1)我们使用旧版 ES 中的 NodeBuilder 按需在内存中创建节点。

2) 在 Elastic 5 中,由于 Nodebuilder 不可用,我们使用以下代码:

   File tmpDir = File.createTempFile("elastic",Long.toString(System.nanoTime()));
    Settings settings = Settings.builder()
            .put("http.enabled", true)
              .put("index.number_of_shards", "1")
              .put("path.data", new File(tmpDir, "data").getAbsolutePath())
              .put("path.logs", new File(tmpDir, "logs").getAbsolutePath())
              .put("path.work", new File(tmpDir, "work").getAbsolutePath()) 
              .put("transport.tcp.port", "9300")
              .put("network.host", "localhost")              
              .put("node.data", "true")
              .put("node.master", "true")

             .put("path.home", tmpDir)
            .put("transport.type", "local").build();
    return new ElasticsearchTemplate(new Node(settings).start().client());

3) 当我们尝试访问 ElasticsearchRepository 时,出现以下异常:

NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{6gkUXEX6Rsyowd928D0k_A}{localhost}{127.0.0.1:9200}]]
        at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:347)
        at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:245)
        at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
        at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:363)
        at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:408)
        at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
        at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
        at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.doCount(ElasticsearchTemplate.java:495)
        at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.count(ElasticsearchTemplate.java:473)
        at org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.count(AbstractElasticsearchRepository.java:150)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:377)
        at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:641)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
        at com.sun.proxy.$Proxy139.count(Unknown Source)
        at com.werner.ecp.elastic.service.carrier.ElasticCarrierServiceImpl.getCarrierCount(ElasticCarrierServiceImpl.java:58)
        at com.werner.ecp.elastic.service.carrier.ElasticCarrierServiceImpl$$FastClassBySpringCGLIB$$e96152a4.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)

4) 对缺少什么有任何想法吗?感谢您的帮助!

谢谢。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    在最近的版本中,您将无法在内存中生成节点,也无法使用已弃用的 TransportClient:考虑尽快使用“Java High Level Client

    您生成的节点尝试加入远程集群/节点,但什么也没找到,因为您的本地主机上没有运行 elasticsearch

    帮自己和您的项目一个忙,并切换到提到的 RestClient。

    如果您需要或想要坚持当前的方法,请参阅

    How to start elasticsearch 5.1 embedded in my java application?

    https://github.com/allegro/embedded-elasticsearch

    以下是一些背景信息:

    https://www.elastic.co/blog/state-of-the-official-elasticsearch-java-clients https://www.elastic.co/blog/the-elasticsearch-java-high-level-rest-client-is-out

    干杯

    【讨论】:

      猜你喜欢
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-12
      • 2017-04-24
      • 2021-06-23
      • 2017-06-19
      • 2015-12-18
      相关资源
      最近更新 更多