# Need help in adding And conditions using must query

**URL:** https://discuss.elastic.co/t/need-help-in-adding-and-conditions-using-must-query/45327
**Category:** Elasticsearch
**Created:** [March 24, 2016, 9:55am UTC](https://discuss.elastic.co/t/need-help-in-adding-and-conditions-using-must-query/45327 "2016-03-24T09:55:04Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![displaynone](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@displaynone](https://discuss.elastic.co/u/displaynone)
#### Post date: [March 24, 2016, 9:55am UTC](https://discuss.elastic.co/t/need-help-in-adding-and-conditions-using-must-query/45327/1 "2016-03-24T09:55:04Z")

</div>

Hi Team,

I am trying to query a data where i need to add filters based on fields but it returns multiple results instead of a single record.

here is the request  
{  
"query": {  
"bool": {  
"must": [  
{"match": {"categories\_filter": "hollywood"}},  
{"match": {"sub\_categories\_filter": "Sub-Category 7"} }

```
  ]
}

```

}  
}

and here is the response

{  
"took": 3,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"failed": 0  
},  
"hits": {  
"total": 2,  
"max\_score": 3.0786304,  
"hits": [  
{  
"\_index": "pvrmod",  
"\_type": "movie",  
"\_id": "43",  
"\_score": 3.0786304,  
"\_source": {  
"id": 43,  
"cast": "Ben Stiller, John Turturro, Olivier Martinez",  
"synopsis": "",  
"joinNowUrl": "",  
"createdBy": "",  
"ticketPrice": "",  
"screeningFlag": "",  
"screeningDetails": "",  
"address": "",  
"showTime": "",  
"ticketTypeSelect": "",  
"censor\_rating": "V/UA",  
"code": "HLR06",  
"type": "Non-3D",  
"trailer": "[https://www.youtube.com/watch?v=cwdliqOGTLw](https://www.youtube.com/watch?v=cwdliqOGTLw)",  
"imdb\_code": "1234654",  
"tags": [  
"Animation"  
],  
"genre": "Adventure",  
"languages": "Bengali",  
"actors": [  
{  
"actor": "Ben Stiller"  
},  
{  
"actor": "John Turturro"  
},  
{  
"actor": "Olivier Martinez"  
}  
],  
"categories": [  
{  
"category": "Category2"  
},  
{  
"category": "Hollywood"  
}  
],  
"categories\_filter": [  
"Category2,Hollywood"  
],  
"sub\_categories\_filter": [  
"Sub-Category1,Sub-Category 4,Sub-Category 5,Sub-Category 6,Sub-Category 7"  
],  
"countries": [  
{  
"country": "India",  
"region": "South",  
"state": "Tamil Nadu",  
"city": "Chennai"  
}  
]  
}  
},  
{  
"\_index": "pvrmod",  
"\_type": "movie",  
"\_id": "38",  
"\_score": 2.6205246,  
"\_source": {  
"id": 38,  
"cast": "",  
"synopsis": ".",  
"joinNowUrl": "",  
"createdBy": "",  
"ticketPrice": "",  
"screeningFlag": "",  
"screeningDetails": "",  
"address": "",  
"showTime": "",  
"ticketTypeSelect": "",  
"censor\_rating": "V/UA",  
"code": "HLR02",  
"type": "Non-3D",  
"trailer": "[https://www.youtube.com/watch?v=nTkcX989XP0](https://www.youtube.com/watch?v=nTkcX989XP0)",  
"imdb\_code": "812352",  
"tags": [],  
"genre": "",  
"languages": "",  
"actors": [],  
"categories": [  
{  
"category": "Hollywood"  
}  
],  
"categories\_filter": [  
"Hollywood"  
],  
"sub\_categories\_filter": [  
"Sub-Category 4"  
],  
"countries": []  
}  
}  
]  
}  
}

---

<div class="post-metadata">

### Author: ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)
#### Post date: [March 24, 2016, 10:43am UTC](https://discuss.elastic.co/t/need-help-in-adding-and-conditions-using-must-query/45327/2 "2016-03-24T10:43:26Z")

</div>

Is it possible that `sub_categories_filter` is an analyzed field? In that case, `"match": {"sub_categories_filter": "Sub-Category 7"}` means "match `Sub` or `Category` or `7`".

---

<div class="post-metadata">

### Author: ![displaynone](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@displaynone](https://discuss.elastic.co/u/displaynone)
#### Post date: [March 24, 2016, 10:47am UTC](https://discuss.elastic.co/t/need-help-in-adding-and-conditions-using-must-query/45327/3 "2016-03-24T10:47:30Z")

</div>

Hi Ywelsch,

Thanks for the reply.

I need to add conditions eg

select \* from movies where categories\_filter='hollywood' AND sub\_categories\_fileter='sub-category7' AND genre='Drama' and so on...

let me know if there is any issue with implementation.

---

<div class="post-metadata">

### Author: ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)
#### Post date: [March 24, 2016, 11:27am UTC](https://discuss.elastic.co/t/need-help-in-adding-and-conditions-using-must-query/45327/4 "2016-03-24T11:27:59Z")

</div>

What happens if you replace "match" by "match\_phrase"?

Can you show me the mapping? [https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html)

---

<div class="post-metadata">

### Author: ![displaynone](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@displaynone](https://discuss.elastic.co/u/displaynone)
#### Post date: [March 29, 2016, 2:29pm UTC](https://discuss.elastic.co/t/need-help-in-adding-and-conditions-using-must-query/45327/5 "2016-03-29T14:29:05Z")

</div>

Hi Ywelsh,

Thanks for the reply it worked.

here is the mapping url

[http://e349b6492cb87eee13b05b0c87ff330d.us-east-1.aws.found.io:9200/pvrmod/\_mappings](http://e349b6492cb87eee13b05b0c87ff330d.us-east-1.aws.found.io:9200/pvrmod/_mappings)

right now i am facing issue with data with fields having multiple value in strings. is there any option to filter those out ?

eg languages : english, hindi, french

---

<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:04pm UTC](https://discuss.elastic.co/t/need-help-in-adding-and-conditions-using-must-query/45327/6 "2017-07-05T23:04:23Z")

</div>


