# How to implement a user specific search?

**URL:** <https://discuss.elastic.co/t/how-to-implement-a-user-specific-search/5564>\
**Category:** Elasticsearch\
**Created:** [October 11, 2011, 2:37pm UTC](https://discuss.elastic.co/t/how-to-implement-a-user-specific-search/5564 "2011-10-11T14:37:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmeier](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@pmeier](https://discuss.elastic.co/u/pmeier)\
**Post date:** [October 11, 2011, 2:37pm UTC](https://discuss.elastic.co/t/how-to-implement-a-user-specific-search/5564/1 "2011-10-11T14:37:36Z")

</div>

Hi all,

I have a bunch of items to search. Normally I would put them in one index  
and they are searchable. But I have the restriction that every user should  
only see a specific subset of all the items.

The problem is I don't know how to implement this performantly. One option  
would be to include the user-ids who are allowed to search or see the item  
as a field. The second one would be to create a own index for every user -  
but here's the question how the performance is if there are 5000+ users or  
maybe even more.

Is there another elegant solution to this problem I haven't found out yet?  
Searching didn't return anything useful to me.

Thanks for every reply and indea.

Patrick Meier.

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [October 11, 2011, 2:42pm UTC](https://discuss.elastic.co/t/how-to-implement-a-user-specific-search/5564/2 "2011-10-11T14:42:20Z")

</div>

Hi Patrick

> I have a bunch of items to search. Normally I would put them in one  
> index and they are searchable. But I have the restriction that every  
> user should only see a specific subset of all the items.

You can use alias filters:

- You have one index which contains data for all your users.
- You have one alias for each user, which specifies the filter  
to be applied for that alias (eg { term =\> { user\_id =\> 123}}
- Your users query your index via their alias.

> **[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.

clint

---

<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:** [October 11, 2011, 3:08pm UTC](https://discuss.elastic.co/t/how-to-implement-a-user-specific-search/5564/3 "2011-10-11T15:08:28Z")

</div>

That's really a cool feature that I was not aware about.

Thanks for the question and the answer.

David 😉

Le 11 oct. 2011 à 16:42, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com) a écrit :

> Hi Patrick
> 
> > I have a bunch of items to search. Normally I would put them in one  
> > index and they are searchable. But I have the restriction that every  
> > user should only see a specific subset of all the items.
> 
> You can use alias filters:
> 
> - You have one index which contains data for all your users.
> - You have one alias for each user, which specifies the filter  
> to be applied for that alias (eg { term =\> { user\_id =\> 123}}
> - Your users query your index via their alias.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html)
> 
> clint

---

<div class="post-metadata">

**Author:** ![pmeier](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@pmeier](https://discuss.elastic.co/u/pmeier)\
**Post date:** [October 12, 2011, 8:07am UTC](https://discuss.elastic.co/t/how-to-implement-a-user-specific-search/5564/4 "2011-10-12T08:07:27Z")

</div>

Hi Clinton,

thanks a lot for your quick reply. This was the elegant solution I was  
searching for.

Patrick Meier

On 11 Okt., 16:42, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:

> Hi Patrick
> 
> > I have a bunch of items to search. Normally I would put them in one  
> > index and they are searchable. But I have the restriction that every  
> > user should only see a specific subset of all the items.
> 
> You can use alias filters:
> 
> - You have one index which contains data for all your users.
> - You have one alias for each user, which specifies the filter  
> to be applied for that alias (eg { term =\> { user\_id =\> 123}}
> - Your users query your index via their alias.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliase)...
> 
> clint

---

<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:52am UTC](https://discuss.elastic.co/t/how-to-implement-a-user-specific-search/5564/5 "2017-07-06T03:52:19Z")

</div>


