# Modelling Social search to work at scale

**URL:** https://discuss.elastic.co/t/modelling-social-search-to-work-at-scale/108239
**Category:** Elasticsearch
**Created:** [November 18, 2017, 3:50pm UTC](https://discuss.elastic.co/t/modelling-social-search-to-work-at-scale/108239 "2017-11-18T15:50:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jalaj](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@jalaj](https://discuss.elastic.co/u/jalaj)
#### Post date: [November 18, 2017, 3:50pm UTC](https://discuss.elastic.co/t/modelling-social-search-to-work-at-scale/108239/1 "2017-11-18T15:50:11Z")

</div>

The question is more inclined towards how to model my data to satisfy all kind of queries at scale.  
I am trying to model search with Social factor to be in consideration .

Example use-case:-

1 - A user can post a status with a #hashtag.  
2 - A user can follow another user.  
3 - A user can like/comment on a status.

I would like answer to queries such as:-

1 - find all posts containing hashtag starting with #health(#heatlth , #healthIsLife i.e all tags with prefix #health). In this search those posts which are liked/commented by users I follow should come on top or have better score.

2 - Find all users whose name starts with Steve. Users who are followed by people I follow should come on top of search result.

3 - All users whom a user follow.

4 - All users following a user.

I tried modelling the above in a parent-child relationship model. However not everything was achieved.

Creating a new user.

/users/user/user1  
{  
user\_id:user1  
tags:[fitness , health , Illionios]  
location: xyz  
}

/users/user/user2  
{  
user\_id:user2  
tags:[GymFreak ,Austin]  
location: abc  
}  
When a user follow another user.

/users/follow/user2?parent=user1  
{  
user\_id:user2  
}  
With above however I am confused If user2 follow other users and they lay on same shard, how will it be achieved as a child cannot have multiple parents. And If I give a unique ID while inserting every child instead on userID, then I cannot answer my #4.  
Also , when searching for #2 , I can get the users but cannot get the attributes(which of my friends follow them) , since I cannot get child attributes in has\_child query.

How can I achieve my 1-4 with the above modelling efficiently ?

Note - A user can be followed by millions of users and can follow several thousand users.

Similarly , A post can be liked by million if users if its a celebrity post.

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [November 20, 2017, 9:22am UTC](https://discuss.elastic.co/t/modelling-social-search-to-work-at-scale/108239/2 "2017-11-20T09:22:23Z")

</div>

You won't be able to do this all in a single document structure. Look to setup an event driven format for tweets, then another one for users and their relationships.

Check out [https://www.elastic.co/elasticon/2015/sf/building-entity-centric-indexes](https://www.elastic.co/elasticon/2015/sf/building-entity-centric-indexes) for an example.

---

<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: [December 18, 2017, 9:22am UTC](https://discuss.elastic.co/t/modelling-social-search-to-work-at-scale/108239/3 "2017-12-18T09:22:24Z")

</div>

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