Term query with range date

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.

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.