Merge fields between documents

Hi everyone,

I have 2 kinds of docments in an Elasticsearch index.
Document 1:

{
	"_id": "xxxxxxx",
	"internal_id": "123456",
	"message": "LOREM IPSUM"
}

Document 2:

{
	"_id": "yyyyyyy",
	"internal_id": "123456",
	"date": "2022-04-28",
	"method": "GET"
}

Is there a way to query the index and have such a result:

{
	"_id": "yyyyyyy",
	"internal_id": "123456",
	"date": "2022-04-28",
	"method": "GET",
	"message": "LOREM IPSUM"
}

A query that is able to "inject" a field from document 1 into document 2 in its result.
If not possible, how to join on the same field between 2 documents.

Thanx a lot for your help and answers.

Khaled

Hi!

I think you should do this merge on the application side but I send the post below, hope it helps.

2 Likes

Hi Andre,

Thank you for this solution. i will try it today..
Hope it works for me.