# Mixing Filters

**URL:** <https://discuss.elastic.co/t/mixing-filters/21240>\
**Category:** Elasticsearch\
**Created:** [December 12, 2014, 8:04pm UTC](https://discuss.elastic.co/t/mixing-filters/21240 "2014-12-12T20:04:44Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkamiche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkamiche/32/14559_2.png) [@bkamiche](https://discuss.elastic.co/u/bkamiche)\
**Post date:** [December 12, 2014, 8:04pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/1 "2014-12-12T20:04:44Z")

</div>

Hello, I'm testing elastic search and I need to apply different filters,  
when I include the "range" filter I get an error and the query is not  
executed, here's the json:

$json = '{  
"size" : 10,  
"from" : 0,  
"sort" : [  
{ "\_timestamp" : { "order" : "desc" } },  
{ "\_score" : { "order" : "desc" } }  
],  
"query" : {  
"filtered" : {  
"query" : {  
"query\_string" : {  
"fields" : ["mytextfield"],  
"query" : "my query string",  
"default\_operator" : "AND"  
}  
},  
"filter" : {  
"range" : {  
"datefields" : {  
"gte" : "1325394000",  
"lte" : "1356930000"  
}  
},  
"bool" : {  
"must" : [  
{  
"term" : {  
"aq\_industryid" : 1 }  
},  
{  
"term" : {  
"aq\_clientid" : 1 }  
},  
{  
"term" : { "ntipo"  
: [5] }  
}  
]  
}  
}  
}

```
    }

```

}';

If I don't include the "range" filter, everything works fine (filtering by  
the other fields, number of results, order, etc), what am I doing wrong?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [December 12, 2014, 8:05pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/2 "2014-12-12T20:05:38Z")

</div>

What is the error?

David

> Le 12 déc. 2014 à 21:04, Bruno Kamiche [bkamiche@gmail.com](mailto:bkamiche@gmail.com) a écrit :
> 
> Hello, I'm testing Elasticsearch and I need to apply different filters, when I include the "range" filter I get an error and the query is not executed, here's the json:
> 
> $json = '{  
> "size" : 10,  
> "from" : 0,  
> "sort" : [  
> { "\_timestamp" : { "order" : "desc" } },  
> { "\_score" : { "order" : "desc" } }  
> ],  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "query\_string" : {  
> "fields" : ["mytextfield"],  
> "query" : "my query string",  
> "default\_operator" : "AND"  
> }  
> },  
> "filter" : {  
> "range" : {  
> "datefields" : {  
> "gte" : "1325394000",  
> "lte" : "1356930000"  
> }  
> },  
> "bool" : {  
> "must" : [  
> {  
> "term" : { "aq\_industryid" : 1 }  
> },  
> {  
> "term" : { "aq\_clientid" : 1 }  
> },  
> {  
> "term" : { "ntipo" : [5] }  
> }  
> ]  
> }  
> }  
> }
> 
> ```
> }
> 
> ```
> 
> }';
> 
> If I don't include the "range" filter, everything works fine (filtering by the other fields, number of results, order, etc), what am I doing wrong?
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1E9AF9D7-6495-44F9-A77B-D96D6BC74A95%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/1E9AF9D7-6495-44F9-A77B-D96D6BC74A95%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [December 12, 2014, 8:06pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/3 "2014-12-12T20:06:39Z")

</div>

Oh I see. Filter accepts only one filter. You should put your range inside the Must array.

David

> Le 12 déc. 2014 à 21:04, Bruno Kamiche [bkamiche@gmail.com](mailto:bkamiche@gmail.com) a écrit :
> 
> Hello, I'm testing Elasticsearch and I need to apply different filters, when I include the "range" filter I get an error and the query is not executed, here's the json:
> 
> $json = '{  
> "size" : 10,  
> "from" : 0,  
> "sort" : [  
> { "\_timestamp" : { "order" : "desc" } },  
> { "\_score" : { "order" : "desc" } }  
> ],  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "query\_string" : {  
> "fields" : ["mytextfield"],  
> "query" : "my query string",  
> "default\_operator" : "AND"  
> }  
> },  
> "filter" : {  
> "range" : {  
> "datefields" : {  
> "gte" : "1325394000",  
> "lte" : "1356930000"  
> }  
> },  
> "bool" : {  
> "must" : [  
> {  
> "term" : { "aq\_industryid" : 1 }  
> },  
> {  
> "term" : { "aq\_clientid" : 1 }  
> },  
> {  
> "term" : { "ntipo" : [5] }  
> }  
> ]  
> }  
> }  
> }
> 
> ```
> }
> 
> ```
> 
> }';
> 
> If I don't include the "range" filter, everything works fine (filtering by the other fields, number of results, order, etc), what am I doing wrong?
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3FCCAC5F-8D32-414A-9901-850267973ED6%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/3FCCAC5F-8D32-414A-9901-850267973ED6%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bkamiche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkamiche/32/14559_2.png) [@bkamiche](https://discuss.elastic.co/u/bkamiche)\
**Post date:** [December 12, 2014, 8:08pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/4 "2014-12-12T20:08:51Z")

</div>

I changed the filter to this:

```
                    "filter" : {
                            "bool" : {
                                    "must" : [
                                            "range" : {
                                                    "fecha" : {
                                                            "gte" : 

```

"1325394000",  
"lte" :  
"1356930000"  
}  
},  
{  
"term" : {  
"aq\_industryid" : 1 }  
},  
{  
"term" : {  
"aq\_clientid" : 1 }  
},  
{  
"term" : { "ntipo"  
: [5] }  
}  
]  
}  
}

But it keeps the error:

PHP Fatal error: Uncaught exception  
'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client  
error response  
[status code] 400  
[reason phrase] Bad Request  
[url] [http://localhost:9200/quantico\_index/quantico\_type/\_search](http://localhost:9200/quantico_index/quantico_type/_search)' in  
/root/vendor/guzzle/http/Guzzle/Http/Exception/BadResponseException.php:43  
Stack trace:  
#0 /root/vendor/guzzle/http/Guzzle/Http/Message/Request.php(145):  
Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest),  
Object(Guzzle\Http\Message\Response))  
#1 [internal function]:  
Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event),  
'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))  
#2  
/root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164):  
call\_user\_func(Array, Object(Guzzle\Common\Event), 'request.error',  
Object(Symfony\Component\EventDispatcher\EventDispatcher))  
#3  
/root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(53):  
Symf in  
/root/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/GuzzleConnection.php  
on line 266

On Friday, December 12, 2014 3:06:47 PM UTC-5, David Pilato wrote:

> Oh I see. Filter accepts only one filter. You should put your range inside  
> the Must array.
> 
> David
> 
> Le 12 déc. 2014 à 21:04, Bruno Kamiche \<[bkam...@gmail.com](mailto:bkam...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hello, I'm testing Elasticsearch and I need to apply different filters,  
> when I include the "range" filter I get an error and the query is not  
> executed, here's the json:
> 
> $json = '{  
> "size" : 10,  
> "from" : 0,  
> "sort" : [  
> { "\_timestamp" : { "order" : "desc" } },  
> { "\_score" : { "order" : "desc" } }  
> ],  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "query\_string" : {  
> "fields" : ["mytextfield"],  
> "query" : "my query string",  
> "default\_operator" : "AND"  
> }  
> },  
> "filter" : {  
> "range" : {  
> "datefields" : {  
> "gte" : "1325394000",  
> "lte" : "1356930000"  
> }  
> },  
> "bool" : {  
> "must" : [  
> {  
> "term" : {  
> "aq\_industryid" : 1 }  
> },  
> {  
> "term" : {  
> "aq\_clientid" : 1 }  
> },  
> {  
> "term" : { "ntipo"  
> : [5] }  
> }  
> ]  
> }  
> }  
> }
> 
> ```
> }
> 
> ```
> 
> }';
> 
> If I don't include the "range" filter, everything works fine (filtering by  
> the other fields, number of results, order, etc), what am I doing wrong?
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/915649e8-57b3-4315-90c6-bba820665c00%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/915649e8-57b3-4315-90c6-bba820665c00%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bkamiche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkamiche/32/14559_2.png) [@bkamiche](https://discuss.elastic.co/u/bkamiche)\
**Post date:** [December 12, 2014, 8:15pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/5 "2014-12-12T20:15:20Z")

</div>

I think I figured it out, I needed an extra set of curly braces

```
                    "filter" : {
                            "bool" : {
                                    "must" : [
                                            {
                                                    "range" : {
                                                            "fecha" : {

```

"gte" : 1325394000,

"lte" : 1356930000  
}  
}  
},  
{  
"term" : {  
"aq\_industryid" : 1 }  
},  
{  
"term" : {  
"aq\_clientid" : 1 }  
},  
{  
"term" : { "ntipo"  
: [5] }  
}  
]  
}  
}

Now the query runs, but it does not yield the expected results, maybe you  
can help me with this

When I index the data, the field "fecha" is declared as a date field, with  
format "YYYY-mm-dd HH:mm:ss", when I query Elasticsearch I see the correct  
dates in the retrieved information, now I need to filter upon this data  
with a range of dates, how shall I express the range values, as text or as  
a unixtime ?

I've tried both and although theres data that should comply elastic does  
not return records.

On Friday, December 12, 2014 3:08:51 PM UTC-5, Bruno Kamiche wrote:

> I changed the filter to this:
> 
> ```
> "filter" : {
> "bool" : {
> "must" : [
> "range" : {
> "fecha" : {
> "gte" : 
> 
> ```
> 
> "1325394000",  
> "lte" :  
> "1356930000"  
> }  
> },  
> {  
> "term" : {  
> "aq\_industryid" : 1 }  
> },  
> {  
> "term" : {  
> "aq\_clientid" : 1 }  
> },  
> {  
> "term" : { "ntipo"  
> : [5] }  
> }  
> ]  
> }  
> }
> 
> But it keeps the error:
> 
> PHP Fatal error: Uncaught exception  
> 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client  
> error response  
> [status code] 400  
> [reason phrase] Bad Request  
> [url] [http://localhost:9200/quantico\_index/quantico\_type/\_search](http://localhost:9200/quantico_index/quantico_type/_search)' in  
> /root/vendor/guzzle/http/Guzzle/Http/Exception/BadResponseException.php:43  
> Stack trace:  
> #0 /root/vendor/guzzle/http/Guzzle/Http/Message/Request.php(145):  
> Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest),  
> Object(Guzzle\Http\Message\Response))  
> #1 [internal function]:  
> Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event),  
> 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> #2  
> /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164):  
> call\_user\_func(Array, Object(Guzzle\Common\Event), 'request.error',  
> Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> #3  
> /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(53):  
> Symf in  
> /root/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/GuzzleConnection.php  
> on line 266
> 
> On Friday, December 12, 2014 3:06:47 PM UTC-5, David Pilato wrote:
> 
> > Oh I see. Filter accepts only one filter. You should put your range  
> > inside the Must array.
> > 
> > David
> > 
> > Le 12 déc. 2014 à 21:04, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > 
> > Hello, I'm testing Elasticsearch and I need to apply different filters,  
> > when I include the "range" filter I get an error and the query is not  
> > executed, here's the json:
> > 
> > $json = '{  
> > "size" : 10,  
> > "from" : 0,  
> > "sort" : [  
> > { "\_timestamp" : { "order" : "desc" } },  
> > { "\_score" : { "order" : "desc" } }  
> > ],  
> > "query" : {  
> > "filtered" : {  
> > "query" : {  
> > "query\_string" : {  
> > "fields" : ["mytextfield"],  
> > "query" : "my query string",  
> > "default\_operator" : "AND"  
> > }  
> > },  
> > "filter" : {  
> > "range" : {  
> > "datefields" : {  
> > "gte" : "1325394000",  
> > "lte" : "1356930000"  
> > }  
> > },  
> > "bool" : {  
> > "must" : [  
> > {  
> > "term" : {  
> > "aq\_industryid" : 1 }  
> > },  
> > {  
> > "term" : {  
> > "aq\_clientid" : 1 }  
> > },  
> > {  
> > "term" : {  
> > "ntipo" : [5] }  
> > }  
> > ]  
> > }  
> > }  
> > }
> > 
> > ```
> > }
> > 
> > ```
> > 
> > }';
> > 
> > If I don't include the "range" filter, everything works fine (filtering  
> > by the other fields, number of results, order, etc), what am I doing wrong?
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [December 12, 2014, 8:32pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/6 "2014-12-12T20:32:50Z")

</div>

Text should be fine. But are you sure you defined the field as date in mapping?  
With the right format?

David

> Le 12 déc. 2014 à 21:15, Bruno Kamiche [bkamiche@gmail.com](mailto:bkamiche@gmail.com) a écrit :
> 
> I think I figured it out, I needed an extra set of curly braces
> 
> ```
> "filter" : {
> "bool" : {
> "must" : [
> {
> "range" : {
> "fecha" : {
> "gte" : 1325394000,
> "lte" : 1356930000
> }
> }
> },
> {
> "term" : { "aq_industryid" : 1 }
> },
> {
> "term" : { "aq_clientid" : 1 }
> },
> {
> "term" : { "ntipo" : [5] }
> }
> ]
> }
> }
> 
> ```
> 
> Now the query runs, but it does not yield the expected results, maybe you can help me with this
> 
> When I index the data, the field "fecha" is declared as a date field, with format "YYYY-mm-dd HH:mm:ss", when I query Elasticsearch I see the correct dates in the retrieved information, now I need to filter upon this data with a range of dates, how shall I express the range values, as text or as a unixtime ?
> 
> I've tried both and although theres data that should comply elastic does not return records.
> 
> > On Friday, December 12, 2014 3:08:51 PM UTC-5, Bruno Kamiche wrote:  
> > I changed the filter to this:
> > 
> > ```
> > "filter" : {
> > "bool" : {
> > "must" : [
> > "range" : {
> > "fecha" : {
> > "gte" : "1325394000",
> > "lte" : "1356930000"
> > }
> > },
> > {
> > "term" : { "aq_industryid" : 1 }
> > },
> > {
> > "term" : { "aq_clientid" : 1 }
> > },
> > {
> > "term" : { "ntipo" : [5] }
> > }
> > ]
> > }
> > }
> > 
> > ```
> > 
> > But it keeps the error:
> > 
> > PHP Fatal error: Uncaught exception 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client error response  
> > [status code] 400  
> > [reason phrase] Bad Request  
> > [url] [http://localhost:9200/quantico\_index/quantico\_type/\_search](http://localhost:9200/quantico_index/quantico_type/_search)' in /root/vendor/guzzle/http/Guzzle/Http/Exception/BadResponseException.php:43  
> > Stack trace:  
> > #0 /root/vendor/guzzle/http/Guzzle/Http/Message/Request.php(145): Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Message\Response))  
> > #1 [internal function]: Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> > #2 /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164): call\_user\_func(Array, Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> > #3 /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(53): Symf in /root/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/GuzzleConnection.php on line 266
> > 
> > > On Friday, December 12, 2014 3:06:47 PM UTC-5, David Pilato wrote:  
> > > Oh I see. Filter accepts only one filter. You should put your range inside the Must array.
> > > 
> > > David
> > > 
> > > > Le 12 déc. 2014 à 21:04, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > > > 
> > > > Hello, I'm testing Elasticsearch and I need to apply different filters, when I include the "range" filter I get an error and the query is not executed, here's the json:
> > > > 
> > > > $json = '{  
> > > > "size" : 10,  
> > > > "from" : 0,  
> > > > "sort" : [  
> > > > { "\_timestamp" : { "order" : "desc" } },  
> > > > { "\_score" : { "order" : "desc" } }  
> > > > ],  
> > > > "query" : {  
> > > > "filtered" : {  
> > > > "query" : {  
> > > > "query\_string" : {  
> > > > "fields" : ["mytextfield"],  
> > > > "query" : "my query string",  
> > > > "default\_operator" : "AND"  
> > > > }  
> > > > },  
> > > > "filter" : {  
> > > > "range" : {  
> > > > "datefields" : {  
> > > > "gte" : "1325394000",  
> > > > "lte" : "1356930000"  
> > > > }  
> > > > },  
> > > > "bool" : {  
> > > > "must" : [  
> > > > {  
> > > > "term" : { "aq\_industryid" : 1 }  
> > > > },  
> > > > {  
> > > > "term" : { "aq\_clientid" : 1 }  
> > > > },  
> > > > {  
> > > > "term" : { "ntipo" : [5] }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > ```
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > }';
> > > > 
> > > > If I don't include the "range" filter, everything works fine (filtering by the other fields, number of results, order, etc), what am I doing wrong?
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/30F77D58-3144-45CC-8540-471DE55BC716%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/30F77D58-3144-45CC-8540-471DE55BC716%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bkamiche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkamiche/32/14559_2.png) [@bkamiche](https://discuss.elastic.co/u/bkamiche)\
**Post date:** [December 12, 2014, 8:35pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/7 "2014-12-12T20:35:23Z")

</div>

This is my mapping

```
                'fecha' => [
                    'type' => 'date',
                    'format' => 'YYYY-mm-dd HH:mm:ss'
                ]

```

On Friday, December 12, 2014 3:33:22 PM UTC-5, David Pilato wrote:

> Text should be fine. But are you sure you defined the field as date in  
> mapping?  
> With the right format?
> 
> David
> 
> Le 12 déc. 2014 à 21:15, Bruno Kamiche \<[bkam...@gmail.com](mailto:bkam...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> I think I figured it out, I needed an extra set of curly braces
> 
> ```
> "filter" : {
> "bool" : {
> "must" : [
> {
> "range" : {
> "fecha" : {
> 
> ```
> 
> "gte" : 1325394000,
> 
> "lte" : 1356930000  
> }  
> }  
> },  
> {  
> "term" : {  
> "aq\_industryid" : 1 }  
> },  
> {  
> "term" : {  
> "aq\_clientid" : 1 }  
> },  
> {  
> "term" : { "ntipo"  
> : [5] }  
> }  
> ]  
> }  
> }
> 
> Now the query runs, but it does not yield the expected results, maybe you  
> can help me with this
> 
> When I index the data, the field "fecha" is declared as a date field, with  
> format "YYYY-mm-dd HH:mm:ss", when I query Elasticsearch I see the correct  
> dates in the retrieved information, now I need to filter upon this data  
> with a range of dates, how shall I express the range values, as text or as  
> a unixtime ?
> 
> I've tried both and although theres data that should comply elastic does  
> not return records.
> 
> On Friday, December 12, 2014 3:08:51 PM UTC-5, Bruno Kamiche wrote:
> 
> > I changed the filter to this:
> > 
> > ```
> > "filter" : {
> > "bool" : {
> > "must" : [
> > "range" : {
> > "fecha" : {
> > "gte" : 
> > 
> > ```
> > 
> > "1325394000",  
> > "lte" :  
> > "1356930000"  
> > }  
> > },  
> > {  
> > "term" : {  
> > "aq\_industryid" : 1 }  
> > },  
> > {  
> > "term" : {  
> > "aq\_clientid" : 1 }  
> > },  
> > {  
> > "term" : {  
> > "ntipo" : [5] }  
> > }  
> > ]  
> > }  
> > }
> > 
> > But it keeps the error:
> > 
> > PHP Fatal error: Uncaught exception  
> > 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client  
> > error response  
> > [status code] 400  
> > [reason phrase] Bad Request  
> > [url] [http://localhost:9200/quantico\_index/quantico\_type/\_search](http://localhost:9200/quantico_index/quantico_type/_search)' in  
> > /root/vendor/guzzle/http/Guzzle/Http/Exception/BadResponseException.php:43  
> > Stack trace:  
> > #0 /root/vendor/guzzle/http/Guzzle/Http/Message/Request.php(145):  
> > Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest),  
> > Object(Guzzle\Http\Message\Response))  
> > #1 [internal function]:  
> > Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event),  
> > 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> > #2  
> > /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164):  
> > call\_user\_func(Array, Object(Guzzle\Common\Event), 'request.error',  
> > Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> > #3  
> > /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(53):  
> > Symf in  
> > /root/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/GuzzleConnection.php  
> > on line 266
> > 
> > On Friday, December 12, 2014 3:06:47 PM UTC-5, David Pilato wrote:
> > 
> > > Oh I see. Filter accepts only one filter. You should put your range  
> > > inside the Must array.
> > > 
> > > David
> > > 
> > > Le 12 déc. 2014 à 21:04, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > > 
> > > Hello, I'm testing Elasticsearch and I need to apply different filters,  
> > > when I include the "range" filter I get an error and the query is not  
> > > executed, here's the json:
> > > 
> > > $json = '{  
> > > "size" : 10,  
> > > "from" : 0,  
> > > "sort" : [  
> > > { "\_timestamp" : { "order" : "desc" } },  
> > > { "\_score" : { "order" : "desc" } }  
> > > ],  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : {  
> > > "query\_string" : {  
> > > "fields" : ["mytextfield"],  
> > > "query" : "my query string",  
> > > "default\_operator" : "AND"  
> > > }  
> > > },  
> > > "filter" : {  
> > > "range" : {  
> > > "datefields" : {  
> > > "gte" : "1325394000",  
> > > "lte" : "1356930000"  
> > > }  
> > > },  
> > > "bool" : {  
> > > "must" : [  
> > > {  
> > > "term" : {  
> > > "aq\_industryid" : 1 }  
> > > },  
> > > {  
> > > "term" : {  
> > > "aq\_clientid" : 1 }  
> > > },  
> > > {  
> > > "term" : {  
> > > "ntipo" : [5] }  
> > > }  
> > > ]  
> > > }  
> > > }  
> > > }
> > > 
> > > ```
> > > }
> > > 
> > > ```
> > > 
> > > }';
> > > 
> > > If I don't include the "range" filter, everything works fine (filtering  
> > > by the other fields, number of results, order, etc), what am I doing wrong?
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/87b1d3a8-a7a6-4b84-9928-bbcd6e4094e8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/87b1d3a8-a7a6-4b84-9928-bbcd6e4094e8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [December 12, 2014, 8:36pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/8 "2014-12-12T20:36:22Z")

</div>

So a date with this format should work.

David

> Le 12 déc. 2014 à 21:35, Bruno Kamiche [bkamiche@gmail.com](mailto:bkamiche@gmail.com) a écrit :
> 
> This is my mapping
> 
> ```
> 'fecha' => [
> 'type' => 'date',
> 'format' => 'YYYY-mm-dd HH:mm:ss'
> ]
> 
> ```
> 
> > On Friday, December 12, 2014 3:33:22 PM UTC-5, David Pilato wrote:  
> > Text should be fine. But are you sure you defined the field as date in mapping?  
> > With the right format?
> > 
> > David
> > 
> > > Le 12 déc. 2014 à 21:15, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > > 
> > > I think I figured it out, I needed an extra set of curly braces
> > > 
> > > ```
> > > "filter" : {
> > > "bool" : {
> > > "must" : [
> > > {
> > > "range" : {
> > > "fecha" : {
> > > "gte" : 1325394000,
> > > "lte" : 1356930000
> > > }
> > > }
> > > },
> > > {
> > > "term" : { "aq_industryid" : 1 }
> > > },
> > > {
> > > "term" : { "aq_clientid" : 1 }
> > > },
> > > {
> > > "term" : { "ntipo" : [5] }
> > > }
> > > ]
> > > }
> > > }
> > > 
> > > ```
> > > 
> > > Now the query runs, but it does not yield the expected results, maybe you can help me with this
> > > 
> > > When I index the data, the field "fecha" is declared as a date field, with format "YYYY-mm-dd HH:mm:ss", when I query Elasticsearch I see the correct dates in the retrieved information, now I need to filter upon this data with a range of dates, how shall I express the range values, as text or as a unixtime ?
> > > 
> > > I've tried both and although theres data that should comply elastic does not return records.
> > > 
> > > > On Friday, December 12, 2014 3:08:51 PM UTC-5, Bruno Kamiche wrote:  
> > > > I changed the filter to this:
> > > > 
> > > > ```
> > > > "filter" : {
> > > > "bool" : {
> > > > "must" : [
> > > > "range" : {
> > > > "fecha" : {
> > > > "gte" : "1325394000",
> > > > "lte" : "1356930000"
> > > > }
> > > > },
> > > > {
> > > > "term" : { "aq_industryid" : 1 }
> > > > },
> > > > {
> > > > "term" : { "aq_clientid" : 1 }
> > > > },
> > > > {
> > > > "term" : { "ntipo" : [5] }
> > > > }
> > > > ]
> > > > }
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > But it keeps the error:
> > > > 
> > > > PHP Fatal error: Uncaught exception 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client error response  
> > > > [status code] 400  
> > > > [reason phrase] Bad Request  
> > > > [url] [http://localhost:9200/quantico\_index/quantico\_type/\_search](http://localhost:9200/quantico_index/quantico_type/_search)' in /root/vendor/guzzle/http/Guzzle/Http/Exception/BadResponseException.php:43  
> > > > Stack trace:  
> > > > #0 /root/vendor/guzzle/http/Guzzle/Http/Message/Request.php(145): Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Message\Response))  
> > > > #1 [internal function]: Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> > > > #2 /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164): call\_user\_func(Array, Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> > > > #3 /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(53): Symf in /root/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/GuzzleConnection.php on line 266
> > > > 
> > > > > On Friday, December 12, 2014 3:06:47 PM UTC-5, David Pilato wrote:  
> > > > > Oh I see. Filter accepts only one filter. You should put your range inside the Must array.
> > > > > 
> > > > > David
> > > > > 
> > > > > > Le 12 déc. 2014 à 21:04, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > > > > > 
> > > > > > Hello, I'm testing Elasticsearch and I need to apply different filters, when I include the "range" filter I get an error and the query is not executed, here's the json:
> > > > > > 
> > > > > > $json = '{  
> > > > > > "size" : 10,  
> > > > > > "from" : 0,  
> > > > > > "sort" : [  
> > > > > > { "\_timestamp" : { "order" : "desc" } },  
> > > > > > { "\_score" : { "order" : "desc" } }  
> > > > > > ],  
> > > > > > "query" : {  
> > > > > > "filtered" : {  
> > > > > > "query" : {  
> > > > > > "query\_string" : {  
> > > > > > "fields" : ["mytextfield"],  
> > > > > > "query" : "my query string",  
> > > > > > "default\_operator" : "AND"  
> > > > > > }  
> > > > > > },  
> > > > > > "filter" : {  
> > > > > > "range" : {  
> > > > > > "datefields" : {  
> > > > > > "gte" : "1325394000",  
> > > > > > "lte" : "1356930000"  
> > > > > > }  
> > > > > > },  
> > > > > > "bool" : {  
> > > > > > "must" : [  
> > > > > > {  
> > > > > > "term" : { "aq\_industryid" : 1 }  
> > > > > > },  
> > > > > > {  
> > > > > > "term" : { "aq\_clientid" : 1 }  
> > > > > > },  
> > > > > > {  
> > > > > > "term" : { "ntipo" : [5] }  
> > > > > > }  
> > > > > > ]  
> > > > > > }  
> > > > > > }  
> > > > > > }
> > > > > > 
> > > > > > ```
> > > > > > }
> > > > > > 
> > > > > > ```
> > > > > > 
> > > > > > }';
> > > > > > 
> > > > > > If I don't include the "range" filter, everything works fine (filtering by the other fields, number of results, order, etc), what am I doing wrong?
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com).  
> > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/87b1d3a8-a7a6-4b84-9928-bbcd6e4094e8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/87b1d3a8-a7a6-4b84-9928-bbcd6e4094e8%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8B7CFD52-8EDF-4D77-BF57-2BFEEA4DC212%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/8B7CFD52-8EDF-4D77-BF57-2BFEEA4DC212%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bkamiche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkamiche/32/14559_2.png) [@bkamiche](https://discuss.elastic.co/u/bkamiche)\
**Post date:** [December 12, 2014, 8:39pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/9 "2014-12-12T20:39:28Z")

</div>

I'm using the range as follows:

```
                                                    "range" : {
                                                            "fecha" : {

```

"gte" : "2012-08-01 00:00:00",

"lte" : "2012-08-31 23:59:59"  
}  
}

But although I dont get an error, the returned fields are not complying  
with the range....

On Friday, December 12, 2014 3:35:23 PM UTC-5, Bruno Kamiche wrote:

> This is my mapping
> 
> ```
> 'fecha' => [
> 'type' => 'date',
> 'format' => 'YYYY-mm-dd HH:mm:ss'
> ]
> 
> ```
> 
> On Friday, December 12, 2014 3:33:22 PM UTC-5, David Pilato wrote:
> 
> > Text should be fine. But are you sure you defined the field as date in  
> > mapping?  
> > With the right format?
> > 
> > David
> > 
> > Le 12 déc. 2014 à 21:15, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > 
> > I think I figured it out, I needed an extra set of curly braces
> > 
> > ```
> > "filter" : {
> > "bool" : {
> > "must" : [
> > {
> > "range" : {
> > "fecha" : 
> > 
> > ```
> > 
> > {
> > 
> > "gte" : 1325394000,
> > 
> > "lte" : 1356930000  
> > }  
> > }  
> > },  
> > {  
> > "term" : {  
> > "aq\_industryid" : 1 }  
> > },  
> > {  
> > "term" : {  
> > "aq\_clientid" : 1 }  
> > },  
> > {  
> > "term" : {  
> > "ntipo" : [5] }  
> > }  
> > ]  
> > }  
> > }
> > 
> > Now the query runs, but it does not yield the expected results, maybe you  
> > can help me with this
> > 
> > When I index the data, the field "fecha" is declared as a date field,  
> > with format "YYYY-mm-dd HH:mm:ss", when I query Elasticsearch I see the  
> > correct dates in the retrieved information, now I need to filter upon this  
> > data with a range of dates, how shall I express the range values, as text  
> > or as a unixtime ?
> > 
> > I've tried both and although theres data that should comply elastic does  
> > not return records.
> > 
> > On Friday, December 12, 2014 3:08:51 PM UTC-5, Bruno Kamiche wrote:
> > 
> > > I changed the filter to this:
> > > 
> > > ```
> > > "filter" : {
> > > "bool" : {
> > > "must" : [
> > > "range" : {
> > > "fecha" : {
> > > "gte" : 
> > > 
> > > ```
> > > 
> > > "1325394000",  
> > > "lte" :  
> > > "1356930000"  
> > > }  
> > > },  
> > > {  
> > > "term" : {  
> > > "aq\_industryid" : 1 }  
> > > },  
> > > {  
> > > "term" : {  
> > > "aq\_clientid" : 1 }  
> > > },  
> > > {  
> > > "term" : {  
> > > "ntipo" : [5] }  
> > > }  
> > > ]  
> > > }  
> > > }
> > > 
> > > But it keeps the error:
> > > 
> > > PHP Fatal error: Uncaught exception  
> > > 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client  
> > > error response  
> > > [status code] 400  
> > > [reason phrase] Bad Request  
> > > [url] [http://localhost:9200/quantico\_index/quantico\_type/\_search](http://localhost:9200/quantico_index/quantico_type/_search)' in  
> > > /root/vendor/guzzle/http/Guzzle/Http/Exception/BadResponseException.php:43  
> > > Stack trace:  
> > > #0 /root/vendor/guzzle/http/Guzzle/Http/Message/Request.php(145):  
> > > Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest),  
> > > Object(Guzzle\Http\Message\Response))  
> > > #1 [internal function]:  
> > > Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event),  
> > > 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> > > #2  
> > > /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164):  
> > > call\_user\_func(Array, Object(Guzzle\Common\Event), 'request.error',  
> > > Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> > > #3  
> > > /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(53):  
> > > Symf in  
> > > /root/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/GuzzleConnection.php  
> > > on line 266
> > > 
> > > On Friday, December 12, 2014 3:06:47 PM UTC-5, David Pilato wrote:
> > > 
> > > > Oh I see. Filter accepts only one filter. You should put your range  
> > > > inside the Must array.
> > > > 
> > > > David
> > > > 
> > > > Le 12 déc. 2014 à 21:04, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > > > 
> > > > Hello, I'm testing Elasticsearch and I need to apply different  
> > > > filters, when I include the "range" filter I get an error and the query is  
> > > > not executed, here's the json:
> > > > 
> > > > $json = '{  
> > > > "size" : 10,  
> > > > "from" : 0,  
> > > > "sort" : [  
> > > > { "\_timestamp" : { "order" : "desc" } },  
> > > > { "\_score" : { "order" : "desc" } }  
> > > > ],  
> > > > "query" : {  
> > > > "filtered" : {  
> > > > "query" : {  
> > > > "query\_string" : {  
> > > > "fields" : ["mytextfield"],  
> > > > "query" : "my query string",  
> > > > "default\_operator" : "AND"  
> > > > }  
> > > > },  
> > > > "filter" : {  
> > > > "range" : {  
> > > > "datefields" : {  
> > > > "gte" : "1325394000",  
> > > > "lte" : "1356930000"  
> > > > }  
> > > > },  
> > > > "bool" : {  
> > > > "must" : [  
> > > > {  
> > > > "term" : {  
> > > > "aq\_industryid" : 1 }  
> > > > },  
> > > > {  
> > > > "term" : {  
> > > > "aq\_clientid" : 1 }  
> > > > },  
> > > > {  
> > > > "term" : {  
> > > > "ntipo" : [5] }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > ```
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > }';
> > > > 
> > > > If I don't include the "range" filter, everything works fine (filtering  
> > > > by the other fields, number of results, order, etc), what am I doing wrong?
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google Groups  
> > > > "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c7125662-eb03-4bd8-8446-bc3c0941f437%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7125662-eb03-4bd8-8446-bc3c0941f437%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [December 12, 2014, 8:50pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/10 "2014-12-12T20:50:57Z")

</div>

I don't know. You should create a full SENSE recreation and GIST it.

David

> Le 12 déc. 2014 à 21:39, Bruno Kamiche [bkamiche@gmail.com](mailto:bkamiche@gmail.com) a écrit :
> 
> I'm using the range as follows:
> 
> ```
> "range" : {
> "fecha" : {
> "gte" : "2012-08-01 00:00:00",
> "lte" : "2012-08-31 23:59:59"
> }
> }
> 
> ```
> 
> But although I dont get an error, the returned fields are not complying with the range....
> 
> > On Friday, December 12, 2014 3:35:23 PM UTC-5, Bruno Kamiche wrote:  
> > This is my mapping
> > 
> > ```
> > 'fecha' => [
> > 'type' => 'date',
> > 'format' => 'YYYY-mm-dd HH:mm:ss'
> > ]
> > 
> > ```
> > 
> > > On Friday, December 12, 2014 3:33:22 PM UTC-5, David Pilato wrote:  
> > > Text should be fine. But are you sure you defined the field as date in mapping?  
> > > With the right format?
> > > 
> > > David
> > > 
> > > > Le 12 déc. 2014 à 21:15, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > > > 
> > > > I think I figured it out, I needed an extra set of curly braces
> > > > 
> > > > ```
> > > > "filter" : {
> > > > "bool" : {
> > > > "must" : [
> > > > {
> > > > "range" : {
> > > > "fecha" : {
> > > > "gte" : 1325394000,
> > > > "lte" : 1356930000
> > > > }
> > > > }
> > > > },
> > > > {
> > > > "term" : { "aq_industryid" : 1 }
> > > > },
> > > > {
> > > > "term" : { "aq_clientid" : 1 }
> > > > },
> > > > {
> > > > "term" : { "ntipo" : [5] }
> > > > }
> > > > ]
> > > > }
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > Now the query runs, but it does not yield the expected results, maybe you can help me with this
> > > > 
> > > > When I index the data, the field "fecha" is declared as a date field, with format "YYYY-mm-dd HH:mm:ss", when I query Elasticsearch I see the correct dates in the retrieved information, now I need to filter upon this data with a range of dates, how shall I express the range values, as text or as a unixtime ?
> > > > 
> > > > I've tried both and although theres data that should comply elastic does not return records.
> > > > 
> > > > > On Friday, December 12, 2014 3:08:51 PM UTC-5, Bruno Kamiche wrote:  
> > > > > I changed the filter to this:
> > > > > 
> > > > > ```
> > > > > "filter" : {
> > > > > "bool" : {
> > > > > "must" : [
> > > > > "range" : {
> > > > > "fecha" : {
> > > > > "gte" : "1325394000",
> > > > > "lte" : "1356930000"
> > > > > }
> > > > > },
> > > > > {
> > > > > "term" : { "aq_industryid" : 1 }
> > > > > },
> > > > > {
> > > > > "term" : { "aq_clientid" : 1 }
> > > > > },
> > > > > {
> > > > > "term" : { "ntipo" : [5] }
> > > > > }
> > > > > ]
> > > > > }
> > > > > }
> > > > > 
> > > > > ```
> > > > > 
> > > > > But it keeps the error:
> > > > > 
> > > > > PHP Fatal error: Uncaught exception 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client error response  
> > > > > [status code] 400  
> > > > > [reason phrase] Bad Request  
> > > > > [url] [http://localhost:9200/quantico\_index/quantico\_type/\_search](http://localhost:9200/quantico_index/quantico_type/_search)' in /root/vendor/guzzle/http/Guzzle/Http/Exception/BadResponseException.php:43  
> > > > > Stack trace:  
> > > > > #0 /root/vendor/guzzle/http/Guzzle/Http/Message/Request.php(145): Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Message\Response))  
> > > > > #1 [internal function]: Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> > > > > #2 /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164): call\_user\_func(Array, Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))  
> > > > > #3 /root/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(53): Symf in /root/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/GuzzleConnection.php on line 266
> > > > > 
> > > > > > On Friday, December 12, 2014 3:06:47 PM UTC-5, David Pilato wrote:  
> > > > > > Oh I see. Filter accepts only one filter. You should put your range inside the Must array.
> > > > > > 
> > > > > > David
> > > > > > 
> > > > > > > Le 12 déc. 2014 à 21:04, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > > > > > > 
> > > > > > > Hello, I'm testing Elasticsearch and I need to apply different filters, when I include the "range" filter I get an error and the query is not executed, here's the json:
> > > > > > > 
> > > > > > > $json = '{  
> > > > > > > "size" : 10,  
> > > > > > > "from" : 0,  
> > > > > > > "sort" : [  
> > > > > > > { "\_timestamp" : { "order" : "desc" } },  
> > > > > > > { "\_score" : { "order" : "desc" } }  
> > > > > > > ],  
> > > > > > > "query" : {  
> > > > > > > "filtered" : {  
> > > > > > > "query" : {  
> > > > > > > "query\_string" : {  
> > > > > > > "fields" : ["mytextfield"],  
> > > > > > > "query" : "my query string",  
> > > > > > > "default\_operator" : "AND"  
> > > > > > > }  
> > > > > > > },  
> > > > > > > "filter" : {  
> > > > > > > "range" : {  
> > > > > > > "datefields" : {  
> > > > > > > "gte" : "1325394000",  
> > > > > > > "lte" : "1356930000"  
> > > > > > > }  
> > > > > > > },  
> > > > > > > "bool" : {  
> > > > > > > "must" : [  
> > > > > > > {  
> > > > > > > "term" : { "aq\_industryid" : 1 }  
> > > > > > > },  
> > > > > > > {  
> > > > > > > "term" : { "aq\_clientid" : 1 }  
> > > > > > > },  
> > > > > > > {  
> > > > > > > "term" : { "ntipo" : [5] }  
> > > > > > > }  
> > > > > > > ]  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }
> > > > > > > 
> > > > > > > ```
> > > > > > > }
> > > > > > > 
> > > > > > > ```
> > > > > > > 
> > > > > > > }';
> > > > > > > 
> > > > > > > If I don't include the "range" filter, everything works fine (filtering by the other fields, number of results, order, etc), what am I doing wrong?
> > > > > > > 
> > > > > > > --  
> > > > > > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be4ca3a2-081f-458a-a006-8d8e80ef23e5%40googlegroups.com).  
> > > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ac37c0e-69a7-4ffd-b211-497fb88b7e23%40googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c7125662-eb03-4bd8-8446-bc3c0941f437%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7125662-eb03-4bd8-8446-bc3c0941f437%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/A6A53EED-9E47-439E-B390-E99E625EB3D6%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/A6A53EED-9E47-439E-B390-E99E625EB3D6%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Hilal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hilal/32/7684_2.png) [@Hilal](https://discuss.elastic.co/u/Hilal)\
**Post date:** [February 9, 2016, 3:16pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/11 "2016-02-09T15:16:52Z")

</div>

I think there are a lot of problems about range filter date. I didn't solve this problem. Is there someone who can solve?

---

<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:** [February 9, 2016, 5:17pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/12 "2016-02-09T17:17:49Z")

</div>

Hijacking old threads won't help you. Please keep your questions in [Date format incorrect results](https://discuss.elastic.co/t/date-format-incorrect-results/40643/10)

---

<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:17pm UTC](https://discuss.elastic.co/t/mixing-filters/21240/13 "2017-07-05T23:17:53Z")

</div>


