字段的术语汇总

问题描述 投票:0回答:1

我正在从指标中读取数据,并希望在最近的日期时间读取选定的数据。我使用Aggregations来获得第一名,但是由于查询给出的结果与最新不匹配而失败了。可能是我缺少某个地方。这是我的最终查询

var elasticResponse = elasticClient.Search<object>(s => s
                .Aggregations(ag => ag
                    .Terms("cpu_aggs", sa => sa.Field("system.cpu.total.pct").Size(1))
                    .Terms("memory_aggs", sa => sa.Field("system.memory.actual.used.pct").Size(1))
                    .Terms("diskio_aggs", sa => sa.Field("docker.diskio.summary.bytes").Size(1))
                    .Terms("load_aggs", sa => sa.Field("system.load.5").Size(1))
                )
                .Sort(so => so.Descending("@timestamp"))
            );

请帮助找到正确的解决方案。

elasticsearch dsl querydsl
1个回答
0
投票

您尝试实现什么?

聚合是一个分组依据

.Aggregations(ag => ag
                     .Terms("cpu_aggs", sa => sa.Field("system.cpu.total.pct").Size(1))
                     .Terms("memory_aggs", sa => sa.Field("system.memory.actual.used.pct").Size(1))
                     .Terms("diskio_aggs", sa => sa.Field("docker.diskio.summary.bytes").Size(1))
                     .Terms("load_aggs", sa => sa.Field("system.load.5").Size(1))
                 )




.Terms("cpu_aggs", sa => sa.Field("system.cpu.total.pct").Size(1)



 Means you want the most (and only because of the size(1) system.cpu.total.pct in your data 
    then

.Terms("memory_aggs", sa => sa.Field("system.memory.actual.used.pct").Size(1))=>最多system.memory.actual.used.pct值ect

All these aggregation are at the same level, so you will have most reccurent pct, most recurent memory, more recurent bytes ect...Each of these aggregations is independant and will scan all your document.



    Your sort is not apply to aggregation, it will be apply to your query, by default, 10 documents are returned, so it will return the last 10 documents.

进行汇总以分析不同的文档(递归,均值,最大值,计数,总和...)。>>

例如,您可以做什么:

首先,如果您只想使用聚合,请不要索取文档,请输入.Size(0)。

var elasticResponse = Client.Search<object>(s => s
                .Size(0)
                 .Aggregations(ag => ag

如果要在一个字段上进行汇总,例如得到另外10个递归值:

.Terms("cpu_aggs", sa => sa.Field("system.cpu.total.pct").Size(10)

如果您想使“ system.cpu.total.pct”的十个子句与每个文件的最后一个文档一起使用,则>]

.Terms("cpu_aggs", sa => sa.Field("system.cpu.total.pct")).TopHits("topcpu", r => r.Field("@timestamp").Sort(ss => ss.Descending()).Size(1)))

[如果要再增加10个递归的“ cpu_aggs”,并且对于每个最高cpu值,则将5个最高的“ system.load.5”]

.Terms("cpu_aggs", sa => sa.Field("docker.diskio.summary.bytes").Size(10)
                        .Aggregations(subag => subag.Terms("subaggr", sua => sua.Field("system.load.5").Size(5))
                     ))

如果您需要统计信息(如果system.cpu.total.pct是一个数字,例如)

.Stats("cpu_stats", sa => sa.Field("system.cpu.total.pct"))

如果只需要最后一个文档,则不需要聚合:

var elasticResponse = elasticClient.Search<object>(s => s
                .Size(1)
                .Sort(so => so.Descending("@timestamp"))
            );

如果这不能回答您的问题,请进行澄清,并加入一些您需要的示例。

© www.soinside.com 2019 - 2024. All rights reserved.