# Filtering a products index by different users

**URL:** <https://discuss.elastic.co/t/filtering-a-products-index-by-different-users/164543>\
**Category:** Elasticsearch\
**Created:** [January 16, 2019, 9:11pm UTC](https://discuss.elastic.co/t/filtering-a-products-index-by-different-users/164543 "2019-01-16T21:11:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roman731](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@roman731](https://discuss.elastic.co/u/roman731)\
**Post date:** [January 16, 2019, 9:11pm UTC](https://discuss.elastic.co/t/filtering-a-products-index-by-different-users/164543/1 "2019-01-16T21:11:13Z")

</div>

Hello,

I'm kind of new to Elasticsearch and am looking to solve the following problem:

I have an index of products. They have regular fields such as id, name, brand etc. Querying this index is working great, however I want to limit the products which are returned for specific users.

Say I have 5 products who’s IDs go from 1-5

Id: 1, name: “Product One”, brand: “Fake Brand”  
Id: 2, name: “Product Two”, brand: “Fake Brand”  
Id: 3, name: “Product Three”, brand: “Fake Brand”  
Id: 4, name: “Product Four”, brand: “Fake Brand”  
Id: 5, name: “Product Five”, brand: “Fake Brand”

If there’s no filter, and I search for brand: “Fake Brand”, I get 5 results.

But I want to add this functionality: Say I have two users. User 1 is only able to “see” product IDs 1, 2, and 5. And User 2 is only able to “see” a different subset, say, product IDs 1, 2, 4 and 5.

So if user 1 searches for brand: “Fake Brand”, he only gets back product with IDs 1, 2, and 5. Where as if user 2 searches for brand: “Fake Brand”, he only gets back products with IDs 1, 2, 4 and 5.

Is there a way to add a “user id” to this products query and then store somewhere else what products a user is able to see?

In SQL I would probably have a different table storing what products each user can see and then just do a join. But using ES I think I either have to have two separate indexes or to use nested or has\_child/has\_parent queries but I’m not entirely sure how to implement it.

Any help or examples are appreciated.

Thank you.

---

<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:** [February 13, 2019, 9:11pm UTC](https://discuss.elastic.co/t/filtering-a-products-index-by-different-users/164543/2 "2019-02-13T21:11:13Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
