I have a couple cases where I need to transform map fields into array fields that are sometimes nested a couple layers deep. These are the only fields that need to change in the document, so the other fields don't need any sort of transformation performed on them. My current approach is to copy over the unchanged fields at each level, like this:
[
{
"operation": "shift",
"spec": {
"agentsMetrics": {
"metricsPerAgent": {
"*": {
"$": "agentsMetrics.metricsPerAgent[#2].agentId",
"@": "agentsMetrics.metricsPerAgent[#2].value"
}
},
"*": {
"@": "agentsMetrics.&"
}
},
"skillsMetricsPerAgent": {
"metricsPerSkill": {
"*": {
"$": "skillsMetricsPerAgent.metricsPerSkill[#2].skillId",
"metricsPerAgent": {
"*": {
"$": "skillsMetricsPerAgent.metricsPerSkill[#4].metricsPerAgent[#2].agentId",
"@": "skillsMetricsPerAgent.metricsPerSkill[#4].metricsPerAgent[#2].value"
}
},
"*": {
"@": "skillsMetricsPerAgent.metricsPerSkill[#3].&"
}
}
},
"*": {
"@": "skillsMetricsPerAgent.&"
}
}
}
}
]
Where my input looks like this:
{
"agentsMetrics": {
"metricsTotals": {
"connectedEngagements": 70,
"nonInteractiveTotalHandlingTime": 309,
"totalHandlingTime": 47696,
"totalNonInteractiveChats": 2,
"totalInteractiveChats": 73
},
"metricsPerAgent": {
"645355412": {
"connectedEngagements": 2,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 1718,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 2
},
"645366912": {
"connectedEngagements": 1,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 488,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 1
}
}
},
"skillsMetricsPerAgent": {
"metricsTotals": {
"connectedEngagements": 70,
"nonInteractiveTotalHandlingTime": 309,
"totalHandlingTime": 47696,
"totalNonInteractiveChats": 2,
"totalInteractiveChats": 73
},
"metricsPerSkill": {
"641431612": {
"metricsTotals": {
"connectedEngagements": 7,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 6377,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 8
},
"metricsPerAgent": {
"645355312": {
"connectedEngagements": 1,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 115,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 1
},
"645365512": {
"connectedEngagements": 0,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 766,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 1
}
}
},
"1218517512": {
"metricsTotals": {
"connectedEngagements": 2,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 1379,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 2
},
"metricsPerAgent": {
"645367512": {
"connectedEngagements": 1,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 571,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 1
},
"645378812": {
"connectedEngagements": 1,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 808,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 1
}
}
}
}
}
}
Is there any way to target specific fields and manipulate them on their own while leaving everything else as it is? In this case I'd like to target metricsPerAgent and metricsPerSkill.