Clients for Elasticsearch

Using the Java programming language the following are the ways by which Elasticsearch can be communicated.

  • Transport Client: Used by REST clients internally. Full support from Elasticsearch as these are used by Elasticsearch internally to achieve various tasks. The most efficient methodology for communication and is quite fast. It uses a binary protocol for communication, the same protocol Elasticsearch uses internally. The following code shows how can you acquire the transport client to communicate with the Elasticsearch. More details on this can be found in elastic's official blog here https://goo.gl/0ZKZIk:
TransportAddress address = new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200);
Settings settings = Settings.builder().put("cluster.name", "dataLakeCluster").build();
Client client = new PreBuiltTransportClient(settings).addTransportAddress(address);
  • Java REST Client: Communicates with Elasticsearch using HTTP. Compatible with most Elasticsearch versions. Uses Apache HTTP Async Client internally for sending HTTP requests. More detail on this can be found in the official elastic blog here https://goo.gl/IKui5X:
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200, "http")).build();
Response response = restClient.performRequest("GET", "/", Collections.singletonMap("pretty", "true"));
  • Jest: Apart from the default REST client by Elasticsearch, this is an alternative HTTP-based Elasticsearch client. The following Java code shows how you can obtain a Jest client:
Client JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig( new HttpClientConfig.Builder("http://localhost:9200").multiThreaded(true) .build());
JestClient client = factory.getObject();
  • Spring Data Elasticsearch: Spring is a very popular framework in Java. It has abstracted many low-level details for many data stores using a module called Spring Data. Spring has a specific module to abstract Elasticsearch from its low-level details in the Spring Data Elasticsearch module.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.32.1