Warm tip: This article is reproduced from serverfault.com, please click

How to find parent vertex of two child vertices with condition in GREMLIN?

发布于 2020-12-01 06:51:53

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'
Questioner
Deepak KS
Viewed
0
Taylor Riggan 2020-12-02 05:59:03

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.