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 操作等。

转载于:https://www.cnblogs.com/unnunique/p/9362112.html

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

  1. HIVE学习系列——windows Hadoop安装(上)

    文章目录 整体流程概览 jre环境 jre安装 jre环境变量配置 Hadoop安装与配置 官网下载步骤 清华镜像下载步骤 Hadooponwindows下载 配置系统变量 hadoop初始文件配置 ...

  2. Android音视频学习系列(五) — 掌握音频基础知识并使用AudioTrack、OpenSL ES渲染PCM数据

    系列文章 Android音视频学习系列(一) - JNI从入门到精通 Android音视频学习系列(二) - 交叉编译动态库.静态库的入门 Android音视频学习系列(三) - Shell脚本入门 ...

  3. idea学习系列五之debug及插件的使用

    idea学习系列五之debug及插件的使用 上一篇,介绍了maven及服务器的使用,这里将介绍idea中debug及插件的使用.在实际开发中debug是最常用的了,而且idea相比于eclipse中的 ...

  4. Linux学习系列五:Shell命令脚本的基本语法

    这个系列的Linux教程主要参考刘遄老师的<Linux就该这么学>.用的系统是RHEL8,如果遇见一些命令出现问题,请首先检查自己的系统是否一致,如果不一致,可网上查一下系统间某些命令之间 ...

  5. Rasa 3.x 学习系列-Rasa 3.1+ ElasticSearch 8.2.0 对话机器人实战四

    Rasa 3.x 学习系列-Rasa 3.1+ ElasticSearch 8.2.0 对话机器人实战四 目录 ElasticSearch 全量更新 ElasticSearch 局部更新 Elasti ...

  6. HIVE学习系列——windows Hadoop安装(下)

    文章目录 1 整体流程概览 2 HIVE下载 3 MySQL(免安装版,zip格式解压直用) 3.1 系统中是否存在MySQL 3.2 MySQL下载 3.3 MySQL初始化 3.4 MySQL其它 ...

  7. Hive学习(三)操作Hive的方式及优化

    Hive 一.操作Hive的两种方式 1.通过Beenline 2.通过JDBC 二.Hive的优化 1.Hive优化的思想: 2.优化的方式 (1)开启本地模式 (2)开启并行计算 (3)严格模式 ...

  8. HIVE学习系列——Hive操作

    文章目录 Hive表介绍 基本句法-创建新表: Demo运行(以实际使用中的常用句法为编写规范): Q&A 基本句法-向table添加数据 Demo运行(承接创建的表) Q&A 基本句 ...

  9. Hadoop Hive概念学习系列之hive里的HiveQL——查询语言(十五)

    Hive的操作与传统关系型数据库SQL操作十分类似. Hive主要支持以下几类操作: DDL 1.DDL:数据定义语句,包括CREATE.ALTER.SHOW.DESCRIBE.DROP等. 详细点, ...

  10. hive 学习系列三(表格的创建create-table)

    表格创建: 语法 第一种建表的形式:说明: temporary 临时表,在当前回话内,这张表有效,当回话结束,可以理解为程序结束,则程序终止. external 外部表, hdfs 上的表的文件,并非 ...

最新文章

  1. HTTP与服务器的四种交互方式
  2. 地平线将融资10亿美元,或创AI芯片融资纪录
  3. 64bit 简单汇编加法
  4. 22.6. 视图(View)
  5. 【转载】dos下通过wmic命令查看硬盘和内存/CPU信息(windows自带命令查看硬件信息)
  6. hdu 2025:查找最大元素(水题,顺序查找)
  7. 互联网1分钟 |1029
  8. python三种基本控制结构_Python学习手册之控制结构(一)
  9. JsonWriter使用
  10. 理解 JavaScript 闭包
  11. nginx 的请求处理、请求的处理流程
  12. 分布式系统 c语言,C语言分布式系统中的进程标识!
  13. 【答辩问题】计算机专业本科毕业设计答辩的一般程序
  14. date-打印或者设置系统日期和时间
  15. 数据库中主键与索引的区别
  16. saspython知乎_银行业为什么喜欢用 sas 而不是 python?
  17. Python新闻网站项目-1.项目分析与产品设计
  18. 斗鱼弹幕服务器未响应,斗鱼看不到弹幕的解决方法步骤
  19. html中英文换行,css控制HTML中英文换行
  20. 高并发之volatile、synchronized关键和内存屏障(Memory Barrier)

热门文章

  1. leetcode 506. Relative Ranks(python)
  2. 基于vue利用openlayers加载天地图,高德地图
  3. 分享109个PHP源码,总有一款适合您
  4. 【计算机网络】思科实验(3):使用三层交换机实现跨VLAN间的通信
  5. CStdioFile类的使用1
  6. TiDB在摩拜单车在线数据业务的应用和实践
  7. 201919102004张雪婷(第二次作业)
  8. SQL函数入门--统计函数+分组函数
  9. python队列的实现
  10. win10修改用户名_win10最详细优化设置|win10专业版笔记本优化教程