简体   繁体   中英

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 (eg 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 eg:

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

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

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