嘿~ 今天天气不错嘛

请各位大佬帮忙看下,使用了top_hits如何排序的问题

Elasticsearch | 作者 kerrygao | 发布于2020年11月03日 | 阅读数:1586



123.png

请大家帮我看看 我要根据ctime进行排序,如何操作呢?
 
es语句如下:
 

{
"query": {
"bool": {
"must": [{
"match": {
"code": "system_monitor"
}
}
]
}
},
"size": 0, 
"aggs": {
  "node_ip_system_type": {
    "terms": {
         "script": "doc['node_ip.keyword'].value + '#' + doc['system_type.keyword'].value"
    },
    
    "aggs": {
      "data_detail":{
        "top_hits":{
          "sort": [
              {
                "_ctime": {
                  "order": "desc"
                }
              }
            ],
            "_source": {
              "includes": [
                "info",
                "node_ip",
                "node_name",
                "node_number",
                "system_type",
                "timestamp",
                "code",
                "_ctime"
              ]
            },
            
          "size":1
        }
      }
    }
  }
}
}
 
已邀请:

BKing - Double non. Open source software and dreamer (English Français Japanese Korean ) learners

赞同来自:

个人看法呀~,没看出来语法哪里有问题。时间没有按照 desc 降序排列...
思路:
1. 看看能否用其他字段进行排序。
2. 查看下该index 的mapping,看是否禁用了排序功能。
3. 查看_ctime 的doc_value 是否开启。
 
 

God_lockin

赞同来自:

你topn的排序是每个桶里命中的数据的topn的排序,我觉得你想要的是根据每个桶里的topn的一条数据的ctime来对桶排序吧,试试在外面一层的聚合里面加上order呢

要回复问题请先登录注册