# Many to many relationships

**URL:** <https://discuss.elastic.co/t/many-to-many-relationships/12515>\
**Category:** Elasticsearch\
**Created:** [June 21, 2013, 8:42pm UTC](https://discuss.elastic.co/t/many-to-many-relationships/12515 "2013-06-21T20:42:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simran\_Butalia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simran_butalia/32/2270_2.png) [@Simran\_Butalia](https://discuss.elastic.co/u/Simran_Butalia)\
**Post date:** [June 21, 2013, 8:42pm UTC](https://discuss.elastic.co/t/many-to-many-relationships/12515/1 "2013-06-21T20:42:45Z")

</div>

Our application is based on the following model Project -\> Workbooks -\>  
Content

Users can have many Projects and many Workbooks. Users can Invite other  
users to collaborate on their Projects/Workbooks.

I would like setup elasticsearch in way that it allows users to search for  
any content within the Projects/workbook they have created or have  
subscribed to.

What is the best practice to restrict search results to a specific user or  
model elastic search to enforce this?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [June 22, 2013, 12:15am UTC](https://discuss.elastic.co/t/many-to-many-relationships/12515/2 "2013-06-22T00:15:13Z")

</div>

Basically, I would say: add in your workbook/project all users that can have an access (array of users). It means update all projects/workbooks each a user grant rights to another one.

Does it help?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 21 juin 2013 à 22:42, Simran Butalia [sbutalia@gmail.com](mailto:sbutalia@gmail.com) a écrit :

Our application is based on the following model Project -\> Workbooks -\> Content

Users can have many Projects and many Workbooks. Users can Invite other users to collaborate on their Projects/Workbooks.

I would like setup elasticsearch in way that it allows users to search for any content within the Projects/workbook they have created or have subscribed to.

What is the best practice to restrict search results to a specific user or model elastic search to enforce this?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ben\_Hundley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ben_hundley/32/1853_2.png) [@Ben\_Hundley](https://discuss.elastic.co/u/Ben_Hundley)\
**Post date:** [June 22, 2013, 12:34am UTC](https://discuss.elastic.co/t/many-to-many-relationships/12515/3 "2013-06-22T00:34:34Z")

</div>

Getting all projects a user has subscribed to:

curl localhost:9200/projects/\_search -d '{  
"query" : {  
"constant\_score" : {  
"filter" : {  
"in" : { "user\_id" : ["\<user\_id\>"] }  
}  
}  
}  
}'

Getting all users for a project:

curl localhost:9200/users/\_search -d '{  
"query" : {  
"constant\_score" : {  
"filter" : {  
"in" : { "project\_id" : ["\<project\_id\>"] }  
}  
}  
}  
}'

---

<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, 2:29am UTC](https://discuss.elastic.co/t/many-to-many-relationships/12515/4 "2017-07-06T02:29:55Z")

</div>


