简体   繁体   中英

How to implement Gremlin query corresponding to Neo4j cypher query?

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:)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM