您需要将索引约束移动到 post_filter
post_filter
{ index: 'all,indices,here', query: { bool: { must: [ { query_string: { query: 'hello', }, }, ], }, }, aggs: { group_by_index: { terms: { field: '_index', min_doc_count: 0, }, }, }, post_filter: { terms: { _index: 'only,search,hits,indices,here', }, }, from: 0, size: 20, };