# AND query

**URL:** <https://discuss.elastic.co/t/and-query/14514>\
**Category:** Elasticsearch\
**Created:** [November 21, 2013, 12:49pm UTC](https://discuss.elastic.co/t/and-query/14514 "2013-11-21T12:49:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul1/32/46819_2.png) [@paul1](https://discuss.elastic.co/u/paul1)\
**Post date:** [November 21, 2013, 12:49pm UTC](https://discuss.elastic.co/t/and-query/14514/1 "2013-11-21T12:49:38Z")

</div>

Hi ,

My Data:

{  
"programs":"Computer",  
degreesAwarded:[  
Bachelor,  
Certificate,  
Doctorate  
],  
"costTution":22977,  
"isCoed":"Yes"  
}

My Query:  
I get results for below query  
{  
"query": {  
"bool": {  
"must": {  
"match": {  
"programs": "Computer",  
}  
}  
}  
}  
}

But i want to find something like "programs": "Computer", AND "  
degreesAwarded":"Bachelor" when i do that below i get exception ,  
i could not find how to do a AND/OR query .  
{  
"query": {  
"bool": {  
"must": {  
"match": {  
"programs": "Computer",  
"degreesAwarded":"Bachelor"  
}  
}  
}  
}  
}

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![paul1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul1/32/46819_2.png) [@paul1](https://discuss.elastic.co/u/paul1)\
**Post date:** [November 21, 2013, 2:30pm UTC](https://discuss.elastic.co/t/and-query/14514/2 "2013-11-21T14:30:54Z")

</div>

This worked for me  
{  
"query":{  
"bool":{  
"must":[  
{  
"match":{  
"programs":"computer"  
}  
},  
{  
"match":{  
"degreesAwarded":"Bachelor"  
}  
}  
]  
}  
}  
}

On Thursday, 21 November 2013 18:19:38 UTC+5:30, paul wrote:

> Hi ,
> 
> My Data:
> 
> {  
> "programs":"Computer",  
> degreesAwarded:[  
> Bachelor,  
> Certificate,  
> Doctorate  
> ],  
> "costTution":22977,  
> "isCoed":"Yes"  
> }
> 
> My Query:  
> I get results for below query  
> {  
> "query": {  
> "bool": {  
> "must": {  
> "match": {  
> "programs": "Computer",  
> }  
> }  
> }  
> }  
> }
> 
> But i want to find something like "programs": "Computer", AND "  
> degreesAwarded":"Bachelor" when i do that below i get exception ,  
> i could not find how to do a AND/OR query .  
> {  
> "query": {  
> "bool": {  
> "must": {  
> "match": {  
> "programs": "Computer",  
> "degreesAwarded":"Bachelor"  
> }  
> }  
> }  
> }  
> }

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [November 21, 2013, 4:03pm UTC](https://discuss.elastic.co/t/and-query/14514/3 "2013-11-21T16:03:09Z")

</div>

You should use filtered query I guess as your second clause sounds like to me as a filter!  
Filters are cached.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 21 nov. 2013 à 15:30, paul [avinashpaul85@gmail.com](mailto:avinashpaul85@gmail.com) a écrit :

> This worked for me  
> {  
> "query":{  
> "bool":{  
> "must":[  
> {  
> "match":{  
> "programs":"computer"  
> }  
> },  
> {  
> "match":{  
> "degreesAwarded":"Bachelor"  
> }  
> }  
> ]  
> }  
> }  
> }
> 
> On Thursday, 21 November 2013 18:19:38 UTC+5:30, paul wrote:
> 
> > Hi ,
> > 
> > My Data:
> > 
> > {  
> > "programs":"Computer",  
> > degreesAwarded:[  
> > Bachelor,  
> > Certificate,  
> > Doctorate  
> > ],  
> > "costTution":22977,  
> > "isCoed":"Yes"  
> > }
> > 
> > My Query:  
> > I get results for below query  
> > {  
> > "query": {  
> > "bool": {  
> > "must": {  
> > "match": {  
> > "programs": "Computer",  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > But i want to find something like "programs": "Computer", AND "degreesAwarded":"Bachelor" when i do that below i get exception ,  
> > i could not find how to do a AND/OR query .  
> > {  
> > "query": {  
> > "bool": {  
> > "must": {  
> > "match": {  
> > "programs": "Computer",  
> > "degreesAwarded":"Bachelor"  
> > }  
> > }  
> > }  
> > }  
> > }
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![paul1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul1/32/46819_2.png) [@paul1](https://discuss.elastic.co/u/paul1)\
**Post date:** [November 22, 2013, 5:27am UTC](https://discuss.elastic.co/t/and-query/14514/4 "2013-11-22T05:27:28Z")

</div>

Sure will look into filter query , thank you for the suggestion.

--  
Paul

On Thursday, 21 November 2013 21:33:09 UTC+5:30, David Pilato wrote:

> You should use filtered query I guess as your second clause sounds like to  
> me as a filter!  
> Filters are cached.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 21 nov. 2013 à 15:30, paul \<[avinas...@gmail.com](mailto:avinas...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> This worked for me  
> {  
> "query":{  
> "bool":{  
> "must":[  
> {  
> "match":{  
> "programs":"computer"  
> }  
> },  
> {  
> "match":{  
> "degreesAwarded":"Bachelor"  
> }  
> }  
> ]  
> }  
> }  
> }
> 
> On Thursday, 21 November 2013 18:19:38 UTC+5:30, paul wrote:
> 
> > Hi ,
> > 
> > My Data:
> > 
> > {  
> > "programs":"Computer",  
> > degreesAwarded:[  
> > Bachelor,  
> > Certificate,  
> > Doctorate  
> > ],  
> > "costTution":22977,  
> > "isCoed":"Yes"  
> > }
> > 
> > My Query:  
> > I get results for below query  
> > {  
> > "query": {  
> > "bool": {  
> > "must": {  
> > "match": {  
> > "programs": "Computer",  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > But i want to find something like "programs": "Computer", AND "  
> > degreesAwarded":"Bachelor" when i do that below i get exception ,  
> > i could not find how to do a AND/OR query .  
> > {  
> > "query": {  
> > "bool": {  
> > "must": {  
> > "match": {  
> > "programs": "Computer",  
> > "degreesAwarded":"Bachelor"  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > --  
> > 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:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:05am UTC](https://discuss.elastic.co/t/and-query/14514/5 "2017-07-06T02:05:30Z")

</div>


