Combining records that have the same id with a query

I have records for call logs that i want to query and combine into 1 result per record instead of 2. This is for logging of calls from one person to another. The person that initiates the call has the 'initiator' flag set to true and the receiver has that flag set to false.

I can query for each of the people separately and that works fine, the problem is when i want to get a record of the complete transaction between the two, i get back both sets of records, while i only want one record with data from both combined.

Below are my records in ES with a sample of the output that i want, that i cant figure out how to write a query for.

{ ... other records }
// Outbound record
{
  "id": 211,
  "initiator" : true,
  "source_name": "John Doe",
  "destination_name": "",
  "type": 0
}

// Inbound record
{
  "id": 211,
  "initiator" : false,
  "source_name": "",
  "destination_name": "Jane Smith",
  "type": 4
}
{ ... other records }


----- Desired output
{
  "id": 211,
  "initiator" : true,
  "source_name": "John Doe",
  "destination_name": "Jane Smith",
  "type": 0
}

Welcome to our community! :smiley:

Will Collapse search results | Elasticsearch Guide [8.6] | Elastic do what you want?

Ive run across that in the docs but im not entirely sure how to use it, the documentation its not very clear to me. My results could change based on the 'initiator' and 'type' fields.

If 'initiator' == true and 'type' == 0 then i want the result output one way, if 'initiator' == true and 'type' == 4 then the results should be slightly different. Can collapse do that?

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