# Multiple terms in filter in filtered query

**URL:** <https://discuss.elastic.co/t/multiple-terms-in-filter-in-filtered-query/19614>\
**Category:** Elasticsearch\
**Created:** [September 4, 2014, 2:23am UTC](https://discuss.elastic.co/t/multiple-terms-in-filter-in-filtered-query/19614 "2014-09-04T02:23:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pontus\_Lundin](https://avatars.discourse-cdn.com/v4/letter/p/5daacb/32.png) [@Pontus\_Lundin](https://discuss.elastic.co/u/Pontus_Lundin)\
**Post date:** [September 4, 2014, 2:23am UTC](https://discuss.elastic.co/t/multiple-terms-in-filter-in-filtered-query/19614/1 "2014-09-04T02:23:16Z")

</div>

Hi,

Can anyone suggest how i can add multiple terms to my filter in the query  
below? Tried one term: "med" and it works, adding yet another as array only  
takes the last element and the first one shows up in the hit list. I tried  
Bool and "AND" but havent got it to work neither.

Thanks!

GET /teststrings/\_search  
{  
"query" : {

"filtered": {  
"query": {  
"multi\_match" : {  
"query": "Decor strip",  
"type":"best\_fields",  
"fields": ["enstring.name", "enstring.untouched^5"]  
}  
},  
"filter": {  
"not": {  
"term": {  
"svstring.name": ["med","utan"]  
}  
}  
}  
}

}  
}

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ee64dc17-1c85-46c7-a144-7b82cb1ad9d5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ee64dc17-1c85-46c7-a144-7b82cb1ad9d5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [September 4, 2014, 2:31am UTC](https://discuss.elastic.co/t/multiple-terms-in-filter-in-filtered-query/19614/2 "2014-09-04T02:31:13Z")

</div>

Hello Pontus ,

You need to use terms instead of term filter

TERMS filter -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Thanks  
Vineeth

On Thu, Sep 4, 2014 at 7:53 AM, Pontus Lundin [lundin.codeitez@gmail.com](mailto:lundin.codeitez@gmail.com)  
wrote:

> Hi,
> 
> Can anyone suggest how i can add multiple terms to my filter in the query  
> below? Tried one term: "med" and it works, adding yet another as array only  
> takes the last element and the first one shows up in the hit list. I tried  
> Bool and "AND" but havent got it to work neither.
> 
> Thanks!
> 
> GET /teststrings/\_search  
> {  
> "query" : {
> 
> "filtered": {  
> "query": {  
> "multi\_match" : {  
> "query": "Decor strip",  
> "type":"best\_fields",  
> "fields": ["enstring.name", "enstring.untouched^5"]  
> }  
> },  
> "filter": {  
> "not": {  
> "term": {  
> "svstring.name": ["med","utan"]  
> }  
> }  
> }  
> }
> 
> }  
> }
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/ee64dc17-1c85-46c7-a144-7b82cb1ad9d5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ee64dc17-1c85-46c7-a144-7b82cb1ad9d5%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/ee64dc17-1c85-46c7-a144-7b82cb1ad9d5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ee64dc17-1c85-46c7-a144-7b82cb1ad9d5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k%3Di1Dx7H%2B2Vv%3DLpHMX5s\_FBF8Nu5%2BP-1MsEUiHggjNPw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k%3Di1Dx7H%2B2Vv%3DLpHMX5s_FBF8Nu5%2BP-1MsEUiHggjNPw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Pontus\_Lundin](https://avatars.discourse-cdn.com/v4/letter/p/5daacb/32.png) [@Pontus\_Lundin](https://discuss.elastic.co/u/Pontus_Lundin)\
**Post date:** [September 4, 2014, 2:31am UTC](https://discuss.elastic.co/t/multiple-terms-in-filter-in-filtered-query/19614/3 "2014-09-04T02:31:49Z")

</div>

I just found out a way with bool.

GET /teststrings/\_search  
{  
"query" : {

"filtered": {  
"query": {  
"multi\_match" : {  
"query": "Decor strip",  
"type":"best\_fields",  
"fields": ["enstring.name", "enstring.untouched^5"]  
}  
},  
"filter": {  
"bool": {  
"must": {},  
"must\_not": [  
{ "term": { "svstring.name": "med" }},  
{ "term": { "svstring.name": "utan" }}  
],  
"should":  
{}

```
}

```

}  
}

}  
}

Den torsdagen den 4:e september 2014 kl. 04:23:16 UTC+2 skrev Pontus Lundin:

> Hi,
> 
> Can anyone suggest how i can add multiple terms to my filter in the query  
> below? Tried one term: "med" and it works, adding yet another as array only  
> takes the last element and the first one shows up in the hit list. I tried  
> Bool and "AND" but havent got it to work neither.
> 
> Thanks!
> 
> GET /teststrings/\_search  
> {  
> "query" : {
> 
> "filtered": {  
> "query": {  
> "multi\_match" : {  
> "query": "Decor strip",  
> "type":"best\_fields",  
> "fields": ["enstring.name", "enstring.untouched^5"]  
> }  
> },  
> "filter": {  
> "not": {  
> "term": {  
> "svstring.name": ["med","utan"]  
> }  
> }  
> }  
> }
> 
> }  
> }

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8627aa77-0293-44fd-8be2-0c21b5313590%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8627aa77-0293-44fd-8be2-0c21b5313590%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Pontus\_Lundin](https://avatars.discourse-cdn.com/v4/letter/p/5daacb/32.png) [@Pontus\_Lundin](https://discuss.elastic.co/u/Pontus_Lundin)\
**Post date:** [September 4, 2014, 12:55pm UTC](https://discuss.elastic.co/t/multiple-terms-in-filter-in-filtered-query/19614/4 "2014-09-04T12:55:32Z")

</div>

Ah, Thanks for the hint vineeth!

Den torsdagen den 4:e september 2014 kl. 04:31:31 UTC+2 skrev vineeth mohan:

> Hello Pontus ,
> 
> You need to use terms instead of term filter
> 
> TERMS filter -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_most_important_queries_and_filters.html#_literal_terms_literal_filter)
> 
> Thanks  
> Vineeth
> 
> On Thu, Sep 4, 2014 at 7:53 AM, Pontus Lundin \<[lundin....@gmail.com](mailto:lundin....@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi,
> > 
> > Can anyone suggest how i can add multiple terms to my filter in the query  
> > below? Tried one term: "med" and it works, adding yet another as array only  
> > takes the last element and the first one shows up in the hit list. I tried  
> > Bool and "AND" but havent got it to work neither.
> > 
> > Thanks!
> > 
> > GET /teststrings/\_search  
> > {  
> > "query" : {
> > 
> > "filtered": {  
> > "query": {  
> > "multi\_match" : {  
> > "query": "Decor strip",  
> > "type":"best\_fields",  
> > "fields": ["enstring.name", "enstring.untouched^5"]  
> > }  
> > },  
> > "filter": {  
> > "not": {  
> > "term": {  
> > "svstring.name": ["med","utan"]  
> > }  
> > }  
> > }  
> > }
> > 
> > }  
> > }
> > 
> > --  
> > 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:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/ee64dc17-1c85-46c7-a144-7b82cb1ad9d5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ee64dc17-1c85-46c7-a144-7b82cb1ad9d5%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/ee64dc17-1c85-46c7-a144-7b82cb1ad9d5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ee64dc17-1c85-46c7-a144-7b82cb1ad9d5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a00bc37d-a689-4ac9-a607-e0ba064d2099%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a00bc37d-a689-4ac9-a607-e0ba064d2099%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:04am UTC](https://discuss.elastic.co/t/multiple-terms-in-filter-in-filtered-query/19614/5 "2017-07-06T01:04:23Z")

</div>


