在elasticsearch-hadoop的具体使用中碰到了几个问题,有必要记录一下,避免下次遇到时又要重新研究。
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集群。
整个集群的节点分为以下三种主要类型
Master nodes -- 负责维护集群状态,不保存index数据, 硬件要求: 一般性的机器就可以,给es进程分配16g内存Data Nodes -- 只保存index的数据,不被选举为Master nodes 硬件要求: 配置要求越高越好,使用大硬盘,有条件可以上SSD硬盘Client Nodes -- 主要用于负载均衡,不被选举为Master node, 也不保存index数据 硬件要求: 24核CPU, 64G内存或更高一个合理的集群应该包含三个master nodes, 1到多个data nodes, 最少一个client node
通用配置,以centos为例,使用rpm安装包
sudo rpm -ivh elasticsearch-version.rpm sudo chkconfig --add elasticsearch修改/etc/sysconfig/elasticsearch, 修改ES_HEAP_SIZE和JAVA_OPTS的内容,注意elasticsearch建议使用的最大内存是32G,
ES_HEAP_SIZE=32g JAVA_OPTS="-Xms32g"修改/etc/security/limits.conf, 添加如下内容
* hard memlock unlimited * soft memlock unlimited/etc/elasticsearch/elasticsearch.yml 内容配置
master节点 node.master: true node.data: false discovery.zen.ping.unicast.hosts: ["master1","master2","master3"] network.host: ${HOSTNAME} data节点 node.master: false node.data: true discovery.zen.ping.unicast.hosts: ["master1","master2","master3"] network.host: ${HOSTNAME}如果为elasticsearch配置了多块硬盘,可以修改 DATA_DIR 的值,多个目录使用逗号(,)分开
client节点 node.master: false node.data: false discovery.zen.ping.unicast.hosts: ["master1","master2","master3"] network.host: ${HOSTNAME}需要注意的是elasticsearch在centos中使用service elasticsearch restart有时不能达到效果,需要分开来做
sudo kill -9 `pgrep -f elasticsearch` sudo service elasticsearch start为了记录针对集群的查询内容,建议使用nginx来做反向代理,nginx安装在client node上,conf.d/default.conf 最简单的配置如下
upstream elasticsearch { server 127.0.0.1:9200; } server { gzip on; access_log /var/log/nginx/access.log combined; listen 80 default_server; server_name _; #charset koi8-r; #access_log logs/host.access.log main; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { root /usr/share/nginx/html; index index.html index.htm; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://elasticsearch; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }建议安装如下插件
kopf 兼容es 1.x, 2.xkopf
./elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf/{branch|version} head 兼容es 1.xbigdesk 兼容es 1.xelasticsearch搜索功能强劲,就是查询语法复杂,presto提供了非常open的plugin机制,我改进了下原有的presto-elasticsearch connector,现发布于github
运行办法 在etc/catalog目录下添加es.properties即可,内容如下
connector.name=elasticsearch elasticsearch-server=localhost elasticsearch-port=9300 elasticsearch-clustername=elasticsearch_demo时间仓促,错误在所难免,欢迎批评指正。
相关资源:python入门教程(PDF版)