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
RabBit_BR
(andre.coelho)
April 28, 2022, 4:05pm
2
Hi!
I think you should do this merge on the application side but I send the post below, hope it helps.
You can use a transform for it. The group_by must be based on a common criteria, e.g. a common id.
For the combining step, you can use a scripted metric, e.g.:
"all_docs": {
"scripted_metric": {
"init_script": "state.docs = []",
"map_script": "state.docs.add(new HashMap(params['_source']))",
"combine_script": "return state.docs",
"reduce_script": "def docs = []; for (s in states) {for (d in s) { docs.add(d);}}return docs"
}
}
this would create an array with the original do…
2 Likes
Hi Andre,
Thank you for this solution. i will try it today..
Hope it works for me.
system
(system)
Closed
May 27, 2022, 8:01am
4
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.