【问题标题】:NEST query not returning data for a Metricbeat field, held in ElasticsearchNEST 查询未返回 Elasticsearch 中保存的 Metricbeat 字段的数据
【发布时间】:2018-03-22 12:03:56
【问题描述】:

我正在尝试查询 elasticsearch 中保存的 metricbeat 数据,我正在寻找两个字段:hostsystem.cpu.total.pct。两者都包含在我的班级中:

public string Host { get; set; }
[Number(NumberType.ScaledFloat, Name = "system.cpu.total.pct")]
public float Cpu_pct { get; set; }

这是我的查询:

var searchResponse = client.Search<System>(s => s
            .Query(q => q
                .Bool(b => b
                    .Filter(bf => bf
                        .Range(r => r
                            .Field(f => f.Cpu_pct)
                            .GreaterThan(0)
                        )
                    )
                )
            )
        );

索引中有文档的数据,在0 上方有system.cpu.total.pct,但是当我打印出响应文档时Cpu_pct 只输出0,但host 给出了正确的主机名。

为什么我无法返回system.cpu.total.pct 中的值?

【问题讨论】:

  • 该字段是在 Elasticsearch 中称为 "system.cpu.total.pct",还是指向 "total""cpu""system" 对象上的 "pct" 字段的点符号路径?
  • 后者,我很确定这是我出错的地方我只是不确定如何在多个嵌套对象中获取一个字段
  • 你找到答案了吗?

标签: elasticsearch nest metricbeat


【解决方案1】:

更新 System 类型以匹配 JSON 源中内部对象的层次结构

public class System
{
    public Cpu Cpu { get; set; }
}

public class Cpu
{
    public Total Total { get; set; }
}

public class Total
{
    public float Pct { get; set; }
}

现在在反序列化时,将为Source.Cpu.Total.Pct 属性设置值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-11
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多