【发布时间】:2015-06-23 12:03:14
【问题描述】:
我正在尝试在 aggs 中对弹性搜索进行排序,等效于 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)。
有没有办法按标题排序?
非常感谢您!
问候
【问题讨论】:
-
您想如何订购标题字段?按分数?按字母顺序?
-
感谢您的回复@Daniel Hoffmann-Mitscherling。我想按字母顺序订购。
标签: sorting elasticsearch group-by