# Applying filter condition

**URL:** https://discuss.elastic.co/t/applying-filter-condition/37878
**Category:** Elasticsearch
**Created:** [December 23, 2015, 4:57pm UTC](https://discuss.elastic.co/t/applying-filter-condition/37878 "2015-12-23T16:57:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Sivaprakash\_Shanmuga](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Sivaprakash\_Shanmuga](https://discuss.elastic.co/u/Sivaprakash_Shanmuga)
#### Post date: [December 23, 2015, 4:57pm UTC](https://discuss.elastic.co/t/applying-filter-condition/37878/1 "2015-12-23T16:57:48Z")

</div>

Hi

In the following query "Course" is a Array data type.

> {  
> "query": {  
> "filtered":  
> {  
> "filter":  
> {  
> "and":  
> [  
> { "terms": { "CategoryId":["3456", "1053"] } },  
> { "terms": { "SubType":["1102" , "2348"]} },  
> { "terms": { "Course":["1456" , "1458"]} },  
> {"geo\_bounding\_box":  
> {  
> "location":  
> {  
> "top\_right":  
> {  
> "lat": 4.482137,  
> "lon": 51.0355306  
> },  
> "bottom\_left":  
> {  
> "lat": 4.482137,  
> "lon": 51.0146768  
> }  
> }  
> }  
> }  
> ]  
> }  
> }  
> },  
> "sort": { "createdDate": { "order": "desc" }}  
> }

I want to retrive data which has COURSE as "1456" and "1458" right now it works "OR" but I want to apply "AND". How to do it?

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [December 24, 2015, 1:11pm UTC](https://discuss.elastic.co/t/applying-filter-condition/37878/2 "2015-12-24T13:11:24Z")

</div>

If you want to meet both conditions, you need to use a bool query/filter. Ie. replace:

```auto
{ "terms": { "Course":["1456" , "1458"]} },

```

with

```auto
{ "bool": {
  "must": [ 
    { "term": { "Course": "1456" } },
    { "term": { "Course": "1458" } }
  ]
 } }

```

---

<div class="post-metadata">

### Author: ![Sivaprakash\_Shanmuga](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Sivaprakash\_Shanmuga](https://discuss.elastic.co/u/Sivaprakash_Shanmuga)
#### Post date: [December 24, 2015, 6:06pm UTC](https://discuss.elastic.co/t/applying-filter-condition/37878/3 "2015-12-24T18:06:30Z")

</div>

It worked Thank you !!

---

<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:28pm UTC](https://discuss.elastic.co/t/applying-filter-condition/37878/4 "2017-07-05T23:28:42Z")

</div>


