In big data analytics scenarios, Hive excels at batch processing massive datasets, while Elasticsearch enables real-time search and analytics. Integrating the two is key to bridging the gap between large-scale batch processing and low-latency search, effectively breaking down data silos. Using the ES-Hadoop connector (Elasticsearch for Apache Hadoop), you can integrate MRS Hive with CSS Elasticsearch by allowing Hive to directly read and write Elasticsearch data in the form of foreign tables. This approach preserves familiar Hadoop ecosystem workflows while delivering second-level search latency
ES-Hadoop is a connector library that integrates Elasticsearch with the Hadoop ecosystem, allowing MapReduce, Hive, and Spark to directly read from and write to Elasticsearch indexes.
In the MRS Hive-Elasticsearch integration scenario, ES-Hadoop acts as a query translation layer: When you execute SQL queries in Hive, ES-Hadoop converts Hive's execution plan into Elasticsearch query requests sent over REST.
Figure 1 Connecting MRS Hive to an Elasticsearch cluster

For more information about ES-Hadoop and Hive, see the official document Apache Hive integration.
Download address: https://www.elastic.co/downloads/hadoop
Download address: https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient
curl -X GET http://<host>:<port>
curl -X GET http://<host>:<port> -u <user>:<password>
curl -X GET https://<host>:<port> -u <user>:<password> -ik
Variable | Description |
|---|---|
host | IP address of each node in the cluster. If the cluster contains multiple nodes, there will be multiple IP addresses. You can use any of them. |
port | Port number for accessing a cluster node. Generally, the port number is 9200. |
user | Username for accessing the cluster. |
password | Password of the user. If the password contains special characters, enclose the username and password in single quotation marks, for example, curl -u "user:password!" "http://<host>:<port>". |
hadoop fs -mkdir /tmp/hadoop-eshadoop fs -put elasticsearch-hadoop-x.x.x.jar /tmp/hadoop-eshadoop fs -put commons-httpclient-x.x.jar /tmp/hadoop-es
keytool -import -alias newname -keystore ./truststore.jks -file ./CloudSearchService.cer
keytool -import -alias newname -keystore .\truststore.jks -file .\CloudSearchService.cer
In the preceding command, newname indicates the user-defined certificate name.
After this command is executed, you will be prompted to set the certificate password and confirm the password. Securely store the password. It will be used for accessing the cluster.
chown -R omm truststore.jks
add jar hdfs:///tmp/hadoop-es/commons-httpclient-3.1.jar;add jar hdfs:///tmp/hadoop-es/elasticsearch-hadoop-x.x.x.jar;
This command is valid only for the current session.
Create a Hive foreign table and associate it with an Elasticsearch index by mapping the Hive table structure to Elasticsearch index fields.
CREATE EXTERNAL table IF NOT EXISTS student(id BIGINT,name STRING,addr STRING)STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'TBLPROPERTIES('es.nodes' = 'xxx.xxx.xxx.xxx:9200','es.port' = '9200','es.net.ssl' = 'false','es.nodes.wan.only' = 'false','es.nodes.discovery'='true','es.input.use.sliced.partitions'='false','es.resource' = 'student/_doc');
CREATE EXTERNAL table IF NOT EXISTS student(id BIGINT,name STRING,addr STRING)STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'TBLPROPERTIES('es.nodes' = 'xxx.xxx.xxx.xxx:9200','es.port' = '9200','es.net.ssl' = 'false','es.nodes.wan.only' = 'false','es.nodes.discovery'='true','es.input.use.sliced.partitions'='false','es.nodes.client.only'='true','es.resource' = 'student/_doc','es.net.http.auth.user' = 'username','es.net.http.auth.pass' = 'password');
CREATE EXTERNAL table IF NOT EXISTS student(id BIGINT,name STRING,addr STRING)STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'TBLPROPERTIES('es.nodes' = 'https://xxx.xxx.xxx.xxx:9200','es.port' = '9200','es.net.ssl' = 'true','es.net.ssl.truststore.location' = 'certFilePath','es.net.ssl.truststore.pass' = 'certPassword','es.nodes.wan.only' = 'false','es.nodes.discovery'='true','es.nodes.client.only'='true','es.input.use.sliced.partitions'='false','es.resource' = 'student/_doc','es.net.http.auth.user' = 'username','es.net.http.auth.pass' = 'password');
Parameter | Default Value | Description |
|---|---|---|
es.nodes | localhost | Address for accessing the Elasticsearch cluster. |
es.port | 9200 | Port number for accessing the cluster. It is typically 9200. |
es.nodes.wan.only | false | Whether to perform node sniffing. |
es.nodes.discovery | true | Whether to disable node discovery. Retain the default setting. |
es.input.use.sliced.partitions | true | Whether to use slices. Its value can be:
When this parameter is set to true, the prefetch phase may take much longer than the actual query. You are advised to set it to false to improve query efficiency. |
es.resource | NA | Target index and type. |
es.net.http.auth.user | NA | Username for accessing the cluster. Set this parameter only if the security mode is enabled. |
es.net.http.auth.pass | NA | Password of the user. Set this parameter only if the security mode is enabled. |
es.net.ssl | false | Whether SSL is enabled. The value can be:
|
es.net.ssl.truststore.location | NA | Path of the .jks certificate file, for example, file:///tmp/truststore.jks. |
es.nodes.client.only | false | Whether the Elasticsearch cluster has dedicated client nodes. The value can be:
|
es.net.ssl.truststore.pass | NA | Password of the .jks certificate file. |
For details about ES-Hadoop configuration items, see the official configuration description.
INSERT INTO TABLE student VALUES (1, "Lucy", "address1"), (2, "Lily", "address2");
select * from student;
The query result is as follows:
+-------------+---------------+---------------+| student.id | student.name | student.addr |+-------------+---------------+---------------+| 1 | Lucy | address1 || 2 | Lily | address2 |+-------------+---------------+---------------+2 rows selected (0.116 seconds)
The left part of the console is the command input box, and the triangle icon in its upper-right corner is the execution button. The right part shows the execution result.
GET /student/_search
Figure 2 Kibana query result
