Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gremlin .match()

I have a query in Gremlin, using Datastax studio that looks like this:

g.V().has('vertexLabel', 'vertexProperty1', '12345').match(
    __.as('d').in('edgeLabel1').values('property2').as('NAME1'),
    __.as('d').in('edgeLabel2').values('property3').as('NAME2'),
    __.as('d').in('edgeLabel1').out('edgeLabel3').values('property4').as('NAME3')
    ).select('NAME1', 'NAME2', 'NAME3')

This works just fine if all entities exists, but if one of them is not on the graph, no results are found, even though I know there are. How can I make an .or query that will find the values if they exist. Say, if property4 was not found at the end of edgeLabel3, how can my query still give me the other two results (property2 and property3)? I've tried doing .or queries, but I haven't had any luck.

like image 945
user5294007 Avatar asked Sep 20 '26 20:09

user5294007


1 Answers

Have you tried using a union step in Gremlin? It should look something like this:

g.V('book:882178048:25').has('vertexLabel', 'vertexProperty1', '12345')
.union(
    as('d').in('edgeLabel1').values('property2').store('NAME1'),
    as('d').in('edgeLabel2').values('property3').store('NAME2'),
    as('d').in('edgeLabel1').out('edgeLabel3').values('property4').store('NAME3')
).cap('NAME1', 'NAME2', 'NAME3')
like image 167
bechbd Avatar answered Sep 24 '26 01:09

bechbd