# Best practices when I have two separated indexes that are related (post/author)

**URL:** <https://discuss.elastic.co/t/best-practices-when-i-have-two-separated-indexes-that-are-related-post-author/7634>\
**Category:** Elasticsearch\
**Created:** [May 10, 2012, 1:07pm UTC](https://discuss.elastic.co/t/best-practices-when-i-have-two-separated-indexes-that-are-related-post-author/7634 "2012-05-10T13:07:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Duarte\_Figuei](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@Daniel\_Duarte\_Figuei](https://discuss.elastic.co/u/Daniel_Duarte_Figuei)\
**Post date:** [May 10, 2012, 1:07pm UTC](https://discuss.elastic.co/t/best-practices-when-i-have-two-separated-indexes-that-are-related-post-author/7634/1 "2012-05-10T13:07:58Z")

</div>

Hello,  
I have an entity called "Post" with fields Id, Title, Text and so on. In a  
relational database, I would have a foreign key to the author's ID, and I  
would be able to get the author's name, occupation and other fields joining  
the two tables. Using Elastic Search, I'm indexing "Posts" and "Users" in  
different indexes, and the post entity has a field corresponding to the  
author's id. So let's suppose I will list all posts, and I need to show  
some field from the authors, like the UserName. What's the best practice?  
Should I list all the posts, and then get the users? I thought about having  
some author's fields in the post index, but then if the user updated the  
field, like changing its username, I would have to go post by post updating  
it. I want to keep them separated. I'm thinking about getting the posts,  
with authors' ids, and the having another query that lists the users with  
corresponding IDs. Is that correct? Can I make only one search query that  
lists the users I want? I mean something like the "WHERE Id IN (id1, id2,  
id3)" statement in SQL syntax.  
Thanks.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 13, 2012, 9:46am UTC](https://discuss.elastic.co/t/best-practices-when-i-have-two-separated-indexes-that-are-related-post-author/7634/2 "2012-05-13T09:46:04Z")

</div>

Yes, getting all the authors would work, if you have the authros ids, you  
can use mget to get all the authors for the mentioned ids.

On Thu, May 10, 2012 at 4:07 PM, Daniel Duarte Figueiredo \<  
[danielduartefigueiredo@gmail.com](mailto:danielduartefigueiredo@gmail.com)\> wrote:

> Hello,  
> I have an entity called "Post" with fields Id, Title, Text and so on. In a  
> relational database, I would have a foreign key to the author's ID, and I  
> would be able to get the author's name, occupation and other fields joining  
> the two tables. Using Elastic Search, I'm indexing "Posts" and "Users" in  
> different indexes, and the post entity has a field corresponding to the  
> author's id. So let's suppose I will list all posts, and I need to show  
> some field from the authors, like the UserName. What's the best practice?  
> Should I list all the posts, and then get the users? I thought about having  
> some author's fields in the post index, but then if the user updated the  
> field, like changing its username, I would have to go post by post updating  
> it. I want to keep them separated. I'm thinking about getting the posts,  
> with authors' ids, and the having another query that lists the users with  
> corresponding IDs. Is that correct? Can I make only one search query that  
> lists the users I want? I mean something like the "WHERE Id IN (id1, id2,  
> id3)" statement in SQL syntax.  
> Thanks.

---

<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:29am UTC](https://discuss.elastic.co/t/best-practices-when-i-have-two-separated-indexes-that-are-related-post-author/7634/3 "2017-07-06T03:29:07Z")

</div>


