{ "size": 0, "query": { "bool": { "must": [ { "match": { "search_tags": { "query": "t-sh", "analyzer": "standard", "operator": "and" } } } ], "must_not": [] } }, "aggs": { "templates_matched": { "nested": { "path": "template" }, "aggs": { "templates": { "filter": { "match": { "template.name": { "query": "t-sh", "analyzer": "standard" } } }, "aggs": { "template_id": { "terms": { "field": "template.id", "size": 10 }, "aggs": { "full_template": { "top_hits": { "size": 1, "_source": { "includes": "template.name" } } } } } } } } }, "options_matched": { "nested": { "path": "template" }, "aggs": { "template_id": { "terms": { "field": "template.id", "size": 10 }, "aggs": { "full_template": { "top_hits": { "size": 1, "_source": { "includes": "template" } } }, "option_groups": { "nested": { "path": "option_groups" }, "aggs": { "option_groups": { "filter": { "nested": { "path": "option_groups.option", "query": { "match": { "option_groups.name": { "query": "t-sh", "analyzer": "standard" } } } } }, "aggs": { "option_group_id": { "terms": { "field": "option_groups.id", "size": 10 }, "aggs": { "option_group_name": { "top_hits": { "size": 1, "_source": { "includes": "option_groups.name" } } }, "option": { "nested": { "path": "option_grouos.option" }, "aggs": { "option": { "filter": { "match": { "option_groups.option.name": { "query": "t-sh", "analyzer": "standard" } } }, "aggs": { "option_id": { "terms": { "field": "option_groups.option.id", "size": 10 }, "aggs": { "full_option": { "top_hits": { "size": 1, "_source": { "includes": "option_groups.option" } } } } } } } } } } } } } } } } } } } } }