# Elastic Search is indexing date fields wrong (milliseconds instead of seconds)

**URL:** https://discuss.elastic.co/t/elastic-search-is-indexing-date-fields-wrong-milliseconds-instead-of-seconds/41764
**Category:** Elasticsearch
**Created:** [February 15, 2016, 10:49am UTC](https://discuss.elastic.co/t/elastic-search-is-indexing-date-fields-wrong-milliseconds-instead-of-seconds/41764 "2016-02-15T10:49:35Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![okozacz](https://avatars.discourse-cdn.com/v4/letter/o/ac8455/32.png) [@okozacz](https://discuss.elastic.co/u/okozacz)
#### Post date: [February 15, 2016, 10:49am UTC](https://discuss.elastic.co/t/elastic-search-is-indexing-date-fields-wrong-milliseconds-instead-of-seconds/41764/1 "2016-02-15T10:49:36Z")

</div>

Hey folks!

I have mapping defined as follows:

```
PUT test1
{
"settings": {
    "index.mapping.ignore_malformed":true

  },
  "mappings": {
    "supersonic": {

      "dynamic": "true",
      "properties": {
        "date": {
        "type": "date",
        "format": "epoch_second"
        },
        "timestamp": {
        "type": "date",
        "format": "epoch_second"
        },
        "other_date": {
        "type": "date",
        "format": "epoch_millis"
        }
    }
  }
}
}

```

Now, "other\_date" is indexed and shown perfectly fine. The problem ist, "date" and "timestamp" are treated as milliseconds as well, thus giving me dates in Jan 1970. The dates themselves arrive within a JSON. Am I missing something here?

Thanks for any help!

---

<div class="post-metadata">

### Author: ![abeyad](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@abeyad](https://discuss.elastic.co/u/abeyad)
#### Post date: [February 15, 2016, 6:24pm UTC](https://discuss.elastic.co/t/elastic-search-is-indexing-date-fields-wrong-milliseconds-instead-of-seconds/41764/2 "2016-02-15T18:24:03Z")

</div>

What Elasticsearch version are you using? And could you send the JSON of a document which you indexed which manifested this behavior?

---

<div class="post-metadata">

### Author: ![okozacz](https://avatars.discourse-cdn.com/v4/letter/o/ac8455/32.png) [@okozacz](https://discuss.elastic.co/u/okozacz)
#### Post date: [February 16, 2016, 5:31pm UTC](https://discuss.elastic.co/t/elastic-search-is-indexing-date-fields-wrong-milliseconds-instead-of-seconds/41764/3 "2016-02-16T17:31:03Z")

</div>

Yes. The version is 2.1.1.  
An example JSON would be:

```
> {"ipLongPeer":2130706433,
> "biomass_cost":110,
> "networkId":0,
> "ipLong":3561950994,
> "gameId":30,
> "instanceId":0,
> "tsEventAccepted":1450714430, 
> "trevor_date":1450714430731,
> "ipLongForwarded":3561950994,
> "date":1450714430,
> "production_type":3,
> "entity_elements":"GA_1_0_0_2_0",
> "version":"0.10.46",
> "timestamp":1450714429,
> "platform_id":-1,
> "eventId":945,
> "playerId":"mzaman",
> "queue_size":1,
> "entity_type":1100,
> "production_id":"2015.12.21.17.13.45.8556370.3696111"}

```

The mapping, when fetched after the first events arrived, is:  
\> \> {  
\> \> "test": {  
\> \> "mappings": {  
\> \> "supersonic": {  
\> \> "dynamic": "true",  
\> \> "properties": {  
\> \> "biomass\_cost": {  
\> \> "type": "double"  
\> \> },  
\> \> "date": {  
\> \> "type": "date",  
\> \> "format": "epoch\_second"  
\> \> },  
\> \> "entity\_elements": {  
\> \> "type": "string"  
\> \> },  
\> \> "entity\_type": {  
\> \> "type": "double"  
\> \> },  
\> \> "eventId": {  
\> \> "type": "double"  
\> \> },  
\> \> "gameId": {  
\> \> "type": "double"  
\> \> },  
\> \> "instanceId": {  
\> \> "type": "double"  
\> \> },  
\> \> "ipLong": {  
\> \> "type": "double"  
\> \> },  
\> \> "ipLongForwarded": {  
\> \> "type": "double"  
\> \> },  
\> \> "ipLongPeer": {  
\> \> "type": "double"  
\> \> },  
\> \> "networkId": {  
\> \> "type": "double"  
\> \> },  
\> \> "platform\_id": {  
\> \> "type": "double"  
\> \> },  
\> \> "playerId": {  
\> \> "type": "string"  
\> \> },  
\> \> "production\_id": {  
\> \> "type": "string"  
\> \> },  
\> \> "production\_type": {  
\> \> "type": "double"  
\> \> },  
\> \> "queue\_size": {  
\> \> "type": "double"  
\> \> },  
\> \> "timestamp": {  
\> \> "type": "date",  
\> \> "format": "epoch\_second"  
\> \> },  
\> \> "trevor\_date": {  
\> \> "type": "date",  
\> \> "format": "epoch\_millis"  
\> \> },  
\> \> "tsEventAccepted": {  
\> \> "type": "double"  
\> \> },  
\> \> "version": {  
\> \> "type": "string"  
\> \> }  
\> \> }  
\> \> }  
\> \> }  
\> \> }  
\> \> }

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [February 17, 2016, 4:50pm UTC](https://discuss.elastic.co/t/elastic-search-is-indexing-date-fields-wrong-milliseconds-instead-of-seconds/41764/4 "2016-02-17T16:50:22Z")

</div>

Tip from someone who's asked for help and provided it for years: format your json and wrap it in ``` and it'll be code formatted and folks are more likely to read it.

---

<div class="post-metadata">

### Author: ![okozacz](https://avatars.discourse-cdn.com/v4/letter/o/ac8455/32.png) [@okozacz](https://discuss.elastic.co/u/okozacz)
#### Post date: [February 18, 2016, 8:40am UTC](https://discuss.elastic.co/t/elastic-search-is-indexing-date-fields-wrong-milliseconds-instead-of-seconds/41764/5 "2016-02-18T08:40:03Z")

</div>

You're right, thanks for the hint 🙂

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [February 19, 2016, 5:21am UTC](https://discuss.elastic.co/t/elastic-search-is-indexing-date-fields-wrong-milliseconds-instead-of-seconds/41764/6 "2016-02-19T05:21:24Z")

</div>

I can't reproduce the issue:

```auto
curl -XDELETE localhost:9200/test1

curl -XPUT localhost:9200/test1 -d'{
  "settings": {
    "index.mapping.ignore_malformed":true

  },
  "mappings": {
    "supersonic": {

      "dynamic": "true",
      "properties": {
        "date": {
        "type": "date",
        "format": "epoch_second"
        },
        "timestamp": {
        "type": "date",
        "format": "epoch_second"
        },
        "other_date": {
        "type": "date",
        "format": "epoch_millis"
        }
    }
  }
}}'

curl -XPOST 'localhost:9200/test1/test/1?refresh&refresh' -d'{"ipLongPeer":2130706433,
    "biomass_cost":110,
    "networkId":0,
    "ipLong":3561950994,
    "gameId":30,
    "instanceId":0,
    "tsEventAccepted":1450714430, 
    "trevor_date":1450714430731,
    "ipLongForwarded":3561950994,
    "date":1450714430,
    "production_type":3,
    "entity_elements":"GA_1_0_0_2_0",
    "version":"0.10.46",
    "timestamp":1450714429,
    "platform_id":-1,
    "eventId":945,
    "playerId":"mzaman",
    "queue_size":1,
    "entity_type":1100,
    "production_id":"2015.12.21.17.13.45.8556370.3696111"}'

curl -XPOST localhost:9200/test1/test/_search?pretty -d'{
  "query": {
    "range": {
      "date": {
        "lt": "2000-1-1T00:00:00",
        "format": "date_optional_time"
      }
    }
  }
}'
# No results

curl -XPOST localhost:9200/test1/test/_search?pretty -d'{
  "query": {
    "range": {
      "date": {
        "gt": "2015-1-1T23:00:00",
        "lt": "2016-1-1T23:00:00",
        "format": "date_optional_time"
      }
    }
  }
}'
# One result

```

Sorry!

---

<div class="post-metadata">

### Author: ![okozacz](https://avatars.discourse-cdn.com/v4/letter/o/ac8455/32.png) [@okozacz](https://discuss.elastic.co/u/okozacz)
#### Post date: [February 25, 2016, 5:45pm UTC](https://discuss.elastic.co/t/elastic-search-is-indexing-date-fields-wrong-milliseconds-instead-of-seconds/41764/7 "2016-02-25T17:45:55Z")

</div>

The problem became obsolete b/c I changed the dynamic mapping so it would automatically assign any field that contains "data", "timestamp" etc to date, so for that I need to send every date field in a homogenous format, as milliseconds in my case. It is a mystery why Icouldn't make it work before though.  
But Thanks anyways, I appreciate the help 🙂

---

<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, 11:13pm UTC](https://discuss.elastic.co/t/elastic-search-is-indexing-date-fields-wrong-milliseconds-instead-of-seconds/41764/8 "2017-07-05T23:13:39Z")

</div>


