從Hive導入數據到ES

大數據方興未艾,Hive在業界,是大數據的標配了。所以hive數據添加到ES的應用場景仍是比較常見的。
學習ES官方的es-hadoop, 有從hive導數據到ES. 實驗可行。
hive的版本: hive-1.1.0-cdh5.9.0node

具體的步驟以下:
step1 將elasticsearch-hadoop-hive-version.jar添加到hiveapi

wget https://artifacts.elastic.co/downloads/elasticsearch-hadoop/elasticsearch-hadoop-6.3.0.zip
unzip elasticsearch-hadoop-6.3.0.zip
hdfs dfs -mkdir /user/test/es_hadoop/
hdfs dfs -put elasticsearch-hadoop-hive-6.3.0.jar /user/test/es_hadoop/
ADD JAR hdfs://test/user/test/es_hadoop/elasticsearch-hadoop-hive-6.3.0.jar;

step2 建立Hive表:restful

CREATE EXTERNAL TABLE elastic_table(
   uuid string,
   key1 int,
   key2 int,
   day string
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource'='index/type',
'es.nodes'='serverIP:port',
'es.index.auto.create'='TRUE',
'es.mapping.id' = 'uuid'
);

step3 添加數據app

INSERT OVERWRITE TABLE elastc_table
SELECT uuid, key1,key2, day FROM source s;

爲了不客戶端版本的問題,es-hadoop使用es的restfull接口導入數據,該接口使用的是Http協議。elasticsearch

一般使用ES, 首當其衝的問題就是: 如何快速將海量數據導入ES? 因爲ES的數據須要創建倒排索引,因此導入數據到ES的瓶頸每每在ES這裏。ide

本文記錄了將Hive表的數據導入ES的方法。這裏背後隱藏了mapreduce,即集羣的威力。 這裏有個系列博客,講述如何最大限度的挖掘ES索引數據的性能,立足點是ES。 oop

https://qbox.io/blog/series/how-to-maximize-elasticsearch-indexing-performance

做者總結有3點:性能

  1. 根據應用場景建立mapping, 去除沒必要要的字段,如_all, _source;
    這裏是從應用場景下手,以免存儲沒必要要的信息來提高索引數據的性能。學習

  2. 修改es/lucene默認的設置,好比
    refresh_interval,
    index.number_of_replicas,
    index.merge.scheduler.max_thread_count,
    index.translog.interval,
    indices.memory.index_buffer_size
    index.index_concurrency
    等參數。 這裏是從集羣的角度進行調優, 一般用於大批量導入數據到ES。大數據

  3. 若是前面兩種仍是沒能解決問題,那就須要對集羣進行橫向擴展了,好比增長集羣的分片數量。
    集羣大了後,各個結點的功能就須要單一化,專一化了。

好比節點只承擔數據相關的任務。

node.master: false
node.data: true
node.ingest: false

bulk api的批量值須要實驗,找到最佳參數。建議bulk的大小在5M~10M.

使用SSD硬盤。索引數據時,副本數設置爲0。

參考:
http://note4code.com/2016/06/17/hive-%E5%90%91-elasticsearch-%E5%AF%BC%E5%87%BA%E6%95%B0%E6%8D%AE/

相關文章
相關標籤/搜索