# Trying to do a simple query filter

**URL:** <https://discuss.elastic.co/t/trying-to-do-a-simple-query-filter/170942>\
**Category:** Elasticsearch\
**Created:** [March 5, 2019, 3:36pm UTC](https://discuss.elastic.co/t/trying-to-do-a-simple-query-filter/170942 "2019-03-05T15:36:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cis4life](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@cis4life](https://discuss.elastic.co/u/cis4life)\
**Post date:** [March 5, 2019, 3:36pm UTC](https://discuss.elastic.co/t/trying-to-do-a-simple-query-filter/170942/1 "2019-03-05T15:36:32Z")

</div>

Good Day,

Maybe Im just over thinking this, but I just want to do a simple filter / query on a numberic number.

I have a document with a timestamp and hour (0-23) have the query of data I need, but I need to filter / query it where docHour is greater than 23 (11:00pm) and less than 04 (4:00am) but Its just not working. What is the best way to do this kind of query. Do I use multiple ranges ???

---

<div class="post-metadata">

**Author:** ![Ant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ant/32/33267_2.png) [@Ant](https://discuss.elastic.co/u/Ant)\
**Post date:** [March 5, 2019, 4:42pm UTC](https://discuss.elastic.co/t/trying-to-do-a-simple-query-filter/170942/2 "2019-03-05T16:42:11Z")

</div>

this works for me

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "range":{"timestamp" : {"gte": "2019-02-26 23:00:00", "lte": "2019-02-27 04:00:00"}}
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![cis4life](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@cis4life](https://discuss.elastic.co/u/cis4life)\
**Post date:** [March 5, 2019, 6:28pm UTC](https://discuss.elastic.co/t/trying-to-do-a-simple-query-filter/170942/3 "2019-03-05T18:28:46Z")

</div>

The problem with that query is that I only want where time is greater than 11:00pm and less that 4:00am. I only need those hours per day. So I can't use the date part cause it will then use the date as well.

I do have a field for hour which is an integer that is from 0 - 23. Thats why I want to use hour .

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 5, 2019, 6:34pm UTC](https://discuss.elastic.co/t/trying-to-do-a-simple-query-filter/170942/4 "2019-03-05T18:34:56Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![cis4life](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@cis4life](https://discuss.elastic.co/u/cis4life)\
**Post date:** [March 5, 2019, 6:44pm UTC](https://discuss.elastic.co/t/trying-to-do-a-simple-query-filter/170942/5 "2019-03-05T18:44:56Z")

</div>

```
GET tmc2018_feb/_search

```

{  
"query":  
{  
"bool": {  
"should": [  
{"match": { "dayOfWeek.keyword": "Tue"}},  
{"match": { "dayOfWeek.keyword": "Wed"}},  
{"match": { "dayOfWeek.keyword": "Thu"}}  
]  
}  
},  
"sort": [  
{  
"measurement\_timestamp": {  
"order": "asc"  
}  
}  
]  
}

Forgive me for my newbie status with this.

Basically what I'm trying to do it...  
1.) return records to me that are from Tue, Wed, or Thu. Now I also only want records that are from the hours of 11:00pm to 4:00am in the morning. I also have a DateTime field named ' measurement\_timestamp ' if that is better to use, but to seperate and filter against the times and day it was suggested I have those fields seperate (thus the hours and DayOfWeek fields).  
2.) sort asc

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 5, 2019, 7:07pm UTC](https://discuss.elastic.co/t/trying-to-do-a-simple-query-filter/170942/6 "2019-03-05T19:07:29Z")

</div>

I can't copy and paste to reproduce anything.  
Please follow my instructions if you need further assistance.

---

<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:** [April 2, 2019, 7:07pm UTC](https://discuss.elastic.co/t/trying-to-do-a-simple-query-filter/170942/7 "2019-04-02T19:07:29Z")

</div>

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