I have the following graph:
V1
/ | \
p1 p2 p3
I want to find parent vertex (V1), if I have p1 and p3 vertices matching the condition in GREMLIN. I have around 25 child nodes for a single parent. And I need to find the parent with any of the child vertices matching the condition.
Ex: if P1, P2, P3 vertices has the following properties - name, value. I need to find parent vertex something like:
SELECT
V1
WHERE
P1.name = 'a' and P1.value = 'b'
AND P3.name = 'x' and P3.value = 'y'
(or)
SELECT
V1
WHERE
P2.name = 'p' and P2.value = 'q'
AND P3.name = 'x' and P3.value = 'y'
The best way to approach this is imperatively (arbitrarily choosing one of the child vertices to start with).
Here's the simplest form of such a query:
g.V().has('Child','name','p1').in('HAS').where(out('HAS').has('name','p2'))
The result of that query would be V1
.
Thank you Taylor for shift response. Yes, I am currently doing exactly the same way. But just thinking, if this is costly traversal to move to and forth from every child vertex to parent and back.
The imperative way is actually very efficient as you are touching the least number of components in the graph as possible. Would be good though to run this against Neptune's /gremlin/profile API endpoint once you get data loaded in to see exactly what the performance characteristics look like.