9

I've recently made the switch from elasticsearch 1.7 to 2.0 and I noticed the way you setup the client has changed. I went through the documentation and for some reason the client is always null. I was wondering if I have set it up correctly.

Here is my code:

    Client client = null;

    try {
        client = TransportClient.builder().build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
    } catch (Exception e) {
        Logger.log(e);
    } finally {
        client.close();
        try {
            conn.close();
        } catch (SQLException e) {
            Logger.log(e);
        }
    }
5
  • Do you get an exception? Your syntax is as it should be Commented Nov 5, 2015 at 12:56
  • I am receiving this error: java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor; Commented Nov 5, 2015 at 14:46
  • this is completely guava related and pertains to a problem with several guava versions in the same time. I suggest you to do a clean compile. If this is a war file delete the folder of project inside webapps and redeploy. nothing to do with ES Commented Nov 5, 2015 at 15:18
  • I've fixed the issue, it seemed to be a dependency issue, now I'm facing this issue: Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate org.elasticsearch.common.inject.InjectorImpl.toString() Commented Nov 5, 2015 at 15:21
  • @DanielBuckle Hi, were you able to solve the StackOverflowError issue? Commented Feb 2, 2016 at 18:54

1 Answer 1

14

As noted in the comments, but a little bit more in detail: Elasticsearch 2.0 uses Guava 18.0 (see https://github.com/elastic/elasticsearch/pull/7593). So to fix errors like java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concu‌rrent/Executor;, make sure to use Guava 18.0 as dependency and not other versions.

Sign up to request clarification or add additional context in comments.

1 Comment

Have tried using Guava 20.0 with elasticsearch 2.4.1 and it works! But its quite strange that Guava 15.0 seem to be working with the ES 2.3.5. IMHO, Its still a good idea to use Guava 18.0 or higher while upgrading to ES 2.0 or higher.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.