# Geospatial & social graph querying

**URL:** <https://discuss.elastic.co/t/geospatial-social-graph-querying/8854>\
**Category:** Elasticsearch\
**Created:** [August 27, 2012, 1:47am UTC](https://discuss.elastic.co/t/geospatial-social-graph-querying/8854 "2012-08-27T01:47:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fredrik\_Bjork](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fredrik_bjork/32/2755_2.png) [@Fredrik\_Bjork](https://discuss.elastic.co/u/Fredrik_Bjork)\
**Post date:** [August 27, 2012, 1:47am UTC](https://discuss.elastic.co/t/geospatial-social-graph-querying/8854/1 "2012-08-27T01:47:10Z")

</div>

Hi,

I'm building a application that needs to find mutual friends in a geo  
location.

Has anyone built anything similar using ElasticSearch before? Got any good  
recommendations on how to approach it?

Currently I'm using MongoDB where I've denormalized each user's friend list  
inside the collection where the geo coordinates are stored i.e:

{ \_id: ObjectId("5031a01f0536937d87002f84"),  
coordinates: [37.0, -122.0],  
user\_id: ObjectId("5031a01f0536937d87002f90"),  
friend\_ids: [ObjectId("5031a01f0536937d87002f89"),  
ObjectId("5031a01f0536937d87002f90")]  
}

In order to find mutual friends in that location I query using $in and the  
current user's friend\_ids and do the intersection client side.

This approach works OK for users with a few hundred friends, but query  
performance is poor for users with tens of thousands of friends.

Curious to hear how people would approach this using ElasticSeach or using  
other technologies.

--

---

<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:14am UTC](https://discuss.elastic.co/t/geospatial-social-graph-querying/8854/2 "2017-07-06T03:14:59Z")

</div>


