# Join kind of query

**URL:** <https://discuss.elastic.co/t/join-kind-of-query/5981>\
**Category:** Elasticsearch\
**Created:** [November 27, 2011, 1:24am UTC](https://discuss.elastic.co/t/join-kind-of-query/5981 "2011-11-27T01:24:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene\_Strokin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugene_strokin/32/1238_2.png) [@Eugene\_Strokin](https://discuss.elastic.co/u/Eugene_Strokin)\
**Post date:** [November 27, 2011, 1:24am UTC](https://discuss.elastic.co/t/join-kind-of-query/5981/1 "2011-11-27T01:24:23Z")

</div>

Hello,  
In one index I have 3 different types of documents. One, has IDs of  
other two.  
For example:  
Type 1:  
{ "post":{  
"properties":{  
"postId":{"type":"string", index:"not\_analyzed"},  
"description":{"type":"string"},  
"categoryId":{"type":"string", index:"not\_analyzed"},  
"userId":{"type":"string", index:"not\_analyzed"},  
} } }

Type 2:  
{ "user":{  
"properties":{  
"userId":{"type":"string", index:"not\_analyzed"},  
"screenName":{"type":"string", index:"not\_analyzed"},  
} } }

Type 3:  
{ "category":{  
"properties":{  
"categoryId":{"type":"string", index:"not\_analyzed"},  
"categoryName":{"type":"string", index:"not\_analyzed"},  
} } }

Currently I make 2 requests, one for the post, and the second one for  
the user and category.  
Could I get everything at once from a single request?

Thank you,  
Eugene S.

---

<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:** [November 27, 2011, 3:40am UTC](https://discuss.elastic.co/t/join-kind-of-query/5981/2 "2011-11-27T03:40:21Z")

</div>

Perhaps a stupid answer but why don't you index the post with the full content (author and category) ?

Seems like you are doing _YesSql_...

BTW, a better answer is perhaps : "have a look at the parent/child feature".

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

I don't use it myself but I think it can do what you want to do.

HTH,  
David 😉  
@dadoonet

Le 27 nov. 2011 à 02:24, Eugene Strokin [eugene@strokin.info](mailto:eugene@strokin.info) a écrit :

> Hello,  
> In one index I have 3 different types of documents. One, has IDs of  
> other two.  
> For example:  
> Type 1:  
> { "post":{  
> "properties":{  
> "postId":{"type":"string", index:"not\_analyzed"},  
> "description":{"type":"string"},  
> "categoryId":{"type":"string", index:"not\_analyzed"},  
> "userId":{"type":"string", index:"not\_analyzed"},  
> } } }
> 
> Type 2:  
> { "user":{  
> "properties":{  
> "userId":{"type":"string", index:"not\_analyzed"},  
> "screenName":{"type":"string", index:"not\_analyzed"},  
> } } }
> 
> Type 3:  
> { "category":{  
> "properties":{  
> "categoryId":{"type":"string", index:"not\_analyzed"},  
> "categoryName":{"type":"string", index:"not\_analyzed"},  
> } } }
> 
> Currently I make 2 requests, one for the post, and the second one for  
> the user and category.  
> Could I get everything at once from a single request?
> 
> Thank you,  
> Eugene S.

---

<div class="post-metadata">

**Author:** ![Eugene\_Strokin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugene_strokin/32/1238_2.png) [@Eugene\_Strokin](https://discuss.elastic.co/u/Eugene_Strokin)\
**Post date:** [November 27, 2011, 5:37am UTC](https://discuss.elastic.co/t/join-kind-of-query/5981/3 "2011-11-27T05:37:26Z")

</div>

Guilty as charged,.. looks like I need to review my strategy to get  
back to NoSQL 🙂  
In "post" I cannot index full content, because if categoryName will be  
updated, I'll need to update all posts from that category, and it  
could be thousands of them.  
Thanks for the link, I'll try to play with parent/child feature, I  
don't really understand how it works yet, but it looks promising. Only  
one concern I have right away, that I would need 2 parents for my  
posts, one for category and one for user, but may be it supports deep  
nesting, so my posts would have category as a parent, and category  
could have user as a parent.  
If someone has any suggestion, I'd greatly appreciate them, as well as  
any info related to the problem.  
Thanks in advance,  
Eugene S.

On Nov 26, 10:40 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> Perhaps a stupid answer but why don't you index the post with the full content (author and category) ?
> 
> Seems like you are doing _YesSql_...
> 
> BTW, a better answer is perhaps : "have a look at the parent/child feature".[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/index_.html)
> 
> I don't use it myself but I think it can do what you want to do.
> 
> HTH,  
> David 😉  
> @dadoonet
> 
> Le 27 nov. 2011 à 02:24, Eugene Strokin [eug...@strokin.info](mailto:eug...@strokin.info) a écrit :
> 
> > Hello,  
> > In one index I have 3 different types of documents. One, has IDs of  
> > other two.  
> > For example:  
> > Type 1:  
> > { "post":{  
> > "properties":{  
> > "postId":{"type":"string", index:"not\_analyzed"},  
> > "description":{"type":"string"},  
> > "categoryId":{"type":"string", index:"not\_analyzed"},  
> > "userId":{"type":"string", index:"not\_analyzed"},  
> > } } }
> 
> > Type 2:  
> > { "user":{  
> > "properties":{  
> > "userId":{"type":"string", index:"not\_analyzed"},  
> > "screenName":{"type":"string", index:"not\_analyzed"},  
> > } } }
> 
> > Type 3:  
> > { "category":{  
> > "properties":{  
> > "categoryId":{"type":"string", index:"not\_analyzed"},  
> > "categoryName":{"type":"string", index:"not\_analyzed"},  
> > } } }
> 
> > Currently I make 2 requests, one for the post, and the second one for  
> > the user and category.  
> > Could I get everything at once from a single request?
> 
> > Thank you,  
> > Eugene S.

---

<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:** [November 27, 2011, 7:40am UTC](https://discuss.elastic.co/t/join-kind-of-query/5981/4 "2011-11-27T07:40:15Z")

</div>

This is about the same use case I have at work.  
To be honest, I don't know yet how I will handle it. By now, I reindex every content that has been updated.

I'm wondering how I should store my documents in CouchDb and how I will update them... Perhaps, get all documents, change the value and push it again to CouchDb ? Looks like reindexing...

BTW, I don't think you can have two parents with ES as the API doesn't seem to support it.

David 😉  
@dadoonet

Le 27 nov. 2011 à 06:37, Eugene Strokin [eugene@strokin.info](mailto:eugene@strokin.info) a écrit :

> Guilty as charged,.. looks like I need to review my strategy to get  
> back to NoSQL 🙂  
> In "post" I cannot index full content, because if categoryName will be  
> updated, I'll need to update all posts from that category, and it  
> could be thousands of them.  
> Thanks for the link, I'll try to play with parent/child feature, I  
> don't really understand how it works yet, but it looks promising. Only  
> one concern I have right away, that I would need 2 parents for my  
> posts, one for category and one for user, but may be it supports deep  
> nesting, so my posts would have category as a parent, and category  
> could have user as a parent.  
> If someone has any suggestion, I'd greatly appreciate them, as well as  
> any info related to the problem.  
> Thanks in advance,  
> Eugene S.
> 
> On Nov 26, 10:40 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > Perhaps a stupid answer but why don't you index the post with the full content (author and category) ?
> > 
> > Seems like you are doing _YesSql_...
> > 
> > BTW, a better answer is perhaps : "have a look at the parent/child feature".[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/index_.html)
> > 
> > I don't use it myself but I think it can do what you want to do.
> > 
> > HTH,  
> > David 😉  
> > @dadoonet
> > 
> > Le 27 nov. 2011 à 02:24, Eugene Strokin [eug...@strokin.info](mailto:eug...@strokin.info) a écrit :
> > 
> > > Hello,  
> > > In one index I have 3 different types of documents. One, has IDs of  
> > > other two.  
> > > For example:  
> > > Type 1:  
> > > { "post":{  
> > > "properties":{  
> > > "postId":{"type":"string", index:"not\_analyzed"},  
> > > "description":{"type":"string"},  
> > > "categoryId":{"type":"string", index:"not\_analyzed"},  
> > > "userId":{"type":"string", index:"not\_analyzed"},  
> > > } } }
> > 
> > > Type 2:  
> > > { "user":{  
> > > "properties":{  
> > > "userId":{"type":"string", index:"not\_analyzed"},  
> > > "screenName":{"type":"string", index:"not\_analyzed"},  
> > > } } }
> > 
> > > Type 3:  
> > > { "category":{  
> > > "properties":{  
> > > "categoryId":{"type":"string", index:"not\_analyzed"},  
> > > "categoryName":{"type":"string", index:"not\_analyzed"},  
> > > } } }
> > 
> > > Currently I make 2 requests, one for the post, and the second one for  
> > > the user and category.  
> > > Could I get everything at once from a single request?
> > 
> > > Thank you,  
> > > Eugene S.

---

<div class="post-metadata">

**Author:** ![Eugene\_Strokin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugene_strokin/32/1238_2.png) [@Eugene\_Strokin](https://discuss.elastic.co/u/Eugene_Strokin)\
**Post date:** [November 27, 2011, 3:59pm UTC](https://discuss.elastic.co/t/join-kind-of-query/5981/5 "2011-11-27T15:59:49Z")

</div>

In Solr I did the same, just stored everything in a post document, and  
reindex all posts, if category or user name changed. I was hoping in  
ES I could do this more efficient. But looks like Parent/Child feature  
also wouldn't help, because it allows to search on child but return  
parent. But in my case I need to search on children and parents, and  
get all children with it's parents together.  
Well, I'll play with it little bit more, and if nothing is found will  
get back to reindexing all posts.  
Will keep you posted, looks like this is not only my problem, people  
could get such use cases in their projects))

On Nov 27, 2:40 am, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> This is about the same use case I have at work.  
> To be honest, I don't know yet how I will handle it. By now, I reindex every content that has been updated.
> 
> I'm wondering how I should store my documents in CouchDb and how I will update them... Perhaps, get all documents, change the value and push it again to CouchDb ? Looks like reindexing...
> 
> BTW, I don't think you can have two parents with ES as the API doesn't seem to support it.
> 
> David 😉  
> @dadoonet
> 
> Le 27 nov. 2011 à 06:37, Eugene Strokin [eug...@strokin.info](mailto:eug...@strokin.info) a écrit :
> 
> > Guilty as charged,.. looks like I need to review my strategy to get  
> > back to NoSQL 🙂  
> > In "post" I cannot index full content, because if categoryName will be  
> > updated, I'll need to update all posts from that category, and it  
> > could be thousands of them.  
> > Thanks for the link, I'll try to play with parent/child feature, I  
> > don't really understand how it works yet, but it looks promising. Only  
> > one concern I have right away, that I would need 2 parents for my  
> > posts, one for category and one for user, but may be it supports deep  
> > nesting, so my posts would have category as a parent, and category  
> > could have user as a parent.  
> > If someone has any suggestion, I'd greatly appreciate them, as well as  
> > any info related to the problem.  
> > Thanks in advance,  
> > Eugene S.
> 
> > On Nov 26, 10:40 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> > 
> > > Perhaps a stupid answer but why don't you index the post with the full content (author and category) ?
> 
> > > Seems like you are doing _YesSql_...
> 
> > > BTW, a better answer is perhaps : "have a look at the parent/child feature".[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/index_.html)
> 
> > > I don't use it myself but I think it can do what you want to do.
> 
> > > HTH,  
> > > David 😉  
> > > @dadoonet
> 
> > > Le 27 nov. 2011 à 02:24, Eugene Strokin [eug...@strokin.info](mailto:eug...@strokin.info) a écrit :
> 
> > > > Hello,  
> > > > In one index I have 3 different types of documents. One, has IDs of  
> > > > other two.  
> > > > For example:  
> > > > Type 1:  
> > > > { "post":{  
> > > > "properties":{  
> > > > "postId":{"type":"string", index:"not\_analyzed"},  
> > > > "description":{"type":"string"},  
> > > > "categoryId":{"type":"string", index:"not\_analyzed"},  
> > > > "userId":{"type":"string", index:"not\_analyzed"},  
> > > > } } }
> 
> > > > Type 2:  
> > > > { "user":{  
> > > > "properties":{  
> > > > "userId":{"type":"string", index:"not\_analyzed"},  
> > > > "screenName":{"type":"string", index:"not\_analyzed"},  
> > > > } } }
> 
> > > > Type 3:  
> > > > { "category":{  
> > > > "properties":{  
> > > > "categoryId":{"type":"string", index:"not\_analyzed"},  
> > > > "categoryName":{"type":"string", index:"not\_analyzed"},  
> > > > } } }
> 
> > > > Currently I make 2 requests, one for the post, and the second one for  
> > > > the user and category.  
> > > > Could I get everything at once from a single request?
> 
> > > > Thank you,  
> > > > Eugene S.

---

<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:47am UTC](https://discuss.elastic.co/t/join-kind-of-query/5981/6 "2017-07-06T03:47:25Z")

</div>


