# Using should and must\_not in bool query

**URL:** https://discuss.elastic.co/t/using-should-and-must-not-in-bool-query/7486
**Category:** Elasticsearch
**Created:** [April 27, 2012, 6:32am UTC](https://discuss.elastic.co/t/using-should-and-must-not-in-bool-query/7486 "2012-04-27T06:32:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)
#### Post date: [April 27, 2012, 6:32am UTC](https://discuss.elastic.co/t/using-should-and-must-not-in-bool-query/7486/1 "2012-04-27T06:32:09Z")

</div>

Hi,

I have a query that is very similar to the terms query, but with more  
restriction. I would like to get  
the documents that have specific terms appear in the query.

for example:

1. {"doc":{"title":"looking dasd abd"}}
2. {"doc":{"title":"afas abd"}}
3. {"doc":{"title":"afas"}}
4. {"doc":{"title":"looking dasd"}}
5. {"doc":{"title":"looking dasd ghi"}}

how can i get result like doc 3 and 4 using should and must\_not query...

how can i write a query that does this?

thanks in advance..

Regards,  
Sumit Gupta

---

<div class="post-metadata">

### Author: ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)
#### Post date: [April 30, 2012, 5:34am UTC](https://discuss.elastic.co/t/using-should-and-must-not-in-bool-query/7486/2 "2012-04-30T05:34:12Z")

</div>

hi all for getting the result i make a query like..

curl -XGET '[http://localhost:9200/tweet2/type2/\_search](http://localhost:9200/tweet2/type2/_search)' -d '  
{  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"should": [  
{  
"field": {  
"Title": "((looking AND dasd) OR afas)"  
}  
}  
],  
"must\_not": [  
{  
"field": {  
"Title": "abd OR ghi"  
}  
}  
],  
"minimum\_number\_should\_match": 1  
}  
},  
"filter": {  
"range": {  
"CreatedAt": {  
"lt": "2011-11-15T00:00:00"  
}  
}  
}  
}  
}  
}'

but it is not giving any result but query is executed..please help me how i can implement bool query using should and must\_not...

please help me

Regards  
Sumit Gupta

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [April 30, 2012, 11:36am UTC](https://discuss.elastic.co/t/using-should-and-must-not-in-bool-query/7486/3 "2012-04-30T11:36:50Z")

</div>

The field names are case-sensitive. Try using "title" instead of "Title".

On Monday, April 30, 2012 1:34:12 AM UTC-4, Sumit Gupta wrote:

> hi all for getting the result i make a query like..
> 
> curl -XGET '[http://localhost:9200/tweet2/type2/\_search](http://localhost:9200/tweet2/type2/_search)' -d '  
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "field": {  
> "Title": "((looking AND dasd) OR  
> afas)"  
> }  
> }  
> ],  
> "must\_not": [  
> {  
> "field": {  
> "Title": "abd OR ghi"  
> }  
> }  
> ],  
> "minimum\_number\_should\_match": 1  
> }  
> },  
> "filter": {  
> "range": {  
> "CreatedAt": {  
> "lt": "2011-11-15T00:00:00"  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> but it is not giving any result but query is executed..please help me how  
> i  
> can implement bool query using should and must\_not...
> 
> please help me
> 
> Regards  
> Sumit Gupta
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/using-should-and-must-not-in-bool-query-tp3943532p3950015.html](http://elasticsearch-users.115913.n3.nabble.com/using-should-and-must-not-in-bool-query-tp3943532p3950015.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

### Author: ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)
#### Post date: [April 30, 2012, 12:29pm UTC](https://discuss.elastic.co/t/using-should-and-must-not-in-bool-query/7486/4 "2012-04-30T12:29:32Z")

</div>

thanx Igor Motov..

thats the reason.

Regards,  
Sumit Gupta

---

<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, 3:30am UTC](https://discuss.elastic.co/t/using-should-and-must-not-in-bool-query/7486/5 "2017-07-06T03:30:34Z")

</div>


