I am using Java with TinkerPop v. 3.5.1 with Neptune DB
I am trying to use either .path().by("fieldName").by("otherFieldName")
but I am only getting the value from the last .by("otherFieldName")
returned, when I want the values from both .by()
.
Here is a sample graph (generated in 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')
When I use:
g.V().has("name", "Jefferson").out("offers").aggregate("x").by("level").by("name").cap("x")
I only get the "name" fields returned:
[
[
"English",
1,
"Math",
1
]
]
Also, what are the 1
fields in the returned value? There is no "level" field in the start node (School). The "level" values should both be 2
if it was from the Class
node.
Is there some way to return the values for multiple fields in the vertex?
I was going to guess you ran those experiments using Gremlify (I recognize the way Gremlify outputs a graph) and then I saw your comment about using it. That tool post processes the JSON result from Gremlin queries. What you are seeing there is the "bulk" count from the BulkSet created by aggregate
. If you were to run the same query on TinkerGraph or Neptune, you would not see those 1
values.
Anyway, if you want to aggregate the name and the level, one way to do it is as follows:
g.V().has("name", "Jefferson").
out("offers").
aggregate("x").by(values("level","name").fold()).
cap("x")
which (on Neptune) returns:
[[2, 'Math'], [2, 'English']]
The by
modulators are applied in a round-robin fashion. In the case of aggregate
only one value per instance of "x" is required, so the last by
modulator is used.
I assume this is part of a bigger query that you are working on as in reality the aggregate
adds no value in the example given as you could just do values('name','level').fold()
right after the out()
step.