0

I am trying to connect with elasticsearch server(6.8.0) which is x-pack enabled and starting without any error. When I am trying to connect with java code following steps on webpage (https://www.elastic.co/guide/en/elastic-stack-overview/6.7/java-clients.html) I am getting below exception.

Caused by: org.elasticsearch.ElasticsearchException: Fail... Caused by: org.elasticsearch.ElasticsearchException: Failed to load plugin class [org.elasticsearch.xpack.XPackPlugin] at org.elasticsearch.plugins.PluginsService.loadPlugin(PluginsService.java:384) ~[elasticsearch-5.3.0.jar:5.3.0] at org.elasticsearch.plugins.PluginsService.(PluginsService.java:104) ~[elasticsearch-5.3.0.jar:5.3.0] at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:101) ~[elasticsearch-5.3.0.jar:5.3.0] at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:126) ~[elasticsearch-5.3.0.jar:5.3.0] at org.elasticsearch.client.transport.TransportClient.(TransportClient.java:268) ~[elasticsearch-5.3.0.jar:5.3.0] at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:128) ~[transport-6.2.4.jar:6.2.4] at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.(PreBuiltXPackTransportClient.java:55) ~[x-pack-transport-5.4.3.jar:5.4.3] at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.(PreBuiltXPackTransportClient.java:50) ~[x-pack-transport-5.4.3.jar:5.4.3] at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.(PreBuiltXPackTransportClient.java:46) ~[x-pack-transport-5.4.3.jar:5.4.3] at com.mastercard.customer.data.management.navigator.bff.config.ElasticSearchConfig.client(ElasticSearchConfig.java:56) ~[classes/:na] at com.mastercard.customer.data.management.navigator.bff.config.ElasticSearchConfig$$EnhancerBySpringCGLIB$$f999e02c.CGLIB$client$2() ~[classes/:na] at com.mastercard.customer.data.management.navigator.bff.config.ElasticSearchConfig$$EnhancerBySpringCGLIB$$f999e02c$$FastClassBySpringCGLIB$$d904a6aa.invoke() ~[classes/:na] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at com.mastercard.customer.data.management.navigator.bff.config.ElasticSearchConfig$$EnhancerBySpringCGLIB$$f999e02c.client() ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_162] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_162] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]

When searched on multiple sources
https://discuss.elastic.co/t/failed-to-load-plugin-class-org-elasticsearch-xpack-xpackplugin/183299

https://discuss.elastic.co/t/elasticsearch-doesnt-start-anymore-after-x-pack-settings/119200

and many more like that figure out this class is coming from x-pack-api-5.4.3,jar and when tried to open this jar in decompiler figure out nothing. attached image. I also tried different version of same jar and getting same problem.

enter image description here

Used dependencies are as below.

    <!-- Start x-pack -->
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <!-- <version>6.2.4</version> -->
        <version>5.4.3</version>
    </dependency>

    <dependency>
     <groupId>org.elasticsearch.client</groupId>
     <artifactId>x-pack-transport</artifactId>
      <version>5.4.3</version>
  </dependency>

<dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>5.3.0</version>
    </dependency>



<dependency>
        <groupId>com.unboundid</groupId>
        <artifactId>unboundid-ldapsdk</artifactId>
        <version>3.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk15on</artifactId>
        <version>1.58</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcpkix-jdk15on</artifactId>
        <version>1.58</version>
    </dependency>

    <!-- End x-pack -->

And used client code as below :

client = new PreBuiltXPackTransportClient(Settings.builder()
                .put("xpack.security.transport.ssl.enabled", true)
                //.put("xpack.security.transport.ssl.key", "/path/to/client.key")
                .put("xpack.security.transport.ssl.certificate", "cert.jks")
                .put("xpack.security.transport.ssl.certificate_authorities", "cert.jks")
                .put("xpack.security.transport.ssl.enabled", "true")
                .put("xpack.security.transport.ssl.keystore.password", "changeme")
                .put("xpack.security.transport.ssl.truststore.password", "changeme")
                .build())
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));

Thankful for any help.

prafful
  • 33
  • 7
  • In your stacktrace there is a mix of versions 5.3.0 and 6.2.4 — this won't work. Also you state that "I am trying to connect with elasticsearch server(6.8.0)" and your import has 5.4.3 as well as 5.3.0. The transport client is pretty sensitive to the version and I'd use the same version (down to the patch level) as your server; and definitely don't mix versions. – xeraa Sep 02 '19 at 22:48
  • xerra, thanks for your comments. When I trying to match versions,dependencies are not fetching from repository. What version is best when connecting with 6.8.0 ? – prafful Sep 03 '19 at 02:36
  • I don't think `x-pack-transport` actually exists or at least not since the code restructuring in 6.3.0. I think you should be able to get all the neccessary imports from `transport`. BTW the transport client is deprecated in 7.x, so if possible I'd look into the High Level REST client before writing more code. – xeraa Sep 03 '19 at 06:16
  • Tried out to remove x-pack-transportthing does not worked. Agreed High Level REST client is next invention, not seems to work with transport layer. and we are also using spring-data-elasticsearch so may not be compatible with that. – prafful Sep 04 '19 at 02:36
  • Then you'll need to approach this differently: What's your Spring Data version and what Elasticsearch version does it include? Spring Data adds quite a dependency on top of what you are trying to do and if you don't follow their version you'll have an uphill battle to fight. – xeraa Sep 04 '19 at 02:49

0 Answers0