Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch-spark fails on null values #242

Closed
rbraley opened this Issue Aug 6, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@rbraley
Copy link

rbraley commented Aug 6, 2014

The following example fails with nulls. Replacing null with None seems to work

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.SparkContext._ 
import org.elasticsearch.spark._
object EsSparkExample extends App{

  val conf = new SparkConf(true)
    .set("es.index.auto.create", "true") 
    .set("es.nodes", "127.0.0.1:9200")

  val sc = new SparkContext("local[10]", "EsSparkExample", conf)
  val numbers = Map("one" -> null, "two" -> 2, "three" -> 3)
  val airports = Map("OTP" -> "Otopeni", "SFO" -> "San Fran")

  sc.makeRDD(Seq(numbers, airports)).saveToEs("spark/docs")
}

with
org.elasticsearch.hadoop.serialization.EsHadoopSerializationException: org.codehaus.jackson.JsonGenerationException: Can not write null value, expecting field name
org.elasticsearch.hadoop.serialization.json.JacksonJsonGenerator.writeNull(JacksonJsonGenerator.java:218)
org.elasticsearch.hadoop.serialization.builder.JdkValueWriter.write(JdkValueWriter.java:49)
org.elasticsearch.spark.serialization.ScalaValueWriter.write(ScalaValueWriter.scala:56)
org.elasticsearch.spark.serialization.ScalaValueWriter$$anonfun$write$2.apply(ScalaValueWriter.scala:29)
org.elasticsearch.spark.serialization.ScalaValueWriter$$anonfun$write$2.apply(ScalaValueWriter.scala:27)
scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:772)
scala.collection.immutable.Map$Map3.foreach(Map.scala:154)
scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:771)
org.elasticsearch.spark.serialization.ScalaValueWriter.write(ScalaValueWriter.scala:27)
org.elasticsearch.hadoop.serialization.builder.ContentBuilder.value(ContentBuilder.java:258)
org.elasticsearch.hadoop.serialization.bulk.TemplatedBulk.doWriteObject(TemplatedBulk.java:68)
org.elasticsearch.hadoop.serialization.bulk.TemplatedBulk.write(TemplatedBulk.java:55)
org.elasticsearch.hadoop.rest.RestRepository.writeToIndex(RestRepository.java:130)
org.elasticsearch.spark.rdd.EsRDDWriter.write(EsRDDWriter.scala:33)
org.elasticsearch.spark.rdd.EsRDDFunctions$$anonfun$saveToEs$1.apply(EsRDDFunctions.scala:43)
org.elasticsearch.spark.rdd.EsRDDFunctions$$anonfun$saveToEs$1.apply(EsRDDFunctions.scala:43)
org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:111)
org.apache.spark.scheduler.Task.run(Task.scala:51)
org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:183)

@costin costin closed this in a68a5f5 Aug 6, 2014

@costin

This comment has been minimized.

Copy link
Member

costin commented Aug 6, 2014

@rbraley Thanks - it was actually a trivial fix once I discovered the mistake (which took a while :) ) Published the artifacts to Maven as well (trailing -75).

@costin costin added bug labels Aug 6, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.