I'm trying to figure out a better way of querying titan
with gremlin
through the python library bulbs
.
I have a simple tree
n0
/ \
/ \
n1 n2
/ \ \
n3 n4 n5
and I want to get n4
and the edges: e[n0 -> n1] => e1
, e[n1 -> n4] => e2
leading up to n4
. So in this example I want [e1, e2, n4]
I know all the indexes of the nodes before I do a query. In this example node_ids = ['ddbe4d52e7034ffeb17c9426fc1484af, '754d5e84daad4140ba93cb10ce00cde0', '7b2848543b444fcc94e69d7930ffa996']
With this information I can build this query which I feel is rather long and repetitive
g.V('nid', 'ddbe4d52e7034ffeb17c9426fc1484af').out
.has('nid', '754d5e84daad4140ba93cb10ce00cde0').out
.has('nid', '7b2848543b444fcc94e69d7930ffa996')
This only gives me the last node. I'm still trying to figure out this sideAffect
thing that gremlin
has to return the edges that I need.
I know I can create custom scripts and use those thorough gremlin
, but I'm very new to all this stuff so help would be appreciated.
pseudo code of something I'm looking for
def get_node(nodes) {
edges = []
for node in nodes:
get first node
find edge that goes to second node
edges.append(edge)
return edges + last node
}
Also if anyone has a good tutorial on gremlin/groovy that would be helpful
Thanks
You can get the path. Try:
g.V('nid', 'ddbe4d52e7034ffeb17c9426fc1484af').outE.inV
.has('nid', '754d5e84daad4140ba93cb10ce00cde0').outE.inV
.has('nid', '7b2848543b444fcc94e69d7930ffa996').path
This gives you a list with:
[startVertex, startIntermediateEdge, intermediateVertex, intermediateTargetEdge, targetVertex]