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);
        }
    }
Daniel Buckle
  • 628
  • 1
  • 9
  • 19
  • Do you get an exception? Your syntax is as it should be – Sezin Karli Nov 05 '15 at 12:56
  • I am receiving this error: `java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;` – Daniel Buckle Nov 05 '15 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 – Sezin Karli Nov 05 '15 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()` – Daniel Buckle Nov 05 '15 at 15:21
  • @DanielBuckle Hi, were you able to solve the `StackOverflowError` issue? – Animesh Pandey Feb 02 '16 at 18:54

1 Answers1

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.

spa
  • 5,059
  • 1
  • 35
  • 59
  • 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. – quickbrownfox Nov 21 '16 at 14:01