Nest

nest 过滤器插件允许您对嵌套数据进行操作。它的操作方式是:

  • nest - 获取一组记录并将其放置在映射中

  • lift - 通过映射的键获取其值并将其提取为记录

Example usage (nest)

以使用 JSON 形式的数据为例,要将带有通配符的键 Key* 嵌套在新键 NestKey 下,转换前后如下:

输入示例:

{
  "Key1"     : "Value1",
  "Key2"     : "Value2",
  "OtherKey" : "Value3"
}

输出示例

{
  "OtherKey" : "Value3"
  "NestKey"  : {
    "Key1"     : "Value1",
    "Key2"     : "Value2",
  }
}

Example usage (lift)

以使用 JSON 形式的数据为例,要提取带有嵌套数据的键 NestKey* 中的值(提取为记录),转换前后如下: 输入示例:

输出示例:

Configuration Parameters

该插件支持如下配置参数:

Key

Value Format

Operation

Description

中文

Operation

ENUM [nest or lift]

Select the operation nest or lift

可选的操作为 nestlift(嵌套或提取)

Wildcard

FIELD WILDCARD

nest

Nest records which field matches the wildcard

带有通配符的字符串,用于筛选记录映射字段用于嵌套或提取

Nest_under

FIELD STRING

nest

Nest records matching the Wildcard under this key

Wildcard 匹配到的键映射嵌套在 Nest_under 指定的键下

Nested_under

FIELD STRING

lift

Lift records nested under the Nested_under key

提取 Nested_under 指定的键下的键值映射作为记录的键值映射

Add_prefix

FIELD STRING

ANY

Prefix affected keys with this string

为受影响的键添加前缀

Remove_prefix

FIELD STRING

ANY

Remove prefix from affected keys if it matches this string

从受影响的键中删除匹配的前缀

Getting Started

要开始记录过滤,您可以从命令行或通过配置文件运行过滤器。以下调用 mem(内存数据指标)输入插件,它输出如下示例记录:

Example #1 - nest

Command Line

注意:使用命令行模式要求引号正确解析通配符。建议使用配置文件。

以下命令将加载 mem 输入插件。然后 nest 过滤器会使用通配符规则与关键字匹配,并将与 Mem.* 匹配的关键字嵌套在新关键字 NEST 下:

Configuration File

Result

命令行和配置调用的输出应相同,输出如下:

Example #1 - nest and lift undo

本示例将所有 Mem.*Swap.* 键嵌套在 Stats 键下,然后通过 lift 操作撤消这些操作。输出显示不变。

Configuration File

Result

Example #2 - nest 3 levels deep

本示例将以 Mem.* 开头的键嵌套在 LAYER1 下,然后将其自身嵌套在 LAYER2 下,后者又嵌套在 LAYER3 下。

Configuration File

Result

Example #3 - multiple nest and lift filters with prefix

本示例以 Example 2 的 3 层深度嵌套开始,并应用 3 次 lift 过滤器以反转操作。最终结果是所有记录再次位于顶层,没有嵌套层级。且为每个提升的级别添加一个前缀。

Configuration file

Result

Last updated

Was this helpful?