# Aggregating two fields with the same data

**URL:** <https://discuss.elastic.co/t/aggregating-two-fields-with-the-same-data/89449>\
**Category:** Elasticsearch\
**Created:** [June 14, 2017, 7:53pm UTC](https://discuss.elastic.co/t/aggregating-two-fields-with-the-same-data/89449 "2017-06-14T19:53:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamA](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@SamA](https://discuss.elastic.co/u/SamA)\
**Post date:** [June 14, 2017, 7:53pm UTC](https://discuss.elastic.co/t/aggregating-two-fields-with-the-same-data/89449/1 "2017-06-14T19:53:56Z")

</div>

I want to aggregate the count for 2 fields in Elasticsearch. The first field is transporter1 and the second field is transporter2. How I want to display my results are as follows:

> Uber: 500

> Lyft: 220

> Taxi: 150  
> So for example, transporter1 might be Uber and another field might be Lyft. If in one document, transporter2 is Uber and transporter1 is Lyft, then both Uber and Lyft will have a count of 2 since they appear as transporter1 in one document and transporter2 in another.

I tried creating a query for this, but the results are not what I want.

```
{
    "query":{
    "match":{
      "market": "TEST"
    }
  },

  "aggs": {
    "group_by_transporter": {
      "terms": {
        "field": "transporter1"
      },
      "aggs": {
        "group_by_transporter": {
          "terms": {
            "field": "transporter2"
          }         
        }
      }
    }
  }
}

```

How do I make it so that I can get the market share of transporters?

---

<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 12, 2017, 7:53pm UTC](https://discuss.elastic.co/t/aggregating-two-fields-with-the-same-data/89449/2 "2017-07-12T19:53:59Z")

</div>

Closed on July 12, 2017, 7:53pm UTC

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