# Time range query on date field

**URL:** <https://discuss.elastic.co/t/time-range-query-on-date-field/102605>\
**Category:** Elasticsearch\
**Created:** [October 3, 2017, 7:39pm UTC](https://discuss.elastic.co/t/time-range-query-on-date-field/102605 "2017-10-03T19:39:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikas\_Mestry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_mestry/32/42301_2.png) [@Vikas\_Mestry](https://discuss.elastic.co/u/Vikas_Mestry)\
**Post date:** [October 3, 2017, 7:39pm UTC](https://discuss.elastic.co/t/time-range-query-on-date-field/102605/1 "2017-10-03T19:39:29Z")

</div>

Hello,

Is there a way to filter a date field (epoch\_mills) with time range without specifying the date e.g.

I have a field "cpuusagetime" with value as 1483283988368, i would like to get all the documents which are within the time range of 8:00 AM to 9:00 AM without specifying the date (MM-dd-yyyy)

Alternatively i have split the date field into separate fields viz hour, min but I am unable to apply a bool range filter on different fields e.g.

```
"_source": {
		"cpuusagetime": 1483283988368,
		"seconds": 48,
		"min": 49,
		"month": 1,
		"hour": 8,
		"cpu_percentage": 37,
		"year": 2017,
		"machine": "user1",
		"day": 1,
		"user": "machine1"
	},

"_source": {
		"cpuusagetime": 1483286028368,
		"seconds": 48,
		"min": 23,
		"month": 1,
		"hour": 9,
		"cpu_percentage": 67,
		"year": 2017,
		"machine": "user1",
		"day": 1,
		"user": "machine1"
	}

```

Below is the query i am attempting

```
"query": {
		"bool": {
			"must": [{
					"range": {
						"hour": {
							"gte": "8",
							"lte": "9"
						}
					}
				}, {
					"range": {
						"min": {
							"gte": "20",
							"lte": "40"
						}
					}
				}
			]
		}
	}
```

---

<div class="post-metadata">

**Author:** ![Vikas\_Mestry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_mestry/32/42301_2.png) [@Vikas\_Mestry](https://discuss.elastic.co/u/Vikas_Mestry)\
**Post date:** [October 6, 2017, 3:52am UTC](https://discuss.elastic.co/t/time-range-query-on-date-field/102605/2 "2017-10-06T03:52:26Z")

</div>

any suggestions please

---

<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:** [November 3, 2017, 3:52am UTC](https://discuss.elastic.co/t/time-range-query-on-date-field/102605/3 "2017-11-03T03:52:45Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
