Elasticsearch provides a native protocol, used mainly for low-level communication between nodes, but is very useful for fast importing of huge data blocks. This protocol is available only for JVM languages and is commonly used in Java, Groovy, and Scala.
You need a working Elasticsearch cluster--the standard port for native protocol is 9300
.
The steps required to use the native protocol in a Java environment are as follows (in Chapter 14, Java Integration we'll discuss it in detail):
pom.xml
lines:<dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>5.0</version> </dependency>
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; ... Settings settings = Settings.settingsBuilder() .put("client.transport.sniff", true).build(); // we define a new settings // using sniff transport allows to autodetect other nodes Client client = TransportClient.builder() .settings(settings).build().addTransportAddress (new InetSocketTransportAddress("127.0.0.1", 9300)); // a client is created with the settings
To initialize a native client, some settings are required to properly configure it. The important ones are:
cluster.name
: It is the name of the clusterclient.transport.sniff
: It allows to sniff the rest of the cluster topology and adds discovered nodes into the client list of machines to useWith these settings, it's possible to initialize a new client giving an IP address and port (default 9300
).
This is the internal protocol used in Elasticsearch: it's the fastest protocol available to talk with Elasticsearch.
The native protocol is an optimized binary one and works only for JVM languages. To use this protocol, you need to include elasticsearch.jar
in your JVM project. Because it depends on Elasticsearch implementation, it must be the same version of the Elasticsearch cluster.
To use this protocol, you also need to study the internals of Elasticsearch, so it's not so easy to use as HTTP protocol.
Native protocol is very useful for massive data import. But as Elasticsearch is mainly thought as a REST HTTP server to communicate with, it lacks support for everything is not standard in Elasticsearch core, such as plugins entry points. Using this protocol, you are unable to call entry points made by external plugins in an easy way.
The native protocol is the most used in the Java world and it will be deeply discussed in Chapters 14, Java Integration, Chapters 15, Scala Integration, and Chapter 17, Plugin Development.
For further details on Elasticsearch Java API, they are available on Elasticsearch site at https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html.
18.222.182.73