# Can I use AND filter for more than two queries?

**URL:** https://discuss.elastic.co/t/can-i-use-and-filter-for-more-than-two-queries/9964
**Category:** Elasticsearch
**Created:** [December 6, 2012, 2:24am UTC](https://discuss.elastic.co/t/can-i-use-and-filter-for-more-than-two-queries/9964 "2012-12-06T02:24:31Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![chenryn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenryn/32/44917_2.png) [@chenryn](https://discuss.elastic.co/u/chenryn)
#### Post date: [December 6, 2012, 2:24am UTC](https://discuss.elastic.co/t/can-i-use-and-filter-for-more-than-two-queries/9964/1 "2012-12-06T02:24:31Z")

</div>

I only find guide show examples than filter use AND to connect two queries.  
What about more?  
and =\> [  
{  
range =\> {  
date =\> {  
from =\> "2012-12-04T00:00:00",  
to =\> "2012-12-05T23:59:59"  
},  
},  
},  
{  
numeric\_range =\> {  
timeCost =\> {  
gte =\> 200,  
},  
},  
},  
{  
prefix =\> {  
requestUrl =\> "[http://img.domain.com/](http://img.domain.com/)",  
},  
},  
]

--

---

<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: [December 6, 2012, 11:27pm UTC](https://discuss.elastic.co/t/can-i-use-and-filter-for-more-than-two-queries/9964/2 "2012-12-06T23:27:17Z")

</div>

You can use a Bool Filter: [http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter.html](http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter.html)

HTH

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

Le 6 déc. 2012 à 03:24, chenlin rao [rao.chenlin@gmail.com](mailto:rao.chenlin@gmail.com) a écrit :

I only find guide show examples than filter use AND to connect two queries. What about more?  
and =\> [  
{  
range =\> {  
date =\> {  
from =\> "2012-12-04T00:00:00",  
to =\> "2012-12-05T23:59:59"  
},  
},  
},  
{  
numeric\_range =\> {  
timeCost =\> {  
gte =\> 200,  
},  
},  
},  
{  
prefix =\> {  
requestUrl =\> "[http://img.domain.com/](http://img.domain.com/)",  
},  
},  
]

--

--

---

<div class="post-metadata">

### Author: ![chenryn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenryn/32/44917_2.png) [@chenryn](https://discuss.elastic.co/u/chenryn)
#### Post date: [December 7, 2012, 4:17am UTC](https://discuss.elastic.co/t/can-i-use-and-filter-for-more-than-two-queries/9964/3 "2012-12-07T04:17:09Z")

</div>

Also cannot write two MUST?  
I found that I must write "bool":{"must":{},"must\_not":{}} and then got  
right result.  
If I write "bool":{"must":{},"must":{}}, return all document ....

2012/12/7 David Pilato [david@pilato.fr](mailto:david@pilato.fr)

> You can use a Bool Filter:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter.html)
> 
> HTH
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 6 déc. 2012 à 03:24, chenlin rao [rao.chenlin@gmail.com](mailto:rao.chenlin@gmail.com) a écrit :
> 
> I only find guide show examples than filter use AND to connect two  
> queries. What about more?  
> and =\> [  
> {  
> range =\> {  
> date =\> {  
> from =\> "2012-12-04T00:00:00",  
> to =\> "2012-12-05T23:59:59"  
> },  
> },  
> },  
> {  
> numeric\_range =\> {  
> timeCost =\> {  
> gte =\> 200,  
> },  
> },  
> },  
> {  
> prefix =\> {  
> requestUrl =\> "[http://img.domain.com/](http://img.domain.com/)",  
> },  
> },  
> ]
> 
> --
> 
> --

--

---

<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: [December 7, 2012, 7:44am UTC](https://discuss.elastic.co/t/can-i-use-and-filter-for-more-than-two-queries/9964/4 "2012-12-07T07:44:48Z")

</div>

You can write it like this.

```
    "must" : [
        {
            "term" : { "tag" : "wow" }
        },
        {
            "term" : { "tag" : "elasticsearch" }
        }
    ],

```

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

Le 7 déc. 2012 à 05:17, chenlin rao [rao.chenlin@gmail.com](mailto:rao.chenlin@gmail.com) a écrit :

> Also cannot write two MUST?  
> I found that I must write "bool":{"must":{},"must\_not":{}} and then got right result.  
> If I write "bool":{"must":{},"must":{}}, return all document ....
> 
> 2012/12/7 David Pilato [david@pilato.fr](mailto:david@pilato.fr)  
> You can use a Bool Filter: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter.html)
> 
> HTH
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 6 déc. 2012 à 03:24, chenlin rao [rao.chenlin@gmail.com](mailto:rao.chenlin@gmail.com) a écrit :
> 
> I only find guide show examples than filter use AND to connect two queries. What about more?  
> and =\> [  
> {  
> range =\> {  
> date =\> {  
> from =\> "2012-12-04T00:00:00",  
> to =\> "2012-12-05T23:59:59"  
> },  
> },  
> },  
> {  
> numeric\_range =\> {  
> timeCost =\> {  
> gte =\> 200,  
> },  
> },  
> },  
> {  
> prefix =\> {  
> requestUrl =\> "[http://img.domain.com/](http://img.domain.com/)",  
> },  
> },  
> ]
> 
> --
> 
> --
> 
> --

--

---

<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:00am UTC](https://discuss.elastic.co/t/can-i-use-and-filter-for-more-than-two-queries/9964/5 "2017-07-06T03:00:55Z")

</div>


