Aggregating counts on child of child

My node structures look something like this (I’m simplifying it quite a bit):

{
  uid
  isTicket
  tags {
    uid
    tag {
      uid
      name
    }
  }

I’m trying to get a returned result that looks something like this:

[
  {
    uid (inner most tag's uid)
    name (inner most tag's name)
    count (number of tickets that lead to each tag. Should be the count of the outer most uid)
  }
]

So if my dataset looked something like this (I’m using a JSON’ish structure for simplicity):

[
  {
    uid: "0x1",
    tags: [
      {
          uid: "0x2",
          tag: {
            uid: "0x3"
            name: "Tag 1"
          }
      },
      {
          uid: "0x4",
          tag: {
            uid: "0x5"
            name: "Tag 2"
          }
      }
    ]
  },{
    uid: "0x6",
    tags: [
      {
          uid: "0x7",
          tag: {
            uid: "0x3"
            name: "Tag 1"
          }
      }
    ]
  }
]

The result set would look like this:

[
  {
    uid: "0x3",
    name: "Tag 1",
    count: 2
  },
  {
    uid: "0x5",
    name: "Tag 2",
    count: 1
]

I’ve tried several times using the documentation to pull this off and either I get an empty result set or I crash the dgraph server. Is there anyway to do this?

If the Dgraph server crashes, can you please create a Github issue with the trace so that we could fix it?

I am trying to understand your data structure here, why do you have tags intermediate node which points to tag. Couldn’t you directly associate tags with the outer node?

The next time I have a server crash I’ll create a github issue for it.

There is other data that is associated to that intermediate node. I just left it out for simplicity sake. There are some other associations that are defined there so we know where the tag came from and some other information about it. We probably could reorganize the data so it’s not necessary, but it would be nice to have.

The way to do this in that case would be to start with the tags and move out on a reverse edge to get the count of tickets.

@Camway I am struggling with similar query, can you please post your query which helped to bring desired result. Thank you.

+1

and I’ve just posted here my troubles about grouping, and I really need / appreciate any help.