【发布时间】:2016-01-25 06:31:22
【问题描述】:
我的映射模型:
// 类型日志:错误、信息、警告
{
"onef-sora": {
"mappings": {
"Log": {
"properties": {
"application": {
"type": "string",
"index": "not_analyzed"
}
"typeLog": {
"type": "string"
}
}
}
}
}
}
我的查询:
{
"size": 0,
"aggs": {
"application": {
"terms": {
"field": "application",
"order" : { "_count" : "desc"},
"size": 5
},
"aggs": {
"typelogs": {
"terms": {
"field": "typeLog",
"order" : { "_term" : "asc"}
}
}
}
}
}
}
我想获取错误最多的前 5 个应用程序,但术语聚合顺序支持三个键:_count、_term、_key。如何在查询中按 typeLog doc_count 排序。谢谢!!!
我想要的结果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 10000,
"max_score": 0,
"hits": []
},
"aggregations": {
"application": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 5000,
"buckets": [
{
"key": "OneF0",
"doc_count": 1000,
"typelogs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "error",
"doc_count": 334
},
{
"key": "info",
"doc_count": 333
},
{
"key": "warn",
"doc_count": 333
}
]
}
},
{
"key": "OneF1",
"doc_count": 1000,
"typelogs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "error",
"doc_count": 333
},
{
"key": "info",
"doc_count": 334
},
{
"key": "warn",
"doc_count": 333
}
]
}
},
{
"key": "OneF2",
"doc_count": 1000,
"typelogs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "error",
"doc_count": 332
},
{
"key": "info",
"doc_count": 333
},
{
"key": "warn",
"doc_count": 334
}
]
}
}
]
}
}
}
【问题讨论】:
-
为什么不在
typelogs子聚合中简单地使用_count: desc? -
无意义,我试过了。我想获取顶级应用程序的类型 = 'Error'
-
不确定我是否理解,但@juliendangers 提供的内容应该有效,他按照建议使用
_count: desc。您可以只删除term查询,但它应该可以工作。 -
他只是添加过滤器查询,我想得到 top doc_count typeLog = error 和 group by typeLog(include Warn,Info)
标签: c# sql elasticsearch nest