Add nested document from another index


(Baljeet Dogra) #1

I have a requirement to lookup another index in elasticsearch and when the document is found I need to embed the entire document in another document in another index.

employee-index (assume already populated)
{ _id: emp01, name: David, role: admin}
{ _id: emp02, name: John, role: developer, country: USA}
{ _id: emp03, name: Manoj, role: marketing, type: external}

salary-index
salary data has employee id
$10000, emp01
$14000, emp02
$17000, emp03

When inserting salary data I need to lookup employee index using the id which I can do using the elasticsearch plugin. But how do I fetch the entire document and nest it in the salary document without having to fetch individual fields. I do not want to use fields because the document schema may be different.

Intended document in salary index where employee is nested type

{
_id: 1,
salary: $10000,
employee : { _id: emp01, name: David, role: admin}
}

{
_id: 2,
salary: $14000,
employee : { _id: emp02, name: John, role: developer, country: USA }
}


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.