title: How does Elasticsearch convert dates to JSON string representations?
body: <p>I have a question about how Elasticsearch converts dates to JSON string representations. I'm using version 1.4.2 for this example.</p>
  
  <p>First, POST a simple document containing a date field called 'postDate' to 'myindex' with type 'datetest': </p>
  
  <pre><code>curl -XPOST "http://localhost:9200/myindex/datetest/" -d'
  {
      "content": "Hello World!",
      "postDate": "2009-11-15T14:12:12"
  }'
  </code></pre>
  
  <p>We can look at the field mapping for postDate that was automatically generated. </p>
  
  <pre><code>curl -XGET "http://localhost:9200/myindex/_mapping/"
  
  ##postDate":{"type":"date","format":"dateOptionalTime"}
  </code></pre>
  
  <p>Now let's POST another document. This time postDate has a UTC offset included. </p>
  
  <pre><code>
  curl -XPOST "http://localhost:9200/myindex/datetest/" -d'
  {
      "content": "Hello World!",
      "postDate": "2009-11-15T14:12:12-07:00"
  }'
  </code></pre>
  
  <p>Now, let's retrieve our documents that we created above:</p>
  
  <pre><code>curl -XGET 'http://localhost:9200/myindex/datetest/_search?q=Hello'
  
    "hits": {
      "total": 2,
      "max_score": 0.11506981,
      "hits": [
        {
          "_index": "myindex",
          "_type": "datetest",
          "_id": "AUw0TyJgqFHXxhSON3r8",
          "_score": 0.11506981,
          "_source": {
            "content": "Hello World!",
            "postDate": "2009-11-15T14:12:12"
          }
        },
        {
          "_index": "myindex",
          "_type": "datetest",
          "_id": "AUw0VIQbqFHXxhSON3r-",
          "_score": 0.095891505,
          "_source": {
            "content": "Hello World!",
            "postDate": "2009-11-15T14:12:12-07:00"
          }
        }
      ]
    }
  </code></pre>
  
  <p>You see that postDate is formatted in each of the documents returned exactly as it was POSTed. This is confusing to me though. According to, </p>
  
  <p><a href="http://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-core-types.html" rel="nofollow">http://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-core-types.html</a></p>
  
  <p>"The date type is a special type which maps to JSON string type. It
  follows a specific format that can be explicitly set. <strong>All dates are
  UTC. Internally, a date maps to a number type long, with the added
  parsing stage from string to long and from long to string.</strong>" (emphasis mine)</p>
  
  <p>My two questions are:</p>
  
  <p>1) Since, "internally, a date maps to a number type long", how or where is
     elasticsearch storing the meta-information on how the date was
     POSTed? </p>
  
  <p>2) Am I able to specify an <em>output-format</em> for dates,
     regardless of how they were POSTed. That is, can I control the "long
     to string" conversion independently of how the date was input?</p>