# Combining several documents in a terms filter

**URL:** <https://discuss.elastic.co/t/combining-several-documents-in-a-terms-filter/23302>\
**Category:** Elasticsearch\
**Created:** [April 17, 2015, 10:19pm UTC](https://discuss.elastic.co/t/combining-several-documents-in-a-terms-filter/23302 "2015-04-17T22:19:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Nill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_nill/32/730_2.png) [@Daniel\_Nill](https://discuss.elastic.co/u/Daniel_Nill)\
**Post date:** [April 17, 2015, 10:19pm UTC](https://discuss.elastic.co/t/combining-several-documents-in-a-terms-filter/23302/1 "2015-04-17T22:19:05Z")

</div>

In the example  
here [http://www.elastic.co/guide/en/elasticsearch/reference/0.90/query-dsl-terms-filter.html#\_terms\_lookup\_twitter\_example](http://www.elastic.co/guide/en/elasticsearch/reference/0.90/query-dsl-terms-filter.html#_terms_lookup_twitter_example),  
it is indicated that the id field can only be for a single document. Is  
there a way to do:

curl -XGET localhost:9200/tweets/\_search -d '{  
"query" : {  
"filtered" : {  
"filter" : {  
"terms" : {  
"user" : {  
"index" : "users",  
"type" : "user",  
"id" : ["2", "3", "4"],  
"path" : "followers"  
},  
"\_cache\_key" : "user\_2\_friends"  
}  
}  
}  
}  
}'

Is the only way to get results for this to do a separate terms filter for  
each id?

--  
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/d8032d4a-fdb7-48c9-9828-64253c5d4b90%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d8032d4a-fdb7-48c9-9828-64253c5d4b90%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:** [April 18, 2015, 5:18am UTC](https://discuss.elastic.co/t/combining-several-documents-in-a-terms-filter/23302/2 "2015-04-18T05:18:27Z")

</div>

Hello Daniel ,

Feel free to use should clause in bool filter  
[http://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-bool-filter.html](http://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-bool-filter.html)  
.  
Here you can give multiple terms filter and each of them can point to a  
different document/field.

Thanks  
Vineeth Mohan,  
Elasticsearch consultant,  
[qbox.io](http://qbox.io) ( Elasticsearch service provider [http://qbox.io/](http://qbox.io/))

On Sat, Apr 18, 2015 at 3:49 AM, Daniel Nill [daniellnill@gmail.com](mailto:daniellnill@gmail.com) wrote:

> In the example here  
> [Terms Filter | Reference [0.90] | Elastic](http://www.elastic.co/guide/en/elasticsearch/reference/0.90/query-dsl-terms-filter.html#_terms_lookup_twitter_example),  
> it is indicated that the id field can only be for a single document. Is  
> there a way to do:
> 
> curl -XGET localhost:9200/tweets/\_search -d '{  
> "query" : {  
> "filtered" : {  
> "filter" : {  
> "terms" : {  
> "user" : {  
> "index" : "users",  
> "type" : "user",  
> "id" : ["2", "3", "4"],  
> "path" : "followers"  
> },  
> "\_cache\_key" : "user\_2\_friends"  
> }  
> }  
> }  
> }  
> }'
> 
> Is the only way to get results for this to do a separate terms filter for  
> each id?
> 
> --  
> 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/d8032d4a-fdb7-48c9-9828-64253c5d4b90%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d8032d4a-fdb7-48c9-9828-64253c5d4b90%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/d8032d4a-fdb7-48c9-9828-64253c5d4b90%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d8032d4a-fdb7-48c9-9828-64253c5d4b90%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/CAGdPd5%3DPmPFdhK6bUhT6WYxWMZtZWAJGNDc8VJF-8tC1z%3Dy7Uw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5%3DPmPFdhK6bUhT6WYxWMZtZWAJGNDc8VJF-8tC1z%3Dy7Uw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![brupm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brupm/32/746_2.png) [@brupm](https://discuss.elastic.co/u/brupm)\
**Post date:** [April 24, 2015, 6:47am UTC](https://discuss.elastic.co/t/combining-several-documents-in-a-terms-filter/23302/3 "2015-04-24T06:47:03Z")

</div>

Is there an upper limit of bool filters?

On Friday, April 17, 2015 at 10:18:38 PM UTC-7, vineeth mohan wrote:

> Hello Daniel ,
> 
> Feel free to use should clause in bool filter  
> [http://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-bool-filter.html](http://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-bool-filter.html)  
> .  
> Here you can give multiple terms filter and each of them can point to a  
> different document/field.
> 
> Thanks  
> Vineeth Mohan,  
> Elasticsearch consultant,  
> [qbox.io](http://qbox.io) ( Elasticsearch service provider [http://qbox.io/](http://qbox.io/))
> 
> On Sat, Apr 18, 2015 at 3:49 AM, Daniel Nill \<[danie...@gmail.com](mailto:danie...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > In the example here  
> > [Terms Filter | Reference [0.90] | Elastic](http://www.elastic.co/guide/en/elasticsearch/reference/0.90/query-dsl-terms-filter.html#_terms_lookup_twitter_example),  
> > it is indicated that the id field can only be for a single document. Is  
> > there a way to do:
> > 
> > curl -XGET localhost:9200/tweets/\_search -d '{  
> > "query" : {  
> > "filtered" : {  
> > "filter" : {  
> > "terms" : {  
> > "user" : {  
> > "index" : "users",  
> > "type" : "user",  
> > "id" : ["2", "3", "4"],  
> > "path" : "followers"  
> > },  
> > "\_cache\_key" : "user\_2\_friends"  
> > }  
> > }  
> > }  
> > }  
> > }'
> > 
> > Is the only way to get results for this to do a separate terms filter for  
> > each id?
> > 
> > --  
> > 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/d8032d4a-fdb7-48c9-9828-64253c5d4b90%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d8032d4a-fdb7-48c9-9828-64253c5d4b90%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/d8032d4a-fdb7-48c9-9828-64253c5d4b90%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d8032d4a-fdb7-48c9-9828-64253c5d4b90%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/835275d7-ab86-41f1-b149-a7d644120bed%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/835275d7-ab86-41f1-b149-a7d644120bed%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, 12:17am UTC](https://discuss.elastic.co/t/combining-several-documents-in-a-terms-filter/23302/4 "2017-07-06T00:17:57Z")

</div>


