7

I am relatively new to this elastic search. So, I have an index called post which contain documents like this:

{
"id": 1,
"link": "https:www.instagram.com/p/XXXXX/",
"profile_id": 11,
"like_count": 100,
"comment_count": 12
}

I have another index called profile which contain documents like this:

{
"id": 11,
"username": "superman",
"name": "Superman",
"followers": 12312
}

So, as you all can see, I have all profiles data under the index called profile and all posts data under the index called post. The "profile_id" present in the post document is linked with the "id" present in the profile document.

Is there any way, when I am querying the post index and filtering out the post documents the profile data will also appear along with the post document based on the "profile_id" present in the post document? Or somehow fetch the both data doing a multi-index search?

Thanks in advance, any help will be appreciated.

pdoherty926
  • 9,895
  • 4
  • 37
  • 68
Souvik Maity
  • 127
  • 1
  • 1
  • 7

1 Answers1

7

For the sake of performance, Elasticsearch encourages you to denormalize your data and model your documents accordingly to the responses you wish to get from your queries. However, in your case, I would suggest defining the relation post-profile by using a Join datatype (link to Elastic documentation) and using the parent-join queries to run your searches (link to Elastic documentation).

glenacota
  • 2,314
  • 1
  • 11
  • 18
  • Thank you very much glenacota. I think this is the way I should be going as the number of children is huge: https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child.html – Souvik Maity Jan 26 '20 at 20:12
  • 1
    Sadly the parent-child mapping has been deprecated, need to go for Join or have to redesign the document of the post object. Thank you for providing the right direction. – Souvik Maity Jan 27 '20 at 15:22
  • 2
    For multi index search Alias could be useful. And then you can query based on profile id and id. – Abinash Jan 28 '20 at 12:50