0
votes

Query

g.withSack(0).V().hasLabel('A').has('label_A','A').union(__.emit().repeat(sack(sum).by(constant(1)).in()),emit().repeat(sack(sum).by(constant(-1)).out())).project('level','properties').by(sack()).by(tree().by(valueMap().by(unfold())).unfold().unfold())

Output

[
    {
        "level": 0,
        "properties": {
            "key": {
                "label_A": "A"
            },
            "value": {}
        }
    },
    {
        "level": 1,
        "properties": {
            "key": {
                "label_A": "A"
            },
            "value": {
                "{label_B="B"}": {}
            }
        }
    },
    {
        "level": 2,
        "properties": {
            "key": {
                "label_A": "A"
            },
            "value": {
                "{label_B=B}": {
                    "{label_C=C}": {}
                }
            }
        }
    },

The query only returns the properties of nodes. Please modify the query so that it returns properties of nodes as well as relations respectively in tree format.

1

1 Answers

1
votes

If you want to get the properties of the edges you need to pass through them, split the out and in steps into outE().inV() and inE().outV(). then the tree step will take them into account.

Also if you want to specify the return value on the edges you can add a second by modulator to the tree step.

g.withSack(0).V().hasLabel('material').
  has('label_A', 'A').union(
    __.emit().repeat(sack(sum).
        by(constant(1)).
      inE().outV()),
    emit().repeat(sack(sum).
        by(constant(-1)).
      outE().inV())
  ).
  project('level', 'properties').by(sack()).
    by(tree().
        by(valueMap().by(unfold())).
        by(valueMap()))

example: https://gremlify.com/rixszg1ougl