# Recommended way to query friends or friends of friends in social graph

**URL:** https://discuss.elastic.co/t/recommended-way-to-query-friends-or-friends-of-friends-in-social-graph/4644
**Category:** Elasticsearch
**Created:** [June 16, 2011, 8:45pm UTC](https://discuss.elastic.co/t/recommended-way-to-query-friends-or-friends-of-friends-in-social-graph/4644 "2011-06-16T20:45:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Andreas\_Saebjoernsen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andreas_saebjoernsen/32/2904_2.png) [@Andreas\_Saebjoernsen](https://discuss.elastic.co/u/Andreas_Saebjoernsen)
#### Post date: [June 16, 2011, 8:45pm UTC](https://discuss.elastic.co/t/recommended-way-to-query-friends-or-friends-of-friends-in-social-graph/4644/1 "2011-06-16T20:45:15Z")

</div>

I am working on a web application for getting people together by  
making it easy to create and discover events, and we'd like to  
recommend events using elastic search. Events that are attended by  
friends and/or friends of friends should show up with a higher  
relevancy. We are currently not sure how to best query for this.

This is pseudo code for our data model:

user

- has many users as friends ( a single array of id's)

event

- has many users as attendees (a single array of id's)

We are getting friend data from Facebook so there are going to be many  
more friends and friends of friends than events.

Any tips on how to create a query that lists upcoming events,  
returning events attended by friends and/or friends of friends with a  
higher relevancy, is greatly appreciated.

Best,  
Andy

---

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [June 20, 2011, 10:59am UTC](https://discuss.elastic.co/t/recommended-way-to-query-friends-or-friends-of-friends-in-social-graph/4644/2 "2011-06-20T10:59:51Z")

</div>

when I 'xy' have a friend timetabling and pannous I could use the  
following to boost the results and get my friends first:

user:(timetabling^10 OR pannous^10 OR _:_)

This should work for a lot of friends. You could use this query type:

[http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html)

Another possibility would be to create two queries and boosting the  
friend query + combining it with OR. To avoid a lot of boolean OR  
clauses you could then construct the friend query via 'forUser:xy',  
but you'll need to attach the forUser information while indexing (less  
flexible when friends change often)

BTW: lucene has an upper limitation for 1024 bool clauses but you can  
increase it () or ES already has it by default, not sure.

Regards,  
Peter.

--  
[http://jetsli.de/tweets](http://jetsli.de/tweets)

---

<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:03am UTC](https://discuss.elastic.co/t/recommended-way-to-query-friends-or-friends-of-friends-in-social-graph/4644/3 "2017-07-06T04:03:08Z")

</div>


