我刚打酱油去了,不好意思

ES向Hadoop插入数据时出现异常[HEAD] on [索引/类型] failed

Elasticsearch | 作者 fengzibs | 发布于2017年09月30日 | 阅读数:10073

最近尝试使用ES向HDFS中插入数据,但是每次在提交作业的时候就会报出ERROR。并且已经考虑:
1.JDK版本问题。
2.jar包问题。
3.索引及类型一定存在。
以下是ERROR内容。
[ERROR] 2017-09-30 10:37:15,358 method:ESWriteHdfs.ESWriteHdfsTest.main(ESWriteHdfsTest.java:44)
[HEAD] on [mysql01/tlll] failed; server[192.168.246.134:9200] returned [400|Bad Request:]
org.elasticsearch.hadoop.rest.EsHadoopInvalidRequest: [HEAD] on [mysql01/tlll] failed; server[192.168.246.134:9200] returned [400|Bad Request:]
at org.elasticsearch.hadoop.rest.RestClient.checkResponse(RestClient.java:488)
at org.elasticsearch.hadoop.rest.RestClient.executeNotFoundAllowed(RestClient.java:459)
at org.elasticsearch.hadoop.rest.RestClient.exists(RestClient.java:519)
at org.elasticsearch.hadoop.rest.RestRepository.indexExists(RestRepository.java:388)
at org.elasticsearch.hadoop.rest.RestService.findPartitions(RestService.java:225)
at org.elasticsearch.hadoop.mr.EsInputFormat.getSplits(EsInputFormat.java:405)
at org.elasticsearch.hadoop.mr.EsInputFormat.getSplits(EsInputFormat.java:386)
at org.apache.hadoop.mapreduce.JobSubmitter.writeNewSplits(JobSubmitter.java:491)
at org.apache.hadoop.mapreduce.JobSubmitter.writeSplits(JobSubmitter.java:508)
at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:392)
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1268)
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1265)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1491)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:1265)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1286)
at ESWriteHdfs.ESWriteHdfsTest.main(ESWriteHdfsTest.java:42)
已邀请:

kennywu76 - Wood

赞同来自: fengzibs

和这个链接里的问题类似 https://github.com/elastic/ela ... /1020
 
HEAD /{index}/{type} 不被支持,改为了HEAD /{index}/_mapping/{type} , 所以ES一端报错。 确认下ES的版本,以及elasticsearch-hadoop的版本是否匹配,上面问题说明里提到ES 5.5.0已经没有这个问题。

kennywu76 - Wood

赞同来自:

@fengzibs  Github那个issue里的fix release,作者加了一个ES版本判断,对于5.x的版本,type的格式用" /index/_mapping/type ", 其他版本用 "/index/type" 。 所以es-hadoop升级到5.5.0以上肯定是必须的。
Fixing_issues_with_checking_for_index__type_and_document_existence__·_elastic_elasticsearch-hadoop_b8d2657.jpg

 

fengzibs - 90后IT男

赞同来自:

测试两天了,发现一个问题,在使用[HEAD/company/info]这种索引形式的时候会报如下异常:
org.elasticsearch.hadoop.EsHadoopIllegalArgumentException: Index [HEAD/company/info] missing and settings [es.index.read.missing.as.empty] is set to false
查阅资料后发现自己应该添加 conf.set("es.index.auto.create", "true");
                                             conf.set("es.index.read.missing.as.empty", "yes");
这两个属性,添加之后,运行无异常。感谢@kennywu76 的帮助。
除基本Job提交,ES需要配置的参数如下:
Configuration conf = new Configuration();  
conf.setBoolean("mapreduce.map.speculative", false);
conf.setBoolean("mapreduce.reduce.speculative", false);
//ElasticSearch节点
conf.set("es.nodes", "192.168.246.134");
conf.set("es.port", "9200");
conf.set("es.index.auto.create", "true");
conf.set("es.index.read.missing.as.empty", "yes");
//ElaticSearch Index/Type
conf.set("es.resource", "HEAD/company/info");
我使用的是es-hadoop5.0.0.jar   es5.5.2.jar  
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-hadoop</artifactId>
<version>5.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.5.2</version>
<scope>compile</scope>
</dependency>

xuezhixu

赞同来自:

maven 依赖中把
elasticsearch-spark
包换成5.50的就行了

要回复问题请先登录注册