# How to organize related types

**URL:** <https://discuss.elastic.co/t/how-to-organize-related-types/5445>\
**Category:** Elasticsearch\
**Created:** [September 24, 2011, 12:51am UTC](https://discuss.elastic.co/t/how-to-organize-related-types/5445 "2011-09-24T00:51:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![goodieboy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/goodieboy/32/3026_2.png) [@goodieboy](https://discuss.elastic.co/u/goodieboy)\
**Post date:** [September 24, 2011, 12:51am UTC](https://discuss.elastic.co/t/how-to-organize-related-types/5445/1 "2011-09-24T00:51:31Z")

</div>

Hi,

I'm building a simple blog for myself as a way to learn ES. I have a pretty  
typical set of models, Post, PostTag, PostCategory, PostComment etc.. I'm  
wondering what the best way to store/index these models is -- specifically,  
with documents that are related to other types. Does ES handle sql-like  
joins with related documents? For example, would Comments be a separate  
type, or would they be nested within the Post from which they belong?

Apologies for the n00bness.

Matt

---

<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:** [September 24, 2011, 5:30am UTC](https://discuss.elastic.co/t/how-to-organize-related-types/5445/2 "2011-09-24T05:30:21Z")

</div>

IMO, I would think about what document type I want to search for.

Are you looking for Posts ? Comments ? I think that your need is to find posts and only that.

So, I would only index posts with all its fields (categories, comments, ...)  
Each Time a new comment is added, just push again the full post to ES.

That's the way I will do it.

BTW it's difficult to stop thinking SQL in a NOSQL world. Things are differents and we don't need to split datas into relationnal documents.

David 😉

Le 24 sept. 2011 à 02:51, goodieboy [goodieboy@gmail.com](mailto:goodieboy@gmail.com) a écrit :

> Hi,
> 
> I'm building a simple blog for myself as a way to learn ES. I have a pretty typical set of models, Post, PostTag, PostCategory, PostComment etc.. I'm wondering what the best way to store/index these models is -- specifically, with documents that are related to other types. Does ES handle sql-like joins with related documents? For example, would Comments be a separate type, or would they be nested within the Post from which they belong?
> 
> Apologies for the n00bness.
> 
> Matt

---

<div class="post-metadata">

**Author:** ![goodieboy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/goodieboy/32/3026_2.png) [@goodieboy](https://discuss.elastic.co/u/goodieboy)\
**Post date:** [September 24, 2011, 1:24pm UTC](https://discuss.elastic.co/t/how-to-organize-related-types/5445/3 "2011-09-24T13:24:18Z")

</div>

Thanks! That's very helpful.

One thing I'm not clear on how to do is hierarchical relationships. I want  
to store the comments for a post in the post document. A comment can have a  
parent etc... What would a mapping look like to handle this situation? What  
if I wanted to query posts on a particular comment author name?

Thanks,  
Matt

---

<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:53am UTC](https://discuss.elastic.co/t/how-to-organize-related-types/5445/4 "2017-07-06T03:53:38Z")

</div>


