# How to get multiple relative fields in terms aggregations?

**URL:** <https://discuss.elastic.co/t/how-to-get-multiple-relative-fields-in-terms-aggregations/47758>\
**Category:** Elasticsearch\
**Created:** [April 19, 2016, 7:33am UTC](https://discuss.elastic.co/t/how-to-get-multiple-relative-fields-in-terms-aggregations/47758 "2016-04-19T07:33:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morriaty](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Morriaty](https://discuss.elastic.co/u/Morriaty)\
**Post date:** [April 19, 2016, 7:33am UTC](https://discuss.elastic.co/t/how-to-get-multiple-relative-fields-in-terms-aggregations/47758/1 "2016-04-19T07:33:24Z")

</div>

```json
{
    ...
    "aggs" : {
        "city_info" : {
            "terms" : { "field" : "city_id" }
        }
    }
}

```

As I see, the agg was something like the sql

```sql
SELECT city_id, COUNT(*) FROM item GROUP BY city_id;

```

But what I really wanna was like this

```sql
SELECT city_id, city_name, province_name, COUNT(*) FROM item GROUP BY city_id;

```

---

<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:** [July 5, 2017, 10:58pm UTC](https://discuss.elastic.co/t/how-to-get-multiple-relative-fields-in-terms-aggregations/47758/2 "2017-07-05T22:58:10Z")

</div>


