Apache Hive integration with Elasticsearh
2016-03-15 22:58
671 查看
Configurationedit
使用hive时,声明一个由Elasticsearch支持的外部表。 可以用TBLPROPERTIES指定一个配置属性(作为一个Hadoop Configuraion object替代品)
CREATE EXTERNAL TABLE artists (...)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource' = 'radio/artists',
'es.index.auto.create' = 'false') ;
elasticsearch-hadoop setting |
Mappingedit
在默认情况下,elasticsearch-hadoop使用Hive table schema映射数据到Elasticsearch,过程中使用字段名和类型,但是有很多情况下在hive中字段名不能被Elasticsearch使用。这时,可以用es.mapping.names设置接受一个以逗号分隔的字段名表映射在下面这种格式:Hive field name:Elasticsearch field name
To wit:
CREATE EXTERNAL TABLE artists (...)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource' = 'radio/artists',
'es.mapping.names' = 'date:@timestamp , url:url_123 ');
两个字段名date和url,用逗号分隔开
name mapping for two fields | |
Hive column date mapped in Elasticsearch to @timestamp | |
Hive column url mapped in Elasticsearch to url_123 |
Hive是大小写不敏感,但Elasticsearch大小写敏感。这样可能会创建无效的queries(例如,Hive的列和Elasticsearch的列不匹配)。为了避免这个,elasticsearch-hadoop总是转化Hive列名为小写。它推荐使用默认Hive并且大写名字仅能作为Hiver命令来避免混合大小写的名字。
Hive treats missing values through a special value NULL as indicated here here. This means that when running an incorrect query (with incorrect or non-existing field names) the Hive tables will be populated with NULL instead of throwing an exception. Make sure to validate your data and keep a close eye on your schema since updates will otherwise go unnotice due to this lenient behavior.
Hive用特定值null处理缺失值。这意味着当运行一个错误的query(用一个错误的或者不存在的字段名)hive表就用null填充就不报错了。确认你的数据有效并注意schema的更新,不然就注意不到这个现象。
Writing data to Elasticsearchedit
With elasticsearch-hadoop, Elasticsearch becomes just an external table in which data can be loaded or read from:
在elasticsearch-hadoop中,Elasticsearch就成了一个数据可被load或read的外部表
CREATE EXTERNAL TABLE artists (
id BIGINT,
name STRING,
links STRUCT<url:STRING, picture:STRING>)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource' = 'radio/artists');
-- insert data to Elasticsearch from another table called 'source'
INSERT OVERWRITE TABLE artists
SELECT NULL, s.name, named_struct('url', s.url, 'picture', s.picture)
FROM source s;
Elasticsearch Hive StorageHandler | |
Elasticsearch resource (index and type) associated with the given storage |
在id需要被指定的文档,可以用映射es.mapping.id。接着前面的例子,说明Elasticsearch用字段id做文档的id,更新table属性:
CREATE EXTERNAL TABLE artists (
id BIGINT,
...)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.mapping.id' = 'id'...);
Writing existing JSON to Elasticsearchedit
写已有的JSON 到Elasticsearch中
在任务是要写入数据已经在JSON中,elasticsearch-hadoop允许直接索引无需应用转换;数据直接发送到Elasticsearch。在这个情况下,一种需要说明通过设置JSON输入es.input.json 参数。这时elasticsearch-hadoop期望输出表仅含有一个内容使用JSON的字段,就这样库会被辨识为特定的文本类型(例如string或binary)或就叫(toString).
相关文章推荐
- 分享Hive的一份胶片资料
- Hadoop生态上几个技术的关系与区别:hive、pig、hbase 关系与区别
- 巧用mysql提示符prompt清晰管理数据库的方法
- 两大步骤教您开启MySQL 数据库远程登陆帐号的方法
- phpmyadmin 4+ 访问慢的解决方法
- linux系统下实现mysql热备份详细步骤(mysql主从复制)
- CentOS 5.5下安装MySQL 5.5全过程分享
- MySQL复制的概述、安装、故障、技巧、工具(火丁分享)
- MySQL中删除重复数据的简单方法
- elasticsearch批量数据导入和导出
- 使用ElasticSearch+LogStash+Kibana+Redis搭建日志管理服务
- ElasticSearch 使用心得
- ES中如何使用逗号来分词
- 将Hive的默认数据库Derby改为Postgresql
- kettle中对hive操作时需要知道的东西
- Hive安装配置
- Hive - truncate partition、drop partition 区别
- Elasticsearch2.2.0数据操作
- Elasticsearch2.2.0安装ik中文分词
- Elasticsearch2.2.0安装pinyin插件