Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java elasticsearch client always null

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);
        }
    }
like image 276
Daniel Buckle Avatar asked Nov 05 '15 12:11

Daniel Buckle


People also ask

How can I access Elasticsearch using Java?

The Elasticsearch can be accessed via a standard REST API or Java client libraries for various programming languages. The most obvious thing is the initial option to use the native Elasticsearch client.

How do I start Elastic Search on Unix?

Download the latest Elastic Search bundle for your platform. Decompress the package to a convenient location. On UNIX or Linux, spin up the instance with: When you see the logging message started, the node is ready to accept requests. For the Java example, you also need Eclipse and Apache Maven.

What are the best outgrowths of Elasticsearch?

Elasticsearch as a project has some interesting outgrowths that might also interest you. In particular, the so-called ELK stack — Elasticsearch, Logstash (for logging management), and Kibana (for reporting/visualization) — is gaining traction.

Why do we need Elasticsearch core project?

For example, the Elasticsearch core project is mostly required by the Java High-Level REST Client. It takes and handles the same web request for all input types, and we get the same response objects as the TransportClient, which the server returns. Suppose we have ever used Apache Lucene or Apache Solr.


1 Answers

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.

like image 160
spa Avatar answered Oct 24 '22 16:10

spa