代码之家  ›  专栏  ›  技术社区  ›  user3216514

从弹性2迁移到弹性5

  •  0
  • user3216514  · 技术社区  · 7 年前

    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());
    

    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) 你有没有想过我错过了什么?谢谢你的帮助!

    谢谢。

    1 回复  |  直到 7 年前
        1
  •  0
  •   ibexit    7 年前

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

    您生成的节点尝试加入远程群集/节点,但找不到任何内容,因为本地主机上没有运行elasticsearch

    帮你自己和你的项目一个忙,切换到提到的rest客户机。

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

    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

    干杯