【发布时间】:2020-12-07 11:12:37
【问题描述】:
我无法创建结构如下的字典:
"aggs": {
"4": {
"date_histogram": {
"field": "@timestamp",
"interval": "1m",
"time_zone": "Asia/Kolkata",
"min_doc_count": 1,
},
"aggs": {
"5": {
"range": {
"field": "system.core.idle.pct",
"ranges": [{"from": 0, "to": 0.001}, {"from": 0.001, "to": 1}],
"keyed": true,
},
"aggs": {
"2": {"max": {"field": "system.core.system.pct"}},
"3": {"max": {"field": "system.core.idle.pct"}},
},
}
},
}
}
大多数情况下,我在 aggs:4 中创建 aggs:5 然后循环它时遇到问题。我需要为多个 aggs 做这件事。 agg id 的数量也可以达到 1000。
我正在尝试从字典中获取它:
"aggs": [
{"id": "1", "enabled": true, "type": "count", "schema": "metric", "params": {}},
{
"id": "2",
"enabled": true,
"type": "max",
"schema": "metric",
"params": {"field": "system.core.system.pct", "customLabel": "system"},
},
{
"id": "3",
"enabled": true,
"type": "max",
"schema": "metric",
"params": {"field": "system.core.idle.pct", "customLabel": "idle"},
},
{
"id": "4",
"enabled": true,
"type": "date_histogram",
"schema": "bucket",
"params": {
"field": "@timestamp",
"interval": "m",
"customInterval": "2h",
"min_doc_count": 1,
"extended_bounds": {},
},
},
{
"id": "5",
"enabled": true,
"type": "range",
"schema": "bucket",
"params": {
"field": "system.core.idle.pct",
"ranges": [{"from": 0, "to": 0.001}, {"from": 0.001, "to": 1}],
},
},
]
任何人都可以显示代码如何执行它。基本上我无法创建嵌套字典。
【问题讨论】:
-
您遇到了什么问题?您实际上并没有告诉我们您看到的错误输出或错误代码。
-
我没有收到任何错误。我无法使用以下信息创建像上面这样的字典。
标签: python python-3.x dictionary nested