I have a requirement to aggregate fields from 2 or more document in a single index(Pages index), and the relation between these documents is defined in another index(Relations index).
localhost:9200/pages/page/0277e82d-6c48-4557-bfa5-aadf9bcd52f6
contains
{
_index: "pages",
_type: "page",
_id: "0277e82d-6c48-4557-bfa5-aadf9bcd52f6", // this is institute id
_score: 1,
_source: {
academics: [],
display_picture: {},
established_date: "1869-01-01 00:00:00",
featured: "yes",
follower_count: 82,
id: "0277e82d-6c48-4557-bfa5-aadf9bcd52f6",
institute_type: "public (autonomous)",
location: {},
profiles_added_to_count: 74,
status: "1",
subtype: "page_institution",
title: "St. Xaviers College | Mumbai",
type: "page"
}
}
and localhost:9200/pages/page/5007e337-7a1c-4668-9204-5cf77b3aed97
contains
{
_index: "pages",
_type: "page",
_id: "5007e337-7a1c-4668-9204-5cf77b3aed97", // this is recruiter id
_score: 1,
_source: {
featured: "no",
follower_count: 0,
id: "5007e337-7a1c-4668-9204-5cf77b3aed97",
profiles_added_to_count: 0,
status: "0",
subtype: "page_organisation",
title: "Oracle Financial Corporation",
type: "page"
}
}
now these 2 are related, and the relation is defined in second index (Relations).
localhost:9200/relations/recruiter/0277e82d-6c48-4557-bfa5-aadf9bcd52f6
contains
{
_index: "relations",
_type: "recruiter",
_id: "0277e82d-6c48-4557-bfa5-aadf9bcd52f6",
_version: 1,
found: true,
_source: {
e6231b19-1489-42a1-951e-90ccd574fcd3: {
id: "e6231b19-1489-42a1-951e-90ccd574fcd3", // this is recruiter id
type: "page"
},
5007e337-7a1c-4668-9204-5cf77b3aed97: {
id: "5007e337-7a1c-4668-9204-5cf77b3aed97", // this is recruiter id
type: "page"
}
}
}
an institute can have multiple recruiters, so the relation here contains 2 different recruiter ids.
So my requirement is to join the above two documents(index as Pages) by their relations(index as Relations) for querying and getting aggregation based on the overall results.
I want to query over the Pages index, with name Xaviers, and want to get the recruiters details too in the result with aggregation of recruiters too.
Can someone please let me know how to achieve this.