ES笔记2_通过hive往ES批量造数

本文详细介绍了如何使用Hive进行数据表创建及数据生成,并通过建立Hive与Elasticsearch之间的映射关系实现数据的高效同步。此外,还提供了具体的Hive SQL语句示例,以及如何通过curl命令验证数据是否成功导入ES的方法。

做接口性能测试前,经常需要往ES中造数。

记录一下,举个栗子:

1.在hive中创建数据表并造数,如edw.courier_order_time。可以通过其它表创建新表(create table tablename as select )

2.建立hive与es的映射关系

drop table edw.courier_work_time_total_20190812 ;
CREATE EXTERNAL TABLE edw.courier_work_time_total_20190812 (
courierId bigint  COMMENT '闪送员id',
workTime bigint COMMENT '工作时长',
workServiceTime bigint COMMENT '休息时长',
day string COMMENT '日期'
) 
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES(
'es.nodes' = '192.1.1.1:9200,192.1.1.2:9200,192.1.1.3:9200,192.1.1.4:9200',
'es.index.auto.create' = 'true',
'es.nodes.wan.only'='true',
'es.number_of_shards'='1',
'es.resource' = 'courier_work_time_total_20190812/courier_work_time',--对应es中的index/type
'es.mapping.names' = '' --一般都是一一映射
);

3.插入数据到映射表里

insert overwrite table edw.courier_work_time_total_20190812
select * from edw.courier_order_time where dt_ymd = 20190812;

 

4.查看数据是否正确插入到es

查看mapping(ps:可以在步骤1之前建立好mapping):

curl -X GET 'http://bigdata-dev-es-1:9200/courier_work_time_total_20190812/_mapping/courier_work_time?pretty'

查看数据量:

curl 'http://bigdata-dev-es-1:9200/courier_work_time_total_20190812/courier_work_time/_count?pretty'

 

另外:

建索引语句:

curl -H "Content-Type: application/json" -XPUT 'http://bigdata-dev-es-1:9200/gal_dw?pretty=true' -d '{"mappings":{"dwv_tkt_ride":{"properties":{"activity_id":{"type":"integer"},"bi_type":{"type":"keyword"},"channel_id":{"type":"integer"}}}}}'

删除索引语句:

curl -XDELETE 'http://bigdata-dev-es-1:9200/gal_dw/'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值