通过hive向写elasticsearch的写如数据

hive 和 elasticsearch 的整合可以参考官方的文档:

ES-hadoop的hive整合 : https://www.elastic.co/guide/en/elasticsearch/hadoop/current/hive.html#hive

ES-hadoop的配置说明 : https://www.elastic.co/guide/en/elasticsearch/hadoop/current/configuration.html

1. 新建一个hive表es_goods_order

将该hive表的数据存储指定到ES上,指定索引的ID列是goods_order_id('es.mapping.id' = 'goods_order_id',);

指定数据写入的方式是upsert('es.write.operation'='upsert'),如果id不存在就插入,如果存在就执行更新操作。

add jar file:///home/hadoop/lib/elasticsearch-hadoop-5.1.1.jar;
set username=fxin.zhao
use temp;
CREATE EXTERNAL TABLE es_goods_order(
goods_order_id string,
sale_place string,
station_place string,
multi_channel_id string,
business_date string,
discount string,
discount_type string,
payment_amouunt string,
refun_amount string
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES(
'es.resource' = 'test_crm/es_goods_order',
'es.nodes'='10.10.110.125',
'es.port'='9200',
'es.mapping.id' = 'goods_order_id',
'es.write.operation'='upsert'
);

向es_goods_order表中插入数据:3分钟启用1个maper写入80万数据。Es中的index是在导入数据的时候检查的,如果不存在,则会创建。

add jar file:///home/hadoop/lib/elasticsearch-hadoop-5.1.1.jar;
use temp;
insert into table es_goods_order
select goods_order_id,
sale_place,
station_place,
multi_channel_id,
business_date,
discount,
discount_type,
payment_amouunt,
refun_amount
from ods.goods_order
where dt >= '2016-10-01'
and dt <= '2016-10-04';
  • 验证upsert功能是否有效:再重新写入部分相同的数据。
insert into table es_goods_order
select goods_order_id,
sale_place,
station_place,
multi_channel_id,
business_date,
discount,
discount_type,
payment_amouunt,
refun_amount
from ods.goods_order
where dt = '2016-10-01'
limit 1000;

结论:

指定ID问题: 通过'es.mapping.id' = 'goods_order_id' 指定id。

数据更新问题: 通过'es.write.operation'='upsert' 来执行插入或者更新操作(如果id存在)。

  • ES 的hive表基于json存储。

hadoop fs -put 20170111202237 /tmp/fuxin.zhao/es_json

add jar file:///home/hadoop/lib/elasticsearch-hadoop-5.1.1.jar;
use temp;
##创建一个临时表
CREATE EXTERNAL TABLE es_json_tmp (
json STRING
);
##给临时表添加数据
load data inpath '/tmp/fuxin.zhao/es_json/20170116185548' into table es_json_tmp; drop table es_json;
##创建json格式的hive表
CREATE EXTERNAL TABLE es_json (
json STRING
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES(
'es.resource' = 'test_crm/es_json',
'es.nodes'='10.10.110.125',
'es.port'='9200',
'es.input.json' = 'yes',
'es.mapping.id' = 'uid'
); ##执行插入数据操作
insert into table es_json
select json
from es_json_tmp;

报出如下错误:

Caused by: org.elasticsearch.hadoop.rest.EsHadoopInvalidRequest: Found unrecoverable error [10.10.110.125:9200] returned Bad Request(400) - Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters.; Bailing out..

原因是json文档中的_id 字段是ES的元数据字段,属于ES的关键字,解决方法:

vi 20170116185548

将文档中的_id 替换成uid。

1,$s/_id/uid/g

通过hive向写elasticsearch的写如数据的更多相关文章

  1. 象写程序一样写博客:搭建基于github的博客

    象写程序一样写博客:搭建基于github的博客   前言 github 真是无所不能.其 Pages 功能 支持上传 html,并且在页面中显示.于是有好事者做了一个基于 github 的博客管理工具 ...

  2. 《自己动手写CPU》写书评获赠书活动结果

    <自己动手写CPU>写书评获赠图书的读者有: 京东:8***2.16号哨兵.magicyu.kk6803.jddickyd.杰出的胡兵 亚马逊:徐贺.马先童.jaychen.farmfar ...

  3. Python写的链接数据库存取数据

    Python写的链接数据库存取数据 #!/usr/bin/python # -*- coding: UTF-8 -*- from __future__ import print_function im ...

  4. SSD 为什么顺序写比随机写性能更好?

    SSD以Page为单位做读写,以Block为单位做垃圾回收,Page一般有16KB大小,Block一般有几十MB大小,SSD写数据的逻辑是: 1)将该块数据所在的Page读出 2)修改该Page中该块 ...

  5. 如果使用引用方式引用了js后 则不能再本地写js 因为写了后不会有效果

    如果使用引用方式引用了js后 则不能再本地写js 因为写了后不会有效果

  6. mnesia的脏写和事物写的测试

    在之前的文章中,测试了脏读和事物读之间性能差别,下面测试下脏写和事物写之间的性能差别: 代码如下: -module(mnesia_text). -compile(export_all). -recor ...

  7. OS: 读者写者问题(写者优先+LINUX+多线程+互斥量+代码)(转)

    一. 引子 最近想自己写个简单的 WEB SERVER ,为了先练练手,熟悉下在LINUX系统使用基本的进程.线程.互斥等,就拿以前学过的 OS 问题开开刀啦.记得当年学读者写者问题,尤其是写者优先的 ...

  8. Qt侠:像写诗一样写代码,玩游戏一样的开心心情,还能领工资!

    [软]上海-Qt侠 2017/7/12 16:11:20我完全是兴趣主导,老板不给我钱,我也要写好代码!白天干,晚上干,周一周五干,周末继续干!编程已经深入我的基因,深入我的骨髓,深入我的灵魂!当我解 ...

  9. 程序代写, CS代写, 代码代写, CS编程代写, java代写, python代写, c++/c代写, R代写, 算法代写, web代写

    互联网一线工程师程序代写 微信联系 当天完成 查看大牛简介特色: 学霸代写,按时交付,保证原创,7*24在线服务,可加急.用心代写/辅导/帮助客户CS作业. 客户反馈与评价 服务质量:保证honor ...

随机推荐

  1. 正规式->最小化DFA说明

      整体的步骤是三步: 一,先把正规式转换为NFA(非确定有穷自动机), 二,在把NFA通过"子集构造法"转化为DFA, 三,在把DFA通过"分割法"进行最小化 ...

  2. Spring Boot实践——统一异常处理

    注解说明 @ControllerAdvice,是Spring3.2提供的新注解,从名字上可以看出大体意思是控制器增强.让我们先看看@ControllerAdvice的实现: /** * Special ...

  3. FireFox add dict

    1.Firefox add add-ons: inline translation 2.https://login.live.com/login.srf?wa=wsignin1.0&wtrea ...

  4. sqlserver数据库导出成insert语句

    点击数据库名称右键=========>任务========>生成脚本 一.表结构导出成sql语句 二.数据导出成sql语句

  5. 转化RGB颜色为CMYK颜色

    procedure RGBTOCMYK(R : byte; G : byte; B : byte; var C : byte; var M : byte; var Y : byte; var K : ...

  6. ConcurrentDictionary内部机制粗解

    ConcurrentDictionary是线程安全类,是什么在保证? 内部类 private class Tables { internal readonly Node[] m_buckets; // ...

  7. ShaderForge打造自定义光照模型

    [ShaderForge打造自定义光照模型] 1.Lambert逻辑图. 2.Blinn-Phong逻辑图. 参考:https://www.youtube.com/watch?v=EjCXwV0YYd ...

  8. Shader.WarmupAllShaders

    [Shader.WarmupAllShaders]

  9. 【BZOJ2806】Cheat 【广义后缀自动机+单调队列优化dp+二分】

    题意 有M篇标准作文组成了一个作文库(每篇作文都是一个01的字符串),然后给出N篇作文(自然也是01字符串).如果一个长度不小于L的串在作文库中出现过,那么它是熟悉的.对于某一篇作文,我们要把它分为若 ...

  10. react native 触摸Touchable***的区别(TouchableWithoutFeedback、TouchableOpacity、TouchableHighlight、TouchableNativeFeedback)

    一.问题背景: react native的跨平台开发没有button的概念,而是使用touchable系列实现点击触发效果. 而touchable系列就有四个之多,而且相互之间仍有较大差别,这就给我们 ...