# Term query with range date

**URL:** <https://discuss.elastic.co/t/term-query-with-range-date/36156>\
**Category:** Elasticsearch\
**Created:** [December 2, 2015, 11:21am UTC](https://discuss.elastic.co/t/term-query-with-range-date/36156 "2015-12-02T11:21:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbalaguero](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@jbalaguero](https://discuss.elastic.co/u/jbalaguero)\
**Post date:** [December 2, 2015, 11:21am UTC](https://discuss.elastic.co/t/term-query-with-range-date/36156/1 "2015-12-02T11:21:30Z")

</div>

Hello,

I have to perform these query:

(creationTime \>= 1449054530286 AND creationTime \<= 1449054540286) **AND**  
(client\_code IN (‘CL1’,’CL2’) OR criterion\_code = ‘country’)

My Query DSL:

{  
"query" :  
{  
"bool" :  
{  
"filter": { "range" : { "creationTime": { "gte": 1449054530286, "lte": 1449054540286 } } },  
"should":  
[  
{ "terms" : { "client\_code" : ["CL1", "CL2"] } },  
{ "term" : { "criterion\_code" : "country1" } }  
]  
}  
}  
}

But this seems to perform this query:

(creationTime \>= 1449054530286 AND creationTime \<= 1449054540286) **OR**  
(client\_code IN (‘CL1’,’CL2’) OR criterion\_code = ‘country’)

How can I do this?

Thanks.

---

<div class="post-metadata">

**Author:** ![thiagolocatelli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiagolocatelli/32/6424_2.png) [@thiagolocatelli](https://discuss.elastic.co/u/thiagolocatelli)\
**Post date:** [December 2, 2015, 7:35pm UTC](https://discuss.elastic.co/t/term-query-with-range-date/36156/2 "2015-12-02T19:35:48Z")

</div>

Try this:

```
{
  "query":{
    "filtered":{
        "filter":{
            "bool":{
                "must":[
                    {
                        "range":{
                            "creationTime":{
                                "gte":1449054530286,
                                "lte":1449054540286
                            }
                        }
                    },
                    {
                        "bool":{
                            "should":[
                                {
                                    "term":{
                                        "criterion_code":"country1"
                                    }
                                },
                                {
                                    "terms":{
                                        "client_code":[
                                            "CL1",
                                            "CL2"
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    }
  }
}

```

Next time try to format your query so its easier to understand what you are trying to run against elasticsearch.

---

<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:34pm UTC](https://discuss.elastic.co/t/term-query-with-range-date/36156/3 "2017-07-05T23:34:06Z")

</div>


