# Return Selected Fields from DSL Aggregation

**URL:** <https://discuss.elastic.co/t/return-selected-fields-from-dsl-aggregation/304158>\
**Category:** Elasticsearch\
**Created:** [May 6, 2022, 10:06pm UTC](https://discuss.elastic.co/t/return-selected-fields-from-dsl-aggregation/304158 "2022-05-06T22:06:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fefontana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fefontana/32/62843_2.png) [@fefontana](https://discuss.elastic.co/u/fefontana)\
**Post date:** [May 6, 2022, 10:06pm UTC](https://discuss.elastic.co/t/return-selected-fields-from-dsl-aggregation/304158/1 "2022-05-06T22:06:24Z")

</div>

Hello, I have the following \_search query:

```auto
{

    "size": 0,

    "aggs": {

        "3": {

            "terms": {

                "field": "REGIONAL.keyword",

                "order": {

                    "_count": "desc"

                },

                "size": 30

            },

            "aggs": {

                "2": {

                    "terms": {

                        "field": "OFICINA_DESCRIPCION.keyword",

                        "order": {

                            "_count": "desc"

                        },

                        "size": 30

                    }

                }

            }

        }

    },

    "query": {

        "bool": {

            "must": [],

            "filter": [

                {

                    "range": {

                        "HORA_INICIO": {

                            "gte": "2022-01-01T03:00:00.000Z",

                            "lte": "2022-05-06T20:05:53.807Z",

                            "format": "strict_date_optional_time"

                        }

                    }

                }

            ],

            "should": [],

            "must_not": []

        }

    }

}

```

and I'm getting the following response:

```auto
{

    "took": 0,

    "timed_out": false,

    "_shards": {

        "total": 1,

        "successful": 1,

        "skipped": 0,

        "failed": 0

    },

    "hits": {

        "total": {

            "value": 10000,

            "relation": "gte"

        },

        "max_score": null,

        "hits": []

    },

    "aggregations": {

        "3": {

            "doc_count_error_upper_bound": 0,

            "sum_other_doc_count": 0,

            "buckets": [

                {

                    "key": "MONTEVIDEO",

                    "doc_count": 24724,

                    "2": {

                        "doc_count_error_upper_bound": 0,

                        "sum_other_doc_count": 0,

                        "buckets": [

                            {

                                "key": "OFICINA COMERCIAL N° 1 CENTRO",

                                "doc_count": 6732

                            },

                            {

                                "key": "OFICINA COMERCIAL N° 4 UNIÓN",

                                "doc_count": 6012

                            },

                            {

                                "key": "OFICINA COMERCIAL N° 5 PASO MOLINO",

                                "doc_count": 4870

                            },

                            {

                                "key": "OFICINA COMERCIAL N° 3 GOES",

                                "doc_count": 3625

                            },

                            {

                                "key": "OFICINA COMERCIAL N° 6 POCITOS",

                                "doc_count": 3485

                            }

                        ]

                    }

                },

                { . . . . . continue

```

How can I get a response like this only with these fields ?:

```auto
{
  "aggregations.3.buckets.key": value,
  "aggregations.3.buckets.doc_count": value,
  "aggregations.3.buckets.2.buckets.key": value,
  "aggregations.3.buckets.2.buckets.doc_count": value
},
{

},
 . . . .

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 3, 2022, 10:06pm UTC](https://discuss.elastic.co/t/return-selected-fields-from-dsl-aggregation/304158/2 "2022-06-03T22:06:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
