# Help in Relationship Mapping

**URL:** <https://discuss.elastic.co/t/help-in-relationship-mapping/20805>\
**Category:** Elasticsearch\
**Created:** [November 18, 2014, 7:50am UTC](https://discuss.elastic.co/t/help-in-relationship-mapping/20805 "2014-11-18T07:50:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asharan](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@asharan](https://discuss.elastic.co/u/asharan)\
**Post date:** [November 18, 2014, 7:50am UTC](https://discuss.elastic.co/t/help-in-relationship-mapping/20805/1 "2014-11-18T07:50:23Z")

</div>

I have related objects. Want to know what should be the mapping and how it  
should be stored in elastic search.  
For example base object is  
Blog  
id  
name  
subject  
body

multiple comments can be related to same blog.

Comment  
blog id  
comment id [type string]  
comment username [type string]  
comment review [type int value between 1-5]  
comment body [type string]

Usecase is

1. Given some blog properties and comment properties return the blog that  
matches the criteria
2. Given some comment properties and blog properties return all comment id  
that matches the criteria.

example:  
Blog  
id = "1"  
name = "blog1"  
subject = "new blog"  
body = "blog body"

Comment

```
blog id = "1"
comment id = "c1"
comment username = "name1"
comment review = 2
comment body = "body1"

blog id = "1"
comment id = "c2"
comment username = "name2"
comment review = 2
comment body = "body2"

blog id = "1"
comment id = "c3"
comment username = "name3"
comment review = 1
comment body = "body3"

blog id = "1"
comment id = "c4"
comment username = "name4"
comment review = 1
comment body = "body4"

```

Query

1. Given subject and review get all blog id (result should be blog with id

1. 

1. Given blog subject and comment review get all comment id (result should  
be comment id c1 and c2 for subject ="new blog" and review = 2)

What should be my mapping in Elastic search?

As per I know we can store related document in 3 ways  
data denormalized way (data will be duplicated)  
nested document (will not be able search for nested object)  
Parent child relationship (will be slow compared to other options)

Number of blog documents will be around 22 million and each document can  
have 15 comment.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6a2119f3-f4fc-498b-afb0-82609d2ce770%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6a2119f3-f4fc-498b-afb0-82609d2ce770%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:49am UTC](https://discuss.elastic.co/t/help-in-relationship-mapping/20805/2 "2017-07-06T00:49:18Z")

</div>


