我有一个aggergation,即自动完成下拉搜索。
GET org-members /_search { "size": 0, "aggs": { "members": { "terms": { "field": "members.keyword", "size": 1000 } } } } }
您接收所有1000个聚合值。
jpfvwuh41#
简单地使用 * 基数 * 和 bucket_sort。基数:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.htmlbucket_sort排序:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-sort-aggregation.html
GET org-members/_search { "size": 0, "aggs": { "total_count_of_aggergation": { "cardinality": { "field": "members.keyword" } }, "members_aggs": { "terms": { "field": "members.keyword", "size": 10000 //put a very high value }, "aggs": { "bucket_sort": { "bucket_sort": { "from": 0, "size": 10 } } } }, "totalIds": { "stats_bucket": { "buckets_path": "members._count" } } } }
1条答案
按热度按时间jpfvwuh41#
简单地使用 * 基数 * 和 bucket_sort。
基数:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
bucket_sort排序:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-sort-aggregation.html