I am using Java with Tinkerpop v. 3.5.1
I have a graph DB that contains many "smaller" graphs in it. I want to traverse the graph from a starting point (it could be different depending on the query) and collect some properties from different vertices along the way.
The basic outline of a "smaller" graph looks like:
Admin
|
v
Student --> School --> Class <-- ClassReq
edited: (I made some small progress, so here is where I am at now)
Here is an example graph from gremlify:
g.addV('Student').as('1').
property(single, 'name', 'Peter').
property(single, 'age', 22).addV('School').
as('2').
property(single, 'name', 'Jefferson').
property(single, 'address', '1234 Jefferson St.').
addV('Administration').as('3').
property(single, 'status', 'AFW').
property(single, 'level', '4.2A').
addV('Class').as('4').
property(single, 'name', 'Math').
property(single, 'level', 2).addV('ClassReq').
as('5').
property(single, 'name', 'Math').
property(single, 'level', 1).addV('Student').
as('6').
property(single, 'name', 'Sam').
property(single, 'age', 24).addV('Class').
as('7').
property(single, 'name', 'English').
property(single, 'level', 2).addE('attends').
from('1').to('2').addE('administers').
from('3').to('2').addE('isReqsFor').from('5').
to('4').addE('offers').from('2').to('4').
addE('attends').from('6').to('2').
addE('offers').from('2').to('7')
I am trying to use .aggregate()
with .by()
, but I am not getting all of the values out that I am expecting.
g.V().has("name", "Jefferson").out("offers").aggregate("x").by("level").by("name").cap("x")
If I do that, I only get the last .by()
fields returned:
[
[
"English",
1,
"Math",
1
]
]
I don't know what those 1
fields are, because the level
that I was expecting are 2
. But even if I don't include the level
as a .by()
, I get the exact same result.
From the Tinkerpop docs, it looks like I should be able to use .by("someField").by("someOtherField")
and it would return both fields...but I am not getting them.
gremlin> g.V().out().out().path().by('name').by('age')
==>[marko,32,ripple]
==>[marko,32,lop]
Edit: Sorry, forgot to add a desired result. I would like to have something like:
g.V().has("name", "Jefferson").out("offers").aggregate("x").by("level").by("name").cap("x").in("offers").out("administers").aggregate("y").by("status").cap("y").in("administers").out("attends").aggregate("z").by("name").by("age").cap("z)
And have it return the data, preferably as key/value pairs, but I am unsure how to get the data with .valueMap()
when I use .aggregate()
and .cap()
.
So a result something like:
[
[
"level": 2,
"name": "English
],
[
"level": 2,
"name": "Math
],
[
"status": "AFW"
],
[
"name": "Peter",
"age": 22
],
[
"name": "Sam",
"age": 24
]
]