编写Hadoop会将输出减少到Elasticsearch

时间:2014-08-15 15:11:47

标签: java hadoop elasticsearch elasticsearch-hadoop

我在理解如何将简单Hadoop的输出写回Elasticsearch时遇到一些麻烦。

作业配置为:

job.setOutputFormatClass(EsOutputFormat.class);
job.setOutputKeyClass(NullWritable.class);
job.setOutputValueClass(MapWritable.class);

Reducer:

final DoubleWritable average = new DoubleWritable(sum / size);

final MapWritable output = new MapWritable();
output.put(key, average);
context.write(NullWritable.get(), output);

然而,我得到了这个令人费解的(对我而言)例外:

14/08/15 16:59:54 INFO mapreduce.Job: Task Id : attempt_1408106733881_0013_r_000000_2, Status : FAILED Error: 
  org.elasticsearch.hadoop.EsHadoopIllegalArgumentException: 
  [org.elasticsearch.hadoop.serialization.field.MapWritableFieldExtractor@5796fabe] cannot extract value from object [org.apache.hadoop.io.MapWritable@dcdb8e97]    
    at org.elasticsearch.hadoop.serialization.bulk.TemplatedBulk$FieldWriter.write(TemplatedBulk.java:49)   
    at org.elasticsearch.hadoop.serialization.bulk.TemplatedBulk.writeTemplate(TemplatedBulk.java:101)  
    at org.elasticsearch.hadoop.serialization.bulk.TemplatedBulk.write(TemplatedBulk.java:77)   
    at org.elasticsearch.hadoop.rest.RestRepository.writeToIndex(RestRepository.java:130)   
    at org.elasticsearch.hadoop.mr.EsOutputFormat$EsRecordWriter.write(EsOutputFormat.java:161)     
    at org.apache.hadoop.mapred.ReduceTask$NewTrackingRecordWriter.write(ReduceTask.java:558)

在context.write()调用。

我有点困惑,不知道吗?

1 个答案:

答案 0 :(得分:1)

原来我在Job配置中犯了一个错误。我添加了以下内容:

configuration.set("es.mapping.id", "_id");

没有在传出的Mapwritable中实际添加_id字段;这导致ES抛出异常。

如果MapWritableFleldExtractor登录失败的哪个字段会很有用。