# Bool query with filter giving error

**URL:** <https://discuss.elastic.co/t/bool-query-with-filter-giving-error/16377>\
**Category:** Elasticsearch\
**Created:** [March 14, 2014, 1:55pm UTC](https://discuss.elastic.co/t/bool-query-with-filter-giving-error/16377 "2014-03-14T13:55:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bagui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bagui/32/960_2.png) [@bagui](https://discuss.elastic.co/u/bagui)\
**Post date:** [March 14, 2014, 1:55pm UTC](https://discuss.elastic.co/t/bool-query-with-filter-giving-error/16377/1 "2014-03-14T13:55:27Z")

</div>

Hi,

I'm trying to run the below bool query with filter range to fetch all the  
node data with CLOUD\_TYPE="AWS-EC2"" and NODE\_STATUS="ACTIVE".  
But I'm getting SearchPhaseExecutionException from elasticsearch. Please  
let me know the correct way to do this.

curl -XPOST "[http://10.203.251.142:9200/aricloud/\_search](http://10.203.251.142:9200/aricloud/_search)" -d  
'{  
"filtered": {  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"CLOUD\_TYPE": "AWS-EC2"  
}  
},  
{  
"term": {  
"NODE\_STATUS": "ACTIVE"  
}  
}  
]  
}  
},  
"filter": {  
"range": {  
"NODE\_CREATE\_TIME": {  
"to": "2014-03-14 18:43:55",  
"from": "2014-03-14 16:22:32"  
}  
}  
}  
},  
"sort": {  
"NODE\_ID": "desc"  
},  
"from": 0,  
"size": 3  
}'

--  
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/4e53acd6-d68a-43fe-8340-72ae695e0060%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4e53acd6-d68a-43fe-8340-72ae695e0060%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 14, 2014, 2:47pm UTC](https://discuss.elastic.co/t/bool-query-with-filter-giving-error/16377/2 "2014-03-14T14:47:33Z")

</div>

You need to pass the search request a "query", so just change the above to:

GET /\_search  
{ "query": { "filtered": .... }, from: 0, size: 3 ...}

On 14 March 2014 14:55, Subhadip Bagui [i.bagui@gmail.com](mailto:i.bagui@gmail.com) wrote:

> Hi,
> 
> I'm trying to run the below bool query with filter range to fetch all the  
> node data with CLOUD\_TYPE="AWS-EC2"" and NODE\_STATUS="ACTIVE".  
> But I'm getting SearchPhaseExecutionException from elasticsearch. Please  
> let me know the correct way to do this.
> 
> curl -XPOST "[http://10.203.251.142:9200/aricloud/\_search](http://10.203.251.142:9200/aricloud/_search)" -d  
> '{  
> "filtered": {  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "CLOUD\_TYPE": "AWS-EC2"  
> }  
> },  
> {  
> "term": {  
> "NODE\_STATUS": "ACTIVE"  
> }  
> }  
> ]  
> }  
> },  
> "filter": {  
> "range": {  
> "NODE\_CREATE\_TIME": {  
> "to": "2014-03-14 18:43:55",  
> "from": "2014-03-14 16:22:32"  
> }  
> }  
> }  
> },  
> "sort": {  
> "NODE\_ID": "desc"  
> },  
> "from": 0,  
> "size": 3  
> }'
> 
> --  
> 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/4e53acd6-d68a-43fe-8340-72ae695e0060%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4e53acd6-d68a-43fe-8340-72ae695e0060%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/4e53acd6-d68a-43fe-8340-72ae695e0060%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/4e53acd6-d68a-43fe-8340-72ae695e0060%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/CAPt3XKSTtR1ppgD\_VopKPwXGZX3j3B\_aQUMtHpeJxgA%3DX0qP3A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKSTtR1ppgD_VopKPwXGZX3j3B_aQUMtHpeJxgA%3DX0qP3A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bagui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bagui/32/960_2.png) [@bagui](https://discuss.elastic.co/u/bagui)\
**Post date:** [March 17, 2014, 8:01am UTC](https://discuss.elastic.co/t/bool-query-with-filter-giving-error/16377/3 "2014-03-17T08:01:23Z")

</div>

Hi Clinton,

Thanks for your reply. I tried as suggested and the same is working now 🙂  
One question though, I have to pass the text field in lower case always as  
the same is getting analyzed by standard analyzer I guess. Is there any way  
to pass multiple match in bool for text search so that I can search with  
part of the exact text entered, like "CLOUD" instead of "cloud"

I tried below as given in link  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html)  
but it's giving error as 'Duplicate key "match" - syntax error'

POST /aricloud/\_search  
{  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"must": [  
{"term": {  
"CLOUD\_TYPE": {  
"value": "cloudstack"  
}  
}  
}  
] ,  
"must\_not": [  
{  
"term": {  
"NODE\_ID": {  
"value": "12235"  
}  
}  
}  
],  
"should": [  
{  
"match": {  
"NODE\_HOSTNAME": "[cloudserver.aricent.com](http://cloudserver.aricent.com)"  
},  
"match": {  
"NODE\_GROUP\_NAME": "MYSQL"  
}  
}  
]  
}  
},  
"filter": {  
"range": {  
"NODE\_CREATE\_TIME": {  
"from": "2014-03-14 16:32:35",  
"to": "2014-03-14 18:43:55"  
}  
}  
}  
}  
},  
"sort": [  
{  
"NODE\_ID": {  
"order": "desc"  
}  
}  
]  
}

--  
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/8aac212b-018c-4f51-8222-9bb00a09377d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8aac212b-018c-4f51-8222-9bb00a09377d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 17, 2014, 12:31pm UTC](https://discuss.elastic.co/t/bool-query-with-filter-giving-error/16377/4 "2014-03-17T12:31:04Z")

</div>

This this instead:

{  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"should": [  
{  
"match": {  
"NODE\_HOSTNAME": "[cloudserver.aricent.com](http://cloudserver.aricent.com)"  
}  
},  
{  
"match": {  
"NODE\_GROUP\_NAME": "MYSQL"  
}  
}  
]  
}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"range": {  
"NODE\_CREATE\_TIME": {  
"from": "2014-03-14 16:32:35",  
"to": "2014-03-14 18:43:55"  
}  
}  
},  
{  
"term": {  
"CLOUD\_TYPE": {  
"value": "cloudstack"  
}  
}  
}  
],  
"must\_not": {  
"term": {  
"NODE\_ID": {  
"value": "12235"  
}  
}  
}  
}  
}  
}  
},  
"sort": [  
{  
"NODE\_ID": {  
"order": "desc"  
}  
}  
]  
}

Note: Your query says to match anything that contains MYSQL or  
cloudserver..... Not sure if that is your intention or not

--  
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/CAPt3XKSTnF7OZGpEf0ZqJ05ZmBgOY\_pCy7JjEZEk5b\_%3DCR21ow%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKSTnF7OZGpEf0ZqJ05ZmBgOY_pCy7JjEZEk5b_%3DCR21ow%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:42am UTC](https://discuss.elastic.co/t/bool-query-with-filter-giving-error/16377/5 "2017-07-06T01:42:49Z")

</div>


