# Filtering on a mapped timestamp

**URL:** https://discuss.elastic.co/t/filtering-on-a-mapped-timestamp/28704
**Category:** Elasticsearch
**Created:** [September 4, 2015, 7:59pm UTC](https://discuss.elastic.co/t/filtering-on-a-mapped-timestamp/28704 "2015-09-04T19:59:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![edmondo1984](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edmondo1984/32/3517_2.png) [@edmondo1984](https://discuss.elastic.co/u/edmondo1984)
#### Post date: [September 4, 2015, 7:59pm UTC](https://discuss.elastic.co/t/filtering-on-a-mapped-timestamp/28704/1 "2015-09-04T19:59:14Z")

</div>

I have been moving from an auto-generated timestamp to a mapped one and query doesn’t work anymore. When using an auto-generated timestamp, I was able to perform this sort of query:

```
FilterBuilder filter = FilterBuilders.rangeFilter("_timestamp").from(zonedDateTime.toLocalDate().toString()).to(zonedDateTime.plusHours(1).toLocalDate().toString());

```

but also passing date expressions such as “now-1h” would work. Now that I have introduced the following mapping:

```
"collections": {
  "_timestamp": {
    "enabled": true,
    "path": "my_date",
    "ignore_missing": false
  },
  "properties": {
    "author": {
      "type": "string",
      "index": "not_analyzed"
    },
    "name": {
      "type": "string",
      "analyzer": "lowercase"
    },
    "my_date": {
      "type": "date"
    }
  }
}

```

And I store my\_date as a Unix EPOCH format, I can’t query anymore:

```
FilterBuilders.rangeFilter("_timestamp").from(zonedDateTime.toLocalDate().toString()).to(zonedDateTime.plusHours(1).toLocalDate().toString());

```

Return empty results, while the query

```
FilterBuilders.rangeFilter("my_date").from(zonedDateTime.toLocalDate().toString()).to(zonedDateTime.plusHours(1).toLocalDate().toString());

```

Fails with an exception

```
from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"match_all":{}},"filter":{"range":{"my_date":{"from":"2015-09-04T19:52:15.001+01:00","to":"2015-09-04T21:52:15.001+01:00","include_lower":true,"include_upper":true}}}}}}]]]; nested: NumberFormatException[For input string: "2015-09-04T19:52:15.001+01:00"];

```

It looks like the only query that I can do is by using the numeric values of the timestamp, on my\_date. Is there anything better I can hope for?

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [September 5, 2015, 2:55am UTC](https://discuss.elastic.co/t/filtering-on-a-mapped-timestamp/28704/2 "2015-09-05T02:55:36Z")

</div>

Already answered on SO. Invalid mapping. `my_date` is supposed to be in the `properties` section.

---

<div class="post-metadata">

### Author: ![edmondo1984](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edmondo1984/32/3517_2.png) [@edmondo1984](https://discuss.elastic.co/u/edmondo1984)
#### Post date: [September 5, 2015, 9:40am UTC](https://discuss.elastic.co/t/filtering-on-a-mapped-timestamp/28704/3 "2015-09-05T09:40:26Z")

</div>

Thanks, I have updated my question as in SO. The mappings in the posts were wrong because I copy/paste only a part of it, in reality they are correct (or I would not even be able to set them on the index)

---

<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:52pm UTC](https://discuss.elastic.co/t/filtering-on-a-mapped-timestamp/28704/4 "2017-07-05T23:52:00Z")

</div>


