# Optimal way to restrict search results

**URL:** <https://discuss.elastic.co/t/optimal-way-to-restrict-search-results/3235>\
**Category:** Elasticsearch\
**Created:** [August 19, 2010, 7:18am UTC](https://discuss.elastic.co/t/optimal-way-to-restrict-search-results/3235 "2010-08-19T07:18:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zellster](https://avatars.discourse-cdn.com/v4/letter/z/ea666f/32.png) [@zellster](https://discuss.elastic.co/u/zellster)\
**Post date:** [August 19, 2010, 7:18am UTC](https://discuss.elastic.co/t/optimal-way-to-restrict-search-results/3235/1 "2010-08-19T07:18:02Z")

</div>

Hello,

I am curious how one could efficiently filter results in a social network  
using ElasticSearch. Let's say that a user wants to search for a phrase,  
but only among documents authored by his friends. The user may have tens of  
thousands (or more) friends which can change fairly often.

Using an OR Filter should work, but could result in huge JSON requests. A  
FilterBuilder could be used instead, but does not seem very reusable. I was  
not able to find the best Lucene solution, as it is not clear to me whether  
a custom filter, multi phrase query, or other is best.

Any suggestions appreciated.

--  
Adam  
[zellster@gmail.com](mailto:zellster@gmail.com)

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 19, 2010, 1:46pm UTC](https://discuss.elastic.co/t/optimal-way-to-restrict-search-results/3235/2 "2010-08-19T13:46:17Z")

</div>

if the friends field is not analyzed (maybe by id?), then you can use the  
terms filter, and add a term per friend. Still be long, but not as long and  
more efficient then other solutions.

-shay.banon

On Thu, Aug 19, 2010 at 10:18 AM, Adam Zell [zellster@gmail.com](mailto:zellster@gmail.com) wrote:

> Hello,
> 
> I am curious how one could efficiently filter results in a social network  
> using Elasticsearch. Let's say that a user wants to search for a phrase,  
> but only among documents authored by his friends. The user may have tens of  
> thousands (or more) friends which can change fairly often.
> 
> Using an OR Filter should work, but could result in huge JSON requests. A  
> FilterBuilder could be used instead, but does not seem very reusable. I was  
> not able to find the best Lucene solution, as it is not clear to me whether  
> a custom filter, multi phrase query, or other is best.
> 
> Any suggestions appreciated.
> 
> --  
> Adam  
> [zellster@gmail.com](mailto:zellster@gmail.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, 4:20am UTC](https://discuss.elastic.co/t/optimal-way-to-restrict-search-results/3235/3 "2017-07-06T04:20:33Z")

</div>

Closed on July 6, 2017, 4:20am UTC


