我如何使用 top_hits 中的字段对顶级存储桶进行排序

问题描述

我一直在尝试使用 top_hits 字段对 actionee_id 存储桶进行排序,但未能实现

{
  "size": 0,"aggs": {
    "actionee_id": {
      "terms": {
        "field": "actionee_id","size": 50
      },"aggs": {
        "player": {
          "top_hits": {
            "sort": {
              "created_at": {
                "order": "desc"
              }
            },"_source": {
              "include": [
                "actionee"
              ]
            },"size": 1
          }
        },"pagination": {
          "bucket_sort": {
            "sort": [
              {
                "debit>amount_total.value": {
                  "order": "desc"
                }
              }
            ],"size": 5,"from": 0
          }
        },"debit": {
          "filter": {
            "term": {
              "transaction_type": "debit"
            }
          },"aggs": {
            "amount_total": {
              "sum": {
                "field": "amount"
              }
            }
          }
        }
      }
    }
  }
}

以下是我在 top_hits 中收到的输出

  "player" : {
            "hits" : {
              "total" : {
                "value" : 8,"relation" : "eq"
              },"max_score" : null,"hits" : [
                {
                  "_index" : "transactions_development_20210305080754941","_type" : "_doc","_id" : "421","_score" : null,"_source" : {
                    "actionee" : {
                      "parent_name" : "Stefany","country_code" : null,"parent_chain_ids" : [
                        6,5
                      ],"wallet" : {
                        "balance" : 20000.0,"currency" : "EUR"
                      },"user_name" : "Filiberto","parent_id" : 6,"last_name" : null,"active" : true,"creation_date" : "2021-02-12T06:23:50.702Z","type" : "User","first_name" : null,"email" : "stanford@runolfsson.co"
                    }
                  },"sort" : [
                    1614677210329
                  ]
                }
              ]
            }
          }

我也尝试先在 actionee_id 上聚合,然后在 actionee.user_name 上聚合,但是这样,我实现了bucket下的bucket,然后无法使用内部bucket的键对外部bucket进行排序

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)