NoSuchMethodError: org.elasticsearch.common.xcontent.XContentBuilder.string()Ljava/lang/String

I am using elasticsearch 6.1.1 alongside spring and I am getting the following error

 NoSuchMethodError: org.elasticsearch.common.xcontent.XContentBuilder.string()Ljava/lang/String 

what might be the reason?

When using springboot with
elasticsearch, you need to be explicit with some transitive dependencies as SpringBoot declares a version 6.4...

Basically you can put this in your pom.xml:

<properties>
  <elasticsearch.version>7.0.0<elasticsearch.version>
</properties>

See documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-customize-dependency-versions

Thanks. Actually, I am using gradle which manages the dependencies. I added these to lines to build.gradle, which seems to solve the problem.

compile 'org.elasticsearch:elasticsearch:6.1.1'
compile group: 'org.elasticsearch.client', name: 'transport', version: '6.1.1'

Yet, there is another issue. It says that spring cannot instantiate a bean which is caused by:

Caused by: java.lang.NoSuchMethodError: org.elasticsearch.search.fetch.subphase.highlight.HighlightPhase.<init>(Ljava/util/Map;)V

I think spring tries to invoke the constructor of the HighlightPhase class, which is supposed to have a no-arg constructor. However, such a constructor does not exist. What can I do to resolve this issue?

Try a more recent version like 6.8.

I tried that but another error occurred :slight_smile:

java.lang.NoSuchMethodError: org.elasticsearch.plugins.ActionPlugin$ActionHandler.<init>(Lorg/elasticsearch/action/Action;Ljava/lang/Class;[Ljava/lang/Class;)V

May be switch to the Rest client ?

I do not understand what you mean by switching to Rest client. could you be more specific about what changes are needed?

I mean: don't use the TransportClient anymore but the Rest Client.