title: Indexing Spark DateType Fields as Dates in ElasticSearch
body: <p>I am attempting to index a <code>DataFrame</code> of the below schema in ElasticSearch using the elasticsearch-hadoop connector.</p>
  
  <pre><code> |-- ROW_ID: long (nullable = false)
   |-- SUBJECT_ID: long (nullable = false)
   |-- HADM_ID: long (nullable = true)
   |-- CHARTDATE: date (nullable = false)
   |-- CATEGORY: string (nullable = false)
   |-- DESCRIPTION: string (nullable = false)
   |-- CGID: integer (nullable = true)
   |-- ISERROR: integer (nullable = true)
   |-- TEXT: string (nullable = true)
  </code></pre>
  
  <p>When writing this DataFrame to ElasticSearch, the "CHARTDATE" field is being written as a long. According to the documentation for the connector I am using (shown below) <code>DateType</code> fields in Spark should be written as string-formatted dates in ElasticSearch. As I was hoping to build some visualizaitons in Kibana leveraging the date fields, them being written as longs is proving problematic.</p>
  
  <p><a href="https://www.elastic.co/guide/en/elasticsearch/hadoop/6.4/spark.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/hadoop/6.4/spark.html</a></p>
  
  <p>Code used to produce error</p>
  
  <pre><code>val elasticOptions = Map(
        "es.nodes"              -&gt; esIP,
        "es.port"               -&gt; esPort,
        "es.mapping.id"         -&gt; primaryKey,
        "es.index.auto.create"  -&gt; "yes",
        "es.nodes.wan.only"     -&gt; "true",
        "es.write.operation"    -&gt; "upsert",
        "es.net.http.auth.user" -&gt; esUser,
        "es.net.http.auth.pass" -&gt; esPassword,
        "es.spark.dataframe.write.null" -&gt; "true",
        "es.mapping.date.rich" -&gt; "true"
      )
  castedDF.saveToEs(index, elasticOptions)
  </code></pre>
  
  <p>Is there a step I am missing to have these values written as ES dates?</p>