# How to fix date field value(change field value from int to string)

**URL:** https://discuss.elastic.co/t/how-to-fix-date-field-value-change-field-value-from-int-to-string/60028
**Category:** Elasticsearch
**Created:** [September 8, 2016, 1:31am UTC](https://discuss.elastic.co/t/how-to-fix-date-field-value-change-field-value-from-int-to-string/60028 "2016-09-08T01:31:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mithril](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mithril](https://discuss.elastic.co/u/mithril)
#### Post date: [September 8, 2016, 1:31am UTC](https://discuss.elastic.co/t/how-to-fix-date-field-value-change-field-value-from-int-to-string/60028/1 "2016-09-08T01:31:49Z")

</div>

I used python ship data from mongodb to elasticsearch.

There is a timestamp field mapping:

```
        "update_time" : {
            "type": "date",
            "format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        },

```

`epoch_millis` is used for timestamp.

After everything done, I used `range` to query doc in date range. But nothing return. After some researching, I thought the problem was: python timestamp `int(time.time())` is 10 digit, but it is 13 digit in elasticsearch , [official example](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-timestamp-field.html) :

> PUT my\_index/my\_type/2?timestamp=1420070400000.

so I tried to update the update\_time field by multiple 1000:

```
    {
      "script": {
        "inline": "ctx._source.update_time=ctx._source.update_time*1000"
      }
    }

```

Unfortunately, I found all `update_time` become minus. Then I come up with that Java int type is `pow(2,32) -1` , much lower than `1420070400000`. I guess timestamp field should not be int ? If it is, the document should add this tip.

So 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 )

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

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [September 9, 2016, 11:00am UTC](https://discuss.elastic.co/t/how-to-fix-date-field-value-change-field-value-from-int-to-string/60028/2 "2016-09-09T11:00:09Z")

</div>

Hey,

date fields are longs internally. What might have happened is, that your script is actually producing integers instead of long values... possibilities to fix here

1. You could try `ctx._source.update_time=ctx._source.update_time*1000 as Long` and see if it works (havent tested it)
2. You could use the `epoch_second` in your mapping configuration, see [https://www.elastic.co/guide/en/elasticsearch/reference/2.4/mapping-date-format.html#custom-date-formats](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/mapping-date-format.html#custom-date-formats)
3. You could use a human readable date in ISO8601 format when indexing and not have any stress about conversion

--Alex

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 10:21pm UTC](https://discuss.elastic.co/t/how-to-fix-date-field-value-change-field-value-from-int-to-string/60028/3 "2017-07-05T22:21:38Z")

</div>


