如何使用Jolt转换进行嵌套/递归转换。 在将其输入到后续服务之前,我试图获得所需的输出。
我的输入是
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1.000438,
"hits": [
{
"_id": "AV-SJgvFPkCspwtrqHA1",
"_source": {
"tenant_id": "tenant1",
"session_id": "e780ff74-d33e-4024-9bb7-971f067484ea"
},
"inner_hits": {
"network_events": {
"hits": {
"total": 1,
"max_score": 6.0892797,
"hits": [
{
"_source": {
"event_id": 16,
"response_time": 0,
"url": "http://www.google.com/"
}
},
{
"_source": {
"event_id": 18,
"response_time": 1,
"url": "http://www.google1.com/"
}
}
]
}
}
}
},
{
"_id": "BS-SJgvFPkCspwtrqHA1",
"_source": {
"tenant_id": "tenant2",
"session_id": "f4939272-d33e-4024-9bb7-971f067484ea"
},
"inner_hits": {
"network_events": {
"hits": {
"total": 1,
"max_score": 6.0892797,
"hits": [
{
"_source": {
"event_id": 18,
"response_time": 4,
"url": "http://www.google4.com/"
}
},
{
"_source": {
"event_id": 5,
"response_time": 5,
"url": "http://www.google5.com/"
}
}
]
}
}
}
}
]
}
}
所需的输出是
{
“sessions”: [
{
session_id : “S1”,
tenant_id : “T1”,
network_events : [
{
“url”: “A”,
“response_time” : 22
},
{
“url”: “B,
“response_time” : 1
}
]
},
{
session_id : “S2”,
tenant_id : “T1”,
network_events : [
{
“url”: “C”,
“response_time” : 22
}
]
}
]
}
这是否可以使用Jolt。我尝试了使用示例示例的多个组合,但没有得到太多。
我是Jolt的新手,所以我们将不胜感激。
答案 0 :(得分:1)
[
{
"operation": "shift",
"spec": {
"hits": {
"hits": {
"*": {
"_source": {
"tenant_id": "sessions[#3].tenant_id",
"session_id": "sessions[#3].session_id"
},
"inner_hits": {
"network_events": {
"hits": {
"hits": {
"*": {
"_source": {
"@": "sessions[#8].network_events.[]"
}
}
}
}
}
}
}
}
}
}
},
{
"operation": "remove",
"spec": {
"sessions": {
"*": {
"network_events": {
"*": {
"data_in": "",
"data_out": "",
"attributes": "",
"event_id": "",
"parent_url": "",
"resource_type": ""
}
}
}
}
}
}
]