gpt4 book ai didi

sorting - Elasticsearch 按列对聚合进行排序

转载 作者:行者123 更新时间:2023-12-02 12:18:18 25 4
gpt4 key购买 nike

我正在尝试在aggs中的 Elasticsearch 中进行排序,相当于mysql中的“ORDER BY Title ASC/DESC”。这是索引结构:

'body' => array(
'mappings' => array(
'test_type' => array(
'_source' => array(
'enabled' => true
),
'properties' => array(
'ProductId' => array(
'type' => 'integer',
'index' => 'not_analyzed'
),
'Title' => array(
'type' => 'string',
'index' => 'not_analyzed'
),
'Price' => array(
'type' => 'double',
'index' => 'not_analyzed'
)
)
)
)

我可以按价格订购,如下:

{
"aggs": {
"group_by_product": {
"terms": {
"field": "ProductId",
"order": {
"product_price" : "asc"
}
},
"aggs": {
"product_price": {
"avg": {
"field": "Price"
}
}
}
}
}
}

但无法按标题排序 (ORDER BY Title ASC/DESC)。

有没有办法按标题排序?

提前非常感谢您!

问候

最佳答案

编辑以反射(reflect)评论中的说明:

要按字符串值对聚合进行排序,请使用 intrinsic sort ,但是目前不支持对非数字指标聚合进行排序。

"aggs" : {
"order_by_title" : {
"terms" : {
"field" : "title",
"order": {
"_term" : "asc"
}
}
}
}

关于sorting - Elasticsearch 按列对聚合进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31002281/

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