在elasticsearch-hadoop的具体使用中碰到了几个问题,有必要记录一下,避免下次遇到时又要重新研究。

利用spark读取es数据源的简单示例

import org.elasticsearch.spark.sql._

val esOptions = Map("es.nodes"->"192.168.1.2,192.168.1.3", "es.scroll.size"->"1000", "es.field.read.as.array.include"->"SampleField")

val esDF = sqlContext.read.format("org.elasticsearch.spark.sql").options(esOptions).load("sampleindex/es-spark")

esDF.registerTempTable("esdemotbl")

es.scroll.size 一次性读入的记录数,默认是10, 如果不设置为大一点的值,要从es中读取1亿条数据,那将是一个漫长的过程

es.field.read.as.array.include 有的字段在es中是以string类型存储,但其中包含逗号(,), spark默认认为这是数组类型,如果读取这种字段的话,就会报错,怎么办,那就用es.field.read.as.array.include来显式指明

spark读取es中数据的时候,partition数目取决于es中指定index的shard数目,为了获得比较高的并发读取性能,建议适当设置shard数目,为什么是适当,因为具体取决于集群规模等多种因素。

字段名的大小写问题

在hive中,字段名是_大小写不敏感_的, 但在ES中是大小写敏感的

你说,这又怎么样。 呵呵, 这意味着不做特殊处理,永远无法读出es中大写字段名的内容,你看到的将是满屏的_NULL_

这该怎么破,很简单,指定 es.mapping.names

比如在es中,字段名为DemoField, 要读出其中的内容,hive表的字义就该这样写

create external table es_demo_tbl(
demofield string)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.nodes'='192.168.1.2,192.168.1.3', 'es.resource'='demoindex/sample',
'es.mapping.names'='demofield:DemoField')

注意是先hive中的字段名,然后是es中的字段名

elasticsearch-hadoop使用示例的更多相关文章

  1. Elasticsearch 邻近查询示例

    Elasticsearch 邻近查询示例(全切分分词) JAVA API方式: SpanNearQueryBuilder span = QueryBuilders.spanNearQuery(); s ...

  2. 使用java如何操作elasticsearch?简单示例。

    在线API:https://www.elastic.co/guide/en/elasticsearch/client/java-api/2.4/transport-client.html教程:http ...

  3. 运行Hadoop的示例程序WordCount-Running Hadoop Example

      In the last post we've installed Hadoop 2.2.0 on Ubuntu. Now we'll see how to launch an example ma ...

  4. Java中ElasticSearch的删除示例

    public class DeleteElasticAPI { private static RestClient restClient; static { restClient=RestClient ...

  5. hadoop SequenceFile示例

    1.写入,SequenceFile的key和value不一定是Writable,只要能被Serialization序列化和反序列化就可以. private static final String[] ...

  6. elasticsearch 高级搜索示例 es7.0

    基础数据 创建索引 PUT mytest { "mappings": { "properties": { "title": { " ...

  7. es第十篇:Elasticsearch for Apache Hadoop

    es for apache hadoop(elasticsearch-hadoop.jar)允许hadoop作业(mapreduce.hive.pig.cascading.spark)与es交互. A ...

  8. Spring Boot + Elasticsearch 使用示例

    本文分别使用 Elasticsearch Repository 和 ElasticsearchTemplate 实现 Elasticsearch 的简单的增删改查 一.Elastic Stack El ...

  9. Hadoop Map/Reduce 示例程序WordCount

    #进入hadoop安装目录 cd /usr/local/hadoop #创建示例文件:input #在里面输入以下内容: #Hello world, Bye world! vim input #在hd ...

  10. Hadoop vs Elasticsearch – Which one is More Useful

    Hadoop vs Elasticsearch – Which one is More Useful     Difference Between Hadoop and Elasticsearch H ...

随机推荐

  1. 计算 TP90TP99TP...

    what-do-we-mean-by-top-percentile-or-tp-based-latency tp90 is a minimum time under which 90% of requ ...

  2. java6

    1:二维数组(理解) (1)元素是一维数组的数组. (2)格式: A:数据类型[][] 数组名 = new 数据类型[m][n]; B:数据类型[][] 数组名 = new 数据类型[m][]; C: ...

  3. php实验四

    实验四 1.创建一个Person类,Person中包含三个属性name,age,wealth,分别设置为public,private,protected,再定义Person类的子类Student. 2 ...

  4. ACM/ICPC 之 最小割转网络流(POJ3469)

    重点:构图 //最小割转网络流 //邻接表+Dinic //Time:5797Ms Memory:6192K #include<iostream> #include<cstring& ...

  5. css中选择器的使用技巧

    td:first-child{选择第一个} td:last-child{选择最后一个} td:nth-child(3){选择第3个} 一个简单的选择方法,很方便

  6. 整合Spring、SpringMVC、MyBatis

    spring+springmvc+mybatis集成 一个核心:将对象交给spring管理. 1新建web项目 2添加项目jar包 spring包见上一篇博客 3建立项目的目录结构 4完成Mapper ...

  7. 通过VS创建简单的WCF服务

    http://www.cnblogs.com/artech/archive/2007/09/15/893838.html http://www.topwcftutorials.net/2013/09/ ...

  8. Struts2 回顾总结

    1.第一个Struts2入门案例 1.找jar包 Struts2-core xwork-core ognl javasist freemarker commons-lang commons-io co ...

  9. mybatis注意事项

    1.如果用注解的方式加载配置CRUD查询的语句时,映射文件中的配置是: <mapper class="com.day03_mybaits.test3.UserMapper"/ ...

  10. 浏览器-08 chromium 渲染2

    Chromium 硬件加速合成 一个网页通常可以包