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

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 :

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

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
  3. You could use a human readable date in ISO8601 format when indexing and not have any stress about conversion

--Alex