# How to search by time ranges (indexed field)

**URL:** https://discuss.elastic.co/t/how-to-search-by-time-ranges-indexed-field/62398
**Category:** Elasticsearch
**Created:** [October 6, 2016, 2:47pm UTC](https://discuss.elastic.co/t/how-to-search-by-time-ranges-indexed-field/62398 "2016-10-06T14:47:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ivy\_me](https://avatars.discourse-cdn.com/v4/letter/i/da6949/32.png) [@Ivy\_me](https://discuss.elastic.co/u/Ivy_me)
#### Post date: [October 6, 2016, 2:47pm UTC](https://discuss.elastic.co/t/how-to-search-by-time-ranges-indexed-field/62398/1 "2016-10-06T14:47:43Z")

</div>

Hi all,  
trying to understand how to perform search within specific timelines, I guess it's range querying but in this case the 'timestamps' are within my indexed field. I tried some queries like `"range" : { "ts" : { "gte" : "sometime", "lt" : "sometime" } }` and `.setQuery(QueryBuilders.rangeQuery("ts").from("sometime").to(sometime"))` but got no hits returned. It seems the dates are not understandable by search client.  
I read about mappings formats(date) but it seems it concerns only Types. What to do with the fields I get parsed from Logstash?  
Below is the screenshot from Elastic HQ, I need to select by specific time-frame from Ts field. I would appreciate any help or thoughts.

 ![](https://us1.discourse-cdn.com/elastic/original/2X/d/d786bc8a51992a6f645c5f7f85f362e42abf635c.png)

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [October 8, 2016, 9:26am UTC](https://discuss.elastic.co/t/how-to-search-by-time-ranges-indexed-field/62398/2 "2016-10-08T09:26:52Z")

</div>

What is the `ts` field mapped as?

---

<div class="post-metadata">

### Author: ![Ivy\_me](https://avatars.discourse-cdn.com/v4/letter/i/da6949/32.png) [@Ivy\_me](https://discuss.elastic.co/u/Ivy_me)
#### Post date: [October 8, 2016, 12:38pm UTC](https://discuss.elastic.co/t/how-to-search-by-time-ranges-indexed-field/62398/3 "2016-10-08T12:38:06Z")

</div>

String

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [October 8, 2016, 8:37pm UTC](https://discuss.elastic.co/t/how-to-search-by-time-ranges-indexed-field/62398/4 "2016-10-08T20:37:53Z")

</div>

> **[Range Query | Elasticsearch Guide \[2.4\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-range-query.html)**

> The type of the Lucene query depends on the field type, for string fields, the TermRangeQuery, while for number/date fields, the query is a NumericRangeQuery.

So start there, or map the field correctly.

---

<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:13pm UTC](https://discuss.elastic.co/t/how-to-search-by-time-ranges-indexed-field/62398/5 "2017-07-05T22:13:49Z")

</div>


