You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过C#中的Nest客户端列出所有Kibana仪表板?

使用Nest客户端获取Kibana仪表板列表

1. 定义Kibana仪表板实体类(可选,推荐)

如果需要强类型处理返回结果,可以创建对应实体类:

public class KibanaDashboard
{
    public string Id { get; set; }
    public string Type { get; set; }
    public Dictionary<string, object> Attributes { get; set; }
    // 可根据需求添加title、description等具体字段
}

2. 配置ElasticClient

var settings = new ConnectionSettings(new Uri("http://localhost:9200/"))
    .DefaultMappingFor<KibanaDashboard>(i => i
        .IndexName(".kibana")
        .IdProperty(p => p.Id)
    );

var client = new ElasticClient(settings);

3. 构造搜索请求(两种实现方式)

方式一:对应原请求的SimpleQueryString查询

完全匹配你用Postman发送的q=type:dashboard&size=20逻辑:

ISearchResponse<KibanaDashboard> searchResponse = client.Search<KibanaDashboard>(s => s
    .Size(20)
    .Query(q => q
        .SimpleQueryString(f => f
            .Query("type:dashboard")
        )
    )
);

方式二:更精准的Term查询(推荐)

因为type字段是精确匹配场景,用Term查询性能更好:

ISearchResponse<KibanaDashboard> searchResponse = client.Search<KibanaDashboard>(s => s
    .Size(20)
    .Query(q => q
        .Term(t => t
            .Field(f => f.Type)
            .Value("dashboard")
        )
    )
);

无实体类的动态查询方式

如果不需要强类型,也可以直接用dynamic类型:

ISearchResponse<dynamic> searchResponse = client.Search<dynamic>(s => s
    .Index(".kibana")
    .Size(20)
    .Query(q => q
        .Term(t => t
            .Field("type")
            .Value("dashboard")
        )
    )
);

4. 获取结果

通过searchResponse.Documents即可获取返回的Kibana仪表板列表。

内容的提问来源于stack exchange,提问作者Jason

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 23:54:28