Elasticsearch fix date field value. (change field value from int to string)
<p>I used python ship data from mongodb to elasticsearch.</p>

<p>There is a timestamp field named <code>update_time</code>, mapping like:</p>

<pre><code>    "update_time" : {
        "type": "date",
        "format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
    },
</code></pre>

<p><code>epoch_millis</code>  is used for timestamp.</p>

<p>After everything done, I used <code>range</code> to query doc in date range. But nothing return. After some researching, I thought the problem was: python timestamp <code>int(time.time())</code> is 10 digit, but it is 13 digit in elasticsearch , <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-timestamp-field.html" rel="nofollow">official example</a> :</p>

<blockquote>
  <p>PUT my_index/my_type/2?timestamp=1420070400000.</p>
</blockquote>

<p>so I tried to update the update_time field by multiple 1000:</p>

<pre><code>{
  "script": {
    "inline": "ctx._source.update_time=ctx._source.update_time*1000"
  }
}
</code></pre>

<p>Unfortunately, I found all <code>update_time</code> become minus. Then I come up with that Java int type is <code>pow(2,32) -1</code> , much lower than <code>1420070400000</code>. So I guess timestamp field should not be int ?</p>

<p>Then I want to update the field value from int to string(I don't want ot change field mapping type, I know change mapping type need reindex, but here only need change value )</p>

<p>But I can't figure out what script I can use, official script document not mention about this</p>

<p>I didn't know groovy was a lauguage and thought it only used for math method because ES doc only wrote about that.</p>

<p>The sulotion is simple, just convert int to long.</p>

<pre><code>curl -XPOST http://localhost:9200/my_index/_update_by_query -d '
{
  "script": {
    "inline": "ctx._source.update_time=(long)ctx._source.update_time*1000"
  }
}'
</code></pre>

python elasticsearch elasticsearch-query