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


(Daniel Duarte Figueiredo) #1

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.


(Shay Banon) #2

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> 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.


(system) #3