原来的ElasticSearch集群是自己搭建,通过elasticsearch-hadoop插入从hive连接到elasticsearch做查询时,没有出现在过“org.elasticsearch.hadoop.EsHadoopIllegalArgumentException:No data nodes with HTTP-enabled available”这样的异常信息,刚开始还以为是AWS中ElasticSearch需要设置,不过在其后台一直没有看到可以修改配置的地方。
在翻了一些论坛后,在这里https://discuss.elastic.co/t/unable-to-connect-to-es-cluster-on-aws-elasticsearch-service-through-hadoop/39283看到了类似的错误和场景,解决的方式是需要将外部表的属性“es.nodes.wan.only”值设置为true:
create external table test_in_es
(
id string,
k string,
v string
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES(
'es.nodes' = 'http://vpc-es-xxxxxxxxxxxxxx.eu-west-1.es.amazonaws.com:80',
'es.index.auto.create' = 'false',
'es.nodes.wan.only' = 'true',
'es.resource' = 'test/test',
'es.read.metadata' = 'true',
'es.mapping.names' = 'id:_metadata._id,k:k, v:v');
然后再执行查询就不会再报错误了。
配置“es.nodes.wan.only”在https://www.elastic.co/guide/en/elasticsearch/hadoop/master/configuration.html可以找到其详细的信息:
其意思也就是通过公网我访问云上或者一些限制性网络上的ES实例时,如AWS,通过声明该配置就会禁用发现其它节点的行为,后续的读和写都只会通过这个指定的节点进行操作,增加了该属性就可以访问云上或者受限制网络中的ES,但是也因为读写都是通过这个节点,因而性能上会受到比较大的影响。
Hadoop中使用ElasticSearch,请查看这篇文章:https://blog.csdn.net/fenglibing/article/details/80480235。