0

I have the following Cypher query(neo4j) and want to convert it to a Gremlin query.

MATCH d=(a:Actor {id:" + entityId +'})-[r:ACTING_IN*0..2]-(m) WITH d, 
RELATIONSHIPS(d) AS rels WHERE NONE (rel in r WHERE rel.Type = "Hollywood") RETURN *
UNION
MATCH d=(aa:Actor{id: " + entityId + "})-[rel:PRODUCER_OF*0..2]->(mm:Movie) WITH d, 
RELATIONSHIPS(d) AS rels return *

Please help, Thanks :)

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
Ranjit Soni
  • 594
  • 6
  • 19

1 Answers1

1

If I understand correctly, then you are trying to run 2 variable length patterns to get path and relationship traversed in those paths. I think below query should do the trick:

g.V(" + entityId +").
  hasLabel("Actor").
  union(
    repeat(outE("ACTING_IN").hasNot('Type', "Hollywood").as('a').inV()).
      emit().
      times(2),
    repeat(outE("PRODUCER_OF").as('a').inV().hasLabel("Movie")).
      emit().
      times(2)).
  path().
  project("path", "relationship").by().by(select('a'), all)