Yet yet another example

Daniel has again posted a short example of how to use Gremlin to query the data out of a graph database.

This is the sample graph definition:

g = TinkerGraph.open()
A = g.addVertex(id, "A")
B1 = g.addVertex(id, "B1")
B2 = g.addVertex(id, "B2")
B3 = g.addVertex(id, "B3")
C = g.addVertex(id, "C")
D = g.addVertex(id, "D")
E = g.addVertex(id, "E")
A.addEdge("link", B1)
A.addEdge("link", B2)
A.addEdge("link", B3)
B1.addEdge("link", C)
B3.addEdge("link", C)
B2.addEdge("link", D)
B1.addEdge("link", E)
B2.addEdge("link", E)

And here comes the query to "identify, for each node connected to A in this way, the subset of B nodes":

gremlin> A.out("link").as("a").out("link").as("b").select().group().by {it.get("b")}.by {it.get("a")}
==>[v[C]:[v[B1], v[B3]], v[D]:[v[B2]], v[E]:[v[B1], v[B2]]]

results matching ""

    No results matching ""