# Group by nested fields

**URL:** <https://discuss.dgraph.io/t/group-by-nested-fields/1806>\
**Category:** Users\
**Created:** [September 29, 2017, 10:08pm UTC](https://discuss.dgraph.io/t/group-by-nested-fields/1806 "2017-09-29T22:08:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rait.raidma](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@rait.raidma](https://discuss.dgraph.io/u/rait.raidma)\
**Post date:** [September 29, 2017, 10:08pm UTC](https://discuss.dgraph.io/t/group-by-nested-fields/1806/1 "2017-09-29T22:08:12Z")

</div>

Hi,  
I have problem on grouping by nested fields.

Let’s say, we have a list of companies who are moving packages from one location to another.  
Data is defined like that:

```auto
mutation {
  schema {
    name: string @index(hash) .
    geoPoint: geo .
  }

  set {
    _:company1 <name> "Company A" .
    _:company1 <pickupFrom> _:company1_pickup_from .
    _:company1 <deliverTo> _:company1_deliver_to .
    _:company1_pickup_from <geoPoint> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company1_deliver_to <geoPoint> "{'type':'Point','coordinates':[10.0,11.0]}" .

    _:company2 <name> "Company A" .
    _:company2 <pickupFrom> _:company2_pickup_from .
    _:company2 <deliverTo> _:company2_deliver_to .
    _:company2_pickup_from <geoPoint> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company2_deliver_to <geoPoint> "{'type':'Point','coordinates':[10.0,11.0]}" .

    _:company3 <name> "Company A" .
    _:company3 <pickupFrom> _:company3_pickup_from .
    _:company3 <deliverTo> _:company3_deliver_to .
    _:company3_pickup_from <geoPoint> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company3_deliver_to <geoPoint> "{'type':'Point','coordinates':[13.0,14.0]}" .
  }
}

```

Now I want to group by `pickupFrom.geoPoint` and `deliverTo.geoPoint` and count how many times packages were delivered from one point to another.  
The result should be something like that:

```auto
[
    {
        pickupFrom: {'type':'Point','coordinates':[0.0,0.0]},
        deliverTo: {'type':'Point','coordinates':[10.0,11.0]},
        count: 2
    },
    {
        pickupFrom: {'type':'Point','coordinates':[0.0,0.0]},
        deliverTo: {'type':'Point','coordinates':[13.0,14.0]},
        count: 1
    }
]

```

It is working, when geo-points are on the same level:

```auto
mutation {
  schema {
    name: string @index(hash) .
    pickupFrom: geo .
    deliverTo: geo .
  }

  set {
    _:company1 <name> "Company B" .
    _:company1 <pickupFrom> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company1 <deliverTo> "{'type':'Point','coordinates':[10.0,11.0]}" .

    _:company2 <name> "Company B" .
    _:company2 <pickupFrom> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company2 <deliverTo> "{'type':'Point','coordinates':[10.0,11.0]}" .

    _:company3 <name> "Company B" .
    _:company3 <pickupFrom> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company3 <deliverTo> "{'type':'Point','coordinates':[13.0,14.0]}" .
  }
}

{
  q(func: eq(name, "Company B")) @groupby(pickupFrom, deliverTo) {
    count(_uid_)
  }
}

```

Now, how could I group by nested fields that would result similar result set from first data set?

---

<div class="post-metadata">

**Author:** ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)\
**Post date:** [October 2, 2017, 1:13am UTC](https://discuss.dgraph.io/t/group-by-nested-fields/1806/2 "2017-10-02T01:13:54Z")

</div>

Hey @rait.raidma

We don’t support `@groupby` using nested fields as of now. You can open an issue on Github and we can look into supporting this.

---

<div class="post-metadata">

**Author:** ![rait.raidma](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@rait.raidma](https://discuss.dgraph.io/u/rait.raidma)\
**Post date:** [October 2, 2017, 6:43am UTC](https://discuss.dgraph.io/t/group-by-nested-fields/1806/3 "2017-10-02T06:43:36Z")

</div>

Thank you for your answer.  
I will open an issue.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [November 1, 2017, 6:52am UTC](https://discuss.dgraph.io/t/group-by-nested-fields/1806/4 "2017-11-01T06:52:42Z")

</div>

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