index | next
How to create the client
To use the ES Kotlin Client, you simply have to create an instance of the Java High Level Restclient (and have this library on the classpath). There are several ways to do this.
Do it the Java way
If you have used the Java Highlevel client before, there is nothing special that you need to do. You simply create a Java Highlevel Rest client as usual. For example:
Use the extension function
The Java way is a bit boilerplate heavy. So we provide an alternative in the form of a
create() extension function that has a lot of parameters with sane default values.
create function has optional parameters that you can set. For example, this is how you would connect to Elastic Cloud:
Set up cluster sniffing
If your application has direct access to the Elasticsearch cluster and is not using a load balancer, you can use client side load balancing. For this purpose, the create function has a
useSniffing parameter. Obviously, this does not work if you are hosting in Elastic Cloud because in that case your cluster is behind a load balancer and the client won’t be able to talk to nodes in the cluster directly.
Sniffing allows the client to discover the cluster from an initial node and allows it to do simple round robing load balancing as well as recover from nodes disappearing. Both are useful features to have in production environment.
index | next
This Markdown is Generated from Kotlin code. Please don’t edit this file and instead edit the source file from which this page is generated.