我发现这样做的唯一方法是使用exclude语法排除不需要的级别。
{ "aggs": { "category": { "terms": { "field": "group_path", "size": 0, "exclude" : ".*\..*" } } }}然后将返回
aggregations: { category: { buckets: [ { key: Book doc_count: 1 } { key: DVD doc_count: 1 } ] }}如果您选择书籍,则可以像这样搜索
{ "query" : { "filtered": { "filter": { "prefix": { "group_path": "Book" } } } }, "aggs" : { "category": { "terms": { "field": "group_path", "size": 0, "include" : "Book\..*", "exclude": ".*\..*\..*" } } }}然后将返回
aggregations: { category: { buckets: [ { key: Book.Thriller doc_count: 1 } ] }}


