hive 操作elasticsearch

一,从hive 表格向elasticsearch 导入数据

1,首先,创建elasticsearch 索引,索引如下

curl -XPUT '10.81.179.209:9200/zebra_info_demo?pretty' -H 'Content-Type: application/json' -d'
{
"settings": {
"number_of_shards":5,
"number_of_replicas":2
},
"mappings": {
"zebra_info": {
"properties": {
"name" : {"type" : "text"},
"type": {"type": "text"},
"province": {"type": "text"},
"city": {"type": "text"},
"citycode": {"type": "text", "index": "no"},
"district": {"type": "text"},
"adcode": {"type": "text", "index": "no"},
"township": {"type": "text"},
"bausiness_circle": {"type": "text"},
"formatted_address": {"type": "text"},
"location": {"type": "geo_point"},
"extensions": {
"type": "nested",
"properties": {
"map_lat": {"type": "double", "index": "no"},
"map_lng": {"type": "double", "index": "no"},
"avg_price": {"type": "double", "index": "no"},
"shops": {"type":"short", "index": "no"},
"good_comments": {"type":"short", "index": "no"},
"lvl": {"type":"short", "index": "no"},
"leisure_type": {"type": "text", "index": "no"},
"fun_type": {"type": "text", "index": "no"},
"numbers": {"type": "short", "index": "no"}
}
}
}
}
}
}
'

2,查看elasticsearch版本,下载相应的elasticsearch-hive-hadoop jar 包

可以用如下命令查看elastic search 的版本

本文版本5.6.9

到如下maven 官网下载jar 包。

https://repo.maven.apache.org/maven2/org/elasticsearch/elasticsearch-hadoop-hive/

选择正确的版本即可。

3, 把下载下来的jar 包上传到hdfs 路径下。

本文jar 包路径,hdfs:///udf/elasticsearch-hadoop-hive-5.6.9.jar

4,哦了,建表,用起来

DELETE jars;
add jar hdfs:///udf/elasticsearch-hadoop-hive-5.6.9.jar;
drop table zebra_info_demo;
CREATE EXTERNAL TABLE zebra_info_demo(
name string,
`type` string,
province double,
city string,
citycode string,
district string,
adcode string,
township string,
business_circle string,
formatted_address string,
location string,
extensions STRUCT<map_lat:double, map_lng:double, avg_price:double, shops:smallint, good_comments:smallint, lvl:smallint, leisure_type:STRING, fun_type:STRING, numbers:smallint>
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.nodes' = '10.81.179.209:9200',
'es.index.auto.create' = 'false',
'es.resource' = 'zebra_info_demo/zebra_info',
'es.read.metadata' = 'true',
'es.mapping.names' = 'name:name, type:type, province:province, city:city, citycode:citycode, district:district, adcode:adcode, township:township, business_circle:business_circle, formatted_address:formatted_address, location:location, extensions:extensions');

5, 往里面填充数据,就O了。

INSERT INTO TABLE zebra_info_demo
SELECT
a.name,
a.brands,
a.province,
a.city,
null as citycode,
null as district,
null as adcode,
null as township,
a.business_circle,
null as formatted_address,
concat(a.map_lat, ', ', a.map_lng) as `location`,
named_struct('map_lat', cast(a.map_lat as double), 'map_lng',cast(a.map_lng as double) ,'avg_price', cast(0 as DOUBLE), 'shops', 0S, 'good_comments', 0S, 'lvl', cast(a.lv1 as SMALLINT), 'leisure_type', '', 'fun_type', '', 'numbers', 0S) as extentions
from medicalsite_childclinic a;

运行结果:

二,已知elasticsearch 索引,然后,建立hive 表格和elasticsearch 进行交互。可以join 哦,一个字,liubi

1,先看一下索引和数据

已知索引如下:

curl -XPUT  '10.81.179.209:9200/join_tests?pretty' -H 'Content-Type: application/json' -d'
{
"mappings": {
"cities": {
"properties": {
"province": {
"type": "string"
},
"city": {
"type": "string"
}
}
}
}
}
}
' curl -XPUT '10.81.179.209:9200/join_tests1?pretty' -H 'Content-Type: application/json' -d'
{
"mappings": {
"shop": {
"properties":{
"name": {
"type": "string"
},
"city": {
"type": "string"
}
}
}
}
}
}
'

数据如下:

2,建立表格,写一堆有毒的sql 语句。

DELETE jars;
add jar hdfs:///udf/elasticsearch-hadoop-hive-5.6.9.jar;
create table join_tests(
province string,
city string
)STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.nodes' = '10.81.179.209:9200',
'es.index.auto.create' = 'false',
'es.resource' = 'join_tests/cities',
'es.read.metadata' = 'true',
'es.mapping.names' = 'province:province, city:city'); create table join_tests1(
name string,
city string
)STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.nodes' = '10.81.179.209:9200',
'es.index.auto.create' = 'false',
'es.resource' = 'join_tests1/shop',
'es.read.metadata' = 'true',
'es.mapping.names' = 'name:name, city:city'); SELECT
a.province,
b.city,
b.name
from join_tests a LEFT JOIN join_tests1 b on a.city = b.city;

3,运行结果

结束语

推荐一个useful 的工具, apache Hue, 可以用来管理hdfs 文件,hive 操作。mysql 操作等。

hive 学习系列五(hive 和elasticsearch 的交互,很详细哦,我又来吹liubi了)的更多相关文章

  1. hive 学习系列六 hive 去重办法的思考

    方法1,建立临时表,利用hive的collect_set 进行去重. create table if not exists tubutest ( name1 string, name2 string ...

  2. hive 学习系列之七 hive 常用数据清洗函数

    1,case when 的利用,清洗诸如评分等的内容,用例如下. case when new.comment_grade = '五星商户' then 50 when new.comment_grade ...

  3. Hive学习 系列博客

    原 Hive作业优化 原 Hive学习六:HIVE日志分析(用户画像) 原 Hive学习五--日志案例分析 原 Hive学习三 原 Hive学习二 原 Hive学习一 博客来源,https://blo ...

  4. scrapy爬虫学习系列五:图片的抓取和下载

    系列文章列表: scrapy爬虫学习系列一:scrapy爬虫环境的准备:      http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_python_00 ...

  5. 大数据学习系列之五 ----- Hive整合HBase图文详解

    引言 在上一篇 大数据学习系列之四 ----- Hadoop+Hive环境搭建图文详解(单机) 和之前的大数据学习系列之二 ----- HBase环境搭建(单机) 中成功搭建了Hive和HBase的环 ...

  6. Hadoop Hive概念学习系列之hive三种方式区别和搭建、HiveServer2环境搭建、HWI环境搭建和beeline环境搭建(五)

     说在前面的话 以下三种情况,最好是在3台集群里做,比如,master.slave1.slave2的master和slave1都安装了hive,将master作为服务端,将slave1作为服务端. 以 ...

  7. Hive学习之六 《Hive进阶— —hive jdbc》 详解

    接Hive学习五 http://www.cnblogs.com/invban/p/5331159.html 一.配置环境变量 hive jdbc的开发,在开发环境中,配置Java环境变量 修改/etc ...

  8. 【Hive学习之八】Hive 调优【重要】

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...

  9. 【Hive学习之一】Hive简介

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...

随机推荐

  1. Business Component(BC)和Business Object(BO)

    Siebel应用架构的一个成功的地方就是在应用里引入了BC,BO的概念,从而使得几千张关系数据表能够按照业务的含义组织成业务对象,对于业务人员而言具有了业务上的含义,而不仅仅是从技术人员的观点来对待数 ...

  2. vue-cli项目接口地址可配置化(多环境部署)一处修改多处适用

    本文档目的在于帮助对vue了解比较少的同学,能够快速配置vue应用中的接口地址.方便项目切换服务环境后,重新修改多组件的http请求地址. 一.前言 我们在上一篇文章分享了vue-cli项目基本搭建( ...

  3. Win+Tab键实现自定义程序列表间的窗口切换

    程序是用AutoHotkey语言写的, 说明: 以自己使用频率的顺序在ExeList自定义的程序间切换 切换可以以所有窗口切换,也可以按程序组切换(比如在word窗口间切换) 程序组可以分别定义排除的 ...

  4. 小于12px的字体大小在Chrome中不起作用

    今天遇见一个小问题,让人挺郁闷的,在Chrome浏览器中无法把字体变成12px以下.网上搜索以下,发现无论中文英文数字在网页中CSS设置小于12px后各大浏览器均支持,在谷歌chrome浏览器不支持解 ...

  5. Jerry的Fiori原创文章合集

    我曾经于2014年10月到2016年5月工作于SAP CRM Fiori应用的开发团队, 我所在的团队负责下列这8个Fiori应用的维护和持续开发: My Opportunities My Tasks ...

  6. 每天一个linux命令(21):chgrp,chown,chmod

    这三个命令都是改变文件属性与权限的,就放一起写了 charp:改变文件所属用户组 chown:改变文件所属者 chmod:改变文件的权限 一个文件对于owner,group ,others有不同的权限 ...

  7. spring 四种数据源配置方式

    1.spring自带的数据源 DriverManagerDataSource XML代码: <bean id="dataSource" class="org.spr ...

  8. AOE网络的关键路径问题

    关于AOE网络的基本概念可以参考<数据结构>或者search一下就能找到,这里不做赘述. 寻找AOE网络的关键路径目的是:发现该活动网络中能够缩短工程时长的活动,缩短这些活动的时长,就可以 ...

  9. js 3秒后跳转页面的实现代码

    隔多少秒后自动跳转到其它页(js脚本) 方法一: $(function(){ Load(URL); }) var secs = 3; //倒计时的秒数 var URL = "<?= u ...

  10. tomcate8配置多个二级域名问题解决根目录空白2017年12月9日

    <Host name="localhost" appBase="webapps" unpackWARs="true" autoDepl ...