gpt4 book ai didi

elasticsearch - .net核心中如何将弹性查询聚合筛选器转换为嵌套查询

转载 作者:行者123 更新时间:2023-12-03 01:28:22 25 4
gpt4 key购买 nike

如何将这个 flex 搜索查询转换为嵌套查询。
该查询给出了Bellow。
GET winlogbeat-6.6.0 * / _ search?size = 0

{
"query": {
"match_all": {}
},
"aggs": {
"success ": {
"filter": {
"term": {
"event_id": 4624
}
}

},
"failed": {
"filter": {
"term": {
"event_id": 4625
}
}
}
}
}

在Kibana中所需的输出如下
    {
"took" : 13120,
"timed_out" : false,
"_shards" : {
"total" : 37,
"successful" : 37,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 299924794,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"failed" : {
"doc_count" : 351643
},
"success " : {
"doc_count" : 40375274
}
}
}

这是我的代码,我需要将其转换为NEST以获得所需的结果。
谢谢

最佳答案

差不多了,您只需要通过在聚合描述符上调用.Filter(..)来添加另一种情况

var searchResponse = await client.SearchAsync<Document>(s => s
.Query(q => q.MatchAll())
.Aggregations(a => a
.Filter("success", success => success
.Filter(filter => filter
.Term(t => t.Field(f => f.EventId).Value(4624))))
.Filter("failed", failed => failed
.Filter(filter => filter
.Term(t => t.Field(f => f.EventId).Value(4625))))));

public class Document
{
public int Id { get; set; }
public int EventId { get; set; }
}

希望能有所帮助。

关于elasticsearch - .net核心中如何将弹性查询聚合筛选器转换为嵌套查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57378645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com