ES笔记2

做接口性能测试前,经常需要往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/'

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章