-
Book Overview & Buying
-
Table Of Contents
ElasticSearch Cookbook - Second Edition
By :
Thrift is an interface definition language, initially developed by Facebook, used to define and create services. This protocol is now maintained by Apache Software Foundation.
Its usage is similar to HTTP, but it bypasses the limit of HTTP protocol (latency, handshake and so on) and it's faster.
You need a working instance of ElasticSearch cluster with the thrift plugin installed (https://github.com/elasticsearch/elasticsearch-transport-thrift/); the standard port for the Thrift protocol is 9500.
To use the Thrift protocol in a Java environment, perform the following steps:
pom.xml file; the code lines are:<dependency> <groupId>org.apache.thrift</groupId> <artifactId>libthrift</artifactId> <version>0.9.1</version> </dependency>
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.elasticsearch.thrift.*;
TTransport transport = new TSocket("127.0.0.1", 9500);
TProtocol protocol = new TBinaryProtocol(transport);
Rest.Client client = new Rest.Client(protocol);
transport.open();TSocket(host, port) setting, using the ElasticSearch thrift standard port 9500.TBinaryProtocol(transport) parameter.Rest.Client utility class and other utility classes are generated by elasticsearch.thrift. It resides in the org.elasticsearch.thrift namespace.transport.open()).transport.close()).Some drivers, to connect to ElasticSearch, provide an easy-to-use API to interact with Thrift without the boulder that this protocol needs.
For advanced usage, I suggest the use of the Thrift protocol to bypass some problems related to HTTP limits, such as:
A big advantage of this protocol is that on the server side it wraps the REST entry points so that it can also be used with calls provided by external REST plugins.
Change the font size
Change margin width
Change background colour