When ading simplePath()
inside a match()
, my query no longer returns results.
The query attempts to find any event (e.g. "graph database conference") that somehow involves three specific people.
- "alice" attended the school that hosted the event.
- "bob" was a hot dog vendor at the event.
- "marko" provided security for the event.
I'm using match()
to find where the three people converge. If there's a better way, please suggest it. Thanks! Just starting to learn gremlin.
Ascii art:
alice --[enrolled-in]-> gremlin 101 --[offered-by]-> graph db school --[hosted]--------------
|
v
bob --[works-for]-> hot dogs r awesome --[subcontractor-of]-> best event planner --[planned]----> graph conference
^
|
marko --[works-for]-> super security --[secured]-------------
Query that works:
g.V().match(
__.as('alice').hasLabel('person').has('name', 'alice').repeat(__.out()).until(__.hasLabel('event')).as('event'),
__.as('event').repeat(__.in()).until(__.hasLabel('person').has('name', 'bob')).as('bob'),
__.as('event').repeat(__.in()).until(__.hasLabel('person').has('name', 'marko')).as('marko')).
path()
==>[v[0],v[0],v[2],v[5],v[21],v[21],v[13],v[10],v[8],v[21],v[18],v[16],[bob:v[8],alice:v[0],event:v[21],marko:v[16]]]
Note that some vertices appear more than once (and we haven't even added any cycles yet!)
When I add .simplePath()
to any of the repeat()
s, the query returns nothing. For example, inside the first repeat()
g.V().match(
__.as('alice').hasLabel('person').has('name', 'alice').repeat(__.out().simplePath()).until(__.hasLabel('event')).as('event'),
__.as('event').repeat(__.in()).until(__.hasLabel('person').has('name', 'bob')).as('bob'),
__.as('event').repeat(__.in()).until(__.hasLabel('person').has('name', 'marko')).as('marko')).
path()
gremlin-console:
alice = g.addV('person').property('name', 'alice').next()
gremlin101 = g.addV('course').property('name', 'gremlin 101').next()
g.addE('enrolled-in').from(alice).to(gremlin101)
school = g.addV('school').property('name', 'graph db school').next()
g.addE('offered-by').from(gremlin101).to(school)
bob = g.addV('person').property('name', 'bob').next()
hotDogs = g.addV('business').property('name', 'hot dogs r awesome').next()
g.addE('works-for').from(bob).to(hotDogs)
eventPlanner = g.addV('business').property('name', 'best event planner').next()
g.addE('subcontractor-of').from(hotDogs).to(eventPlanner)
marko = g.addV('person').property('name', 'marko').next()
security = g.addV('business').property('name', 'super security').next()
g.addE('works-for').from(marko).to(security)
event = g.addV('event').property('name', 'graph conference').next()
g.addE('hosted').from(school).to(event)
g.addE('secured').from(security).to(event)
g.addE('planned').from(eventPlanner).to(event)