24

I'm trying to connect from Java to ElasticSearch but I can only connect over HTTP. I can't use the TransportClient. Is there a Java client wrapper around the ElasticSearch REST APIs? If so, how do I use it?

Machavity
  • 30,841
  • 27
  • 92
  • 100
James Ward
  • 29,283
  • 9
  • 49
  • 85

4 Answers4

23

Hi There is a brand new project just matching your needs. It Java based Rest API for Elasticsearch

Check it out! its name JEST

dogukan sonmez
  • 335
  • 3
  • 8
  • I have the same issue, I have to be able to connect to a ES server over port 80 only. Jest looks nice, but unfortunately the Jest sample application is way behind the core Jest library. – PHY6 Sep 06 '14 at 00:42
9

A new "official" REST-based java client will be available starting with v5.0.0-alpha4.

imotov
  • 28,277
  • 3
  • 90
  • 82
5

We just open sourced Flummi, a Java HTTP/REST client for Elastic Search. It imitates the transport client's API as closely as possible, making it easy to port existing code. It also provides a better abstraction level than Jest, because it reports all the errors with Exceptions. Give it a try!

Simple usage example:

Flummi flummi = new Flummi("http://elasticsearch.base.url:9200");

SearchResponse searchResponse = flummi
   .prepareSearch("products")
   .setQuery(
      QueryBuilders.termQuery("color", "yellow").build()
    )
   .execute();

System.out.println("Found " 
   + searchResponse.getHits().getTotalHits()
   + " products");
searchResponse.getHits()
  .stream().map(hit -> hit.getSource().get("name").getAsString())
  .forEach(name -> System.out.println("Name: " + name));
Bastian Voigt
  • 5,311
  • 6
  • 47
  • 65
3

Since version 5.6 of the Elasticsearch Java SDK they provide a Java REST Client.

 RestClient restClient = RestClient.builder(
    new HttpHost("localhost", 9200, "http"),
    new HttpHost("localhost", 9201, "http")).build();

 // for the RestHighLevelClient
 RestHighLevelClient client =
    new RestHighLevelClient(restClient);
disco crazy
  • 31,313
  • 12
  • 80
  • 83