Query Help: Summarising paths

Hi,

Im trying (and failing) to write a query that will add a summary link between two nodes, via a 3 hop traversal, and totalling the value of the facets on route. Take the following graph:

Which is fetched from the following query

{
  trxs(func: type(Person)) @filter(gt(count(Account.transactedTo), 0)) {
    uid
    a: Person.hasAccount @filter(gt(count(Account.transactedTo), 0)) {
      uid
      b: Account.transactedTo @facets(amount) {
        uid
        ~a:~Person.hasAccount {uid}
      }
    }
  }
}

For all pairs of Person → Person with this pattern I would like to add a summary link, which sums the facet “amount”, in this case amount = 5.

The examples make it clear I need to use variables to acheive this. The examples group by the initial uid, but in my case I need to group by unique pairs of Person uids. Does anyone know how this can be done?

You can follow this https://dgraph.io/docs/query-language/facets/#facets-and-aggregation

Hi @MichelDiz yes I tried to make these examples work before posting, I think the complexity of my query is that I need it for unique person pairs, i.e. Person A sent $5 to Person B via 2 transactions, and Person A sent $7 to Person C via 3 transactions etc. I dont see how i can group by Uid pairs currently. Edit: Missed this, should work. Ill test today and update the query for future reference.

Give a sample of your dataset so I can analyze it and give you a proper answer.

Cheers.

1 Like

Hi,

Here is an example JSON for the scenario in my prev post. 0x167895f → 0x1678945 should total 5, 0x167895f → 0x1678946 should total 7

{
  "uid": "0x167895f",
  "a": [
    {
      "uid": "0x1678943",
      "b": [
        {
          "uid": "0x167894a",
          "~a": [
            {
              "uid": "0x1678945"
            }
          ],
          "b|amount": "2"
        }
      ]
    },
    {
      "uid": "0x167896d",
      "b": [
        {
          "uid": "0x167896a",
          "~a": [
            {
              "uid": "0x1678945"
            }
          ],
          "b|amount": "3"
        }
      ]
    },
    {
      "uid": "0x167896f",
      "b": [
        {
          "uid": "0x168896a",
          "~a": [
            {
              "uid": "0x1678946"
            }
          ],
          "b|amount": "1"
        }
      ]
    },
    {
      "uid": "0x167896b",
      "b": [
        {
          "uid": "0x167897d",
          "~a": [
            {
              "uid": "0x1678946"
            }
          ],
          "b|amount": "1"
        }
      ]
    },
    {
      "uid": "0x167896c",
      "b": [
        {
          "uid": "0x167897e",
          "~a": [
            {
              "uid": "0x1678946"
            }
          ],
          "b|amount": "5"
        }
      ]
    }
  ]
}

So basically your issue is just like this one Aggregating facet variables
See my last comment there.

Also see this example