繁体   English   中英

如何按热门字段(文本字段)对聚合进行排序? 或者是否有可能按文本字段对聚合进行排序(不使用_term)

[英]How to sort aggregations by top hits field (text field)? Or is there any possibility to sort aggregations by text field (without using _term)

在标题中,我有一个按文本字段排序Elasticsearch聚合的问题。 有没有可能做到这一点? 使用热门点击或类似的东西? 现在我正在使用术语聚合,我可以使用_term按聚合字段排序,但我需要按不同的字段对此聚合进行排序。 我知道如何使用具有数值的字段来完成它。 例如使用max,min,sum等。

如果我可以这样做(但我不能)会很棒:

    "aggs": {
        "Variants": {
            "terms": {
                "field": "variant",
                "order": {
                    "top_Song_hits": "asc"
                }
            },
            "aggs": {
                "top_Song_hits": {
                    "sum": {
                        "name": {
                            "order": "desc"
                        }
                    }
                }
            }
        }
    }
}

或者像这样:

{
    "aggs": {
        "Variants": {
            "terms": {
                "field": "variant",
                "order": {
                    "name_agg": "asc"
                }
            },
            "aggs": {
                "name_agg": {
                    "terms": {
                        "field": "name"
                    }
                }
            }
        }
    }
}

要么

{
    "aggs": {
        "Variants": {
            "terms": {
                "field": "variant",
                "order": {
                    "details": "asc"
                }
            },
            "aggs": {
                "details": {
                    "top_hits": {
                        "size": 1,
                        "_source": {
                            "include": ["name"]
                        }
                    }
                }
            }
        }
    }
}

在最后一种情况下我得到错误:

"reason": "Invalid aggregation order path [details]. Buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end."

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM