Elasticsearch Java Client Transport Client Exception

Hello!

I'm trying to get the Elasticsearch Java SDK TransportClient Initialized, and I'm getting the following exception:

rg.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.common.settings.IndexScopedSettings
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:982)

My POM looks like this since I'm using Maven:

<dependency>
   <groupId>org.elasticsearch</groupId>
   <artifactId>elasticsearch</artifactId>
   <version>6.0.1</version>
</dependency>
<dependency>
   <groupId>org.elasticsearch.client</groupId>
   <artifactId>transport</artifactId>
   <version>6.0.1</version>
</dependency>

Any help is appreciated!

A wild guess is that this spring version is not compatible?

Maybe, however I'm not sure why that would be the case. I'm not using spring-data-elasticsearch. Generally I'd say that unless I'm integrating with spring somehow, I haven't had any issues importing any other maven libraries.

Could you share more of your pom.xml and part of your code, ie. how you start elasticsearch?

Here is my setup code. All parts of my code related to ES are in the original post, let me know what I may be missing.

  Settings settings = Settings.builder()
		        .put("cluster.name", this.clusterName)
		        .put("client.transport.sniff", true).build();
			
			lazy_client = new PreBuiltTransportClient(settings);
			lazy_client.addTransportAddress(new TransportAddress(InetAddress.getByName(this.clusterHost), this.clusterPort));
			return lazy_client;

Could you just execute that code without Spring at all in a main() method?

The code looks good.

I moved on to use the RestHighLevelClient since the TransportClient is being deprecated eventually. I never solved this issue.

Great. But that was not my point.
Could you reproduce the problem without Spring?

Never tried it unfortunately, had to move on. I'm hard pressed to imagine how spring could cause the inability to find a class from a completely different maven library. If the issue does have something to do with spring, personally I'd call it a defect with the ES maven library, as an external dependency shouldn't cause class resolution problems.

Similar post (no maven though): Could Not Initialize Class PreBuiltTransportClient

Personally my opinion is that we should just let the TransportClient get deprecated, ignore this issue as a very uncommon situation, and for anyone reading this post, they should move on to using the RestClient or RestHighLevelClient.

Thanks for your continued help and support!

That's why I asked for this.
I'd like to understand the cause and make sure nothing wierd is on our end.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.