Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gremlin query to get in and out edges for a given Vertex

I’m just playing with the Graph API in Cosmos DB which uses the Gremlin syntax for query.

I have a number of users (Vertex) in the graph and each have ‘knows’ properties to other users. Some of these are out edges (outE) and others are in edges (inE) depending on how the relationship was created. I’m now trying to create a query which will return all ‘knows’ relationships for a given user (Vertex). I can easily get the ID of either inE or outE via:

g.V('7112138f-fae6-4272-92d8-4f42e331b5e1').inE('knows') 
g.V('7112138f-fae6-4272-92d8-4f42e331b5e1').outE('knows') 

where '7112138f-fae6-4272-92d8-4f42e331b5e1' is the Id of the user I’m querying, but I don’t know ahead of time whether this is an in or out edge, so want to get both (e.g. if the user has in and out edges with the ‘knows’ label). I’ve tried using a projection and OR operator and various combinations of things e.g.:

g.V('7112138f-fae6-4272-92d8-4f42e331b5e1').where(outE('knows').or().inE('knows'))

but its not getting me back the data I want.

All I want out is a list of the Id’s of all inE and outE that have the label ‘knows’ for a given vertex.

Or is there a simpler/better way to model bi-directional associations such as ‘knows’ or ‘friendOf’?

Thanks

like image 430
LDJ Avatar asked Dec 13 '22 21:12

LDJ


1 Answers

You can use the bothE step in this case. g.V('7112138f-fae6-4272-92d8-4f42e331b5e1').bothE('knows')

like image 180
pantalohnes Avatar answered Jan 19 '23 01:01

pantalohnes