我有产品索引,每个产品都有category
和category_owner
。我想在我的GUI表上显示按category_owner排序的所有类别,但是该表必须是可分页的。
我知道有一种使用bucket_sort
对聚合进行排序(和分页)的方法。例子
GET products/_search
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"unique_categories": {
"terms": {
"field": "category",
"size": 1000
},
"aggs": {
"inner": {
"avg": {
"field": "price"
}
},
"soring_agg": {
"bucket_sort": {
"sort": [
{
"inner": {"order": "asc"}
}
],
"from": 1,
"size": 1
}
}
}
}
}
}
但是有什么方法可以对非数字字段进行排序?例如,我可以创建大小为1的term
聚合或top_hists
搜索
"aggs": {
"inner": {
"top_hits": {
"size": 1,
"sort": [
{
"@timestamp": {"order": "desc"}
}
],
"_source": {
"includes": ["category_owner"]
}
}
},
"soring_agg": {
"bucket_sort": {
"sort": [
{
"inner": {"order": "asc"}
}
]
}
}
}
Bu我遇到了错误buckets_path must reference either a number value or a single value numeric metric aggregation, got: [InternalTopHits] at aggregation [inner]
terms
聚合也不起作用
"inner": {
"terms": {
"field": "category_owner",
"size": 1
}
},
buckets_path must reference either a number value or a single value numeric metric aggregation, got: [StringTerms] at aggregation [inner]
是否可以根据所有者分类的独特类别创建分页?
编辑: 我可以为每个所有者创建所有uniqe类别,但我必须在我的应用程序中手动对其进行排序和分页:(
"aggs": {
"owners": {
"terms": {
"field": "category_owner",
"size": 100000
},
"aggs": {
"categories": {
"terms": {
"field": "category",
"size": 1000
}
}
}
}
}