Sesam文档显示了一种扁平化列表的方法,但是如何扁平化这样一个更深层次的结构呢?该文档指定它不能递归展平。
"logdata": {
"metrics": {
"entities": {
"entities_per_second": "~f463.18217846895715"
}
}
}
答案 0 :(得分:0)
您可以使用DTL tranfsorm进行递归展平,请参见以下示例:
{
"_id": "recursive-flattening",
"type": "pipe",
"source": {
"type": "embedded",
"entities": [{
"_id": "foo",
"value": {
"logdata": {
"metrics": {
"entities": {
"entities_per_second": "~f463.18217846895715"
}
}
}
}
}]
},
"transform": {
"type": "dtl",
"rules": {
"default": [
["copy", "*"],
["add", "flattened",
["apply", "flatten-dict", "_S.value"]
]
],
"do-flatten": [
["if",
["is-dict", "_S.value"],
["merge",
["apply", "do-flatten",
["key-values",
["map-dict",
["concat", "_S.key", "_", "_."], "_.", "_S.value"]
]
]
],
["add", "_S.key", "_S.value"]
]
],
"flatten-dict": [
["merge",
["apply", "do-flatten",
["key-values", "_S."]
]
]
]
}
}
}
这应该输出以下内容:
{
"flattened": {
"logdata_metrics_entities_entities_per_second": "~f463.18217846895715"
},
"value": {
"logdata": {
"metrics": {
"entities": {
"entities_per_second": "~f463.18217846895715"
}
}
}
}
}