如何在 Kusto 中创建自定义输出对象

How do I create custom output object in Kusto

我有如下所示的数组作为我的对象的属性之一。我想提取某些字段并且 return 它仍然作为输出中的数组。例如,我只希望 namestorageAccountType 被 return 编辑,如下所示

期望输出

[
    {
        "name": "Data",
        "storageAccountType": "Standard_LRS"
    },
    {
        "name": "Disk2",
        "storageAccountType": "Standard_LRS"
    }
]

输入数组

[
    {
        "name": "Data",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Data",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 0
    },
    {
        "name": "Disk2",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Disk2",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 1
    }
]

这里有一个你可以遵循的方向(它假设你实际上需要取回数组而不是让数组中的每个元素都在它自己的行中。如果后者是好的,删除带有注释的行(// *)

datatable(some_value:string, d:dynamic) // just a sample data set with 2 records
[
    "hello", dynamic([
    {
        "name": "Data",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Data",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 0
    },
    {
        "name": "Disk2",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Disk2",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 1
    }
]), "world", dynamic([
    {
        "name": "Data3",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Data",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 0
    },
    {
        "name": "Disk23",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Disk2",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 1
    }
])
]
// --> answer starts here <--
| extend r = rand() // *
| mv-apply d on (   
    project d = pack("name", d.name, "storageAccountType", d.managedDisk.storageAccountType)
)
| summarize d = make_list(d) by r, some_value // *
| project-away r // *