[英]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. 我只是在
Cosmos DB
中使用Graph API,它使用Gremlin语法进行查询。
I have a number of users (Vertex) in the graph and each have 'knows' properties to other users. 我在图中有许多用户(Vertex),每个用户都有“知道”属性给其他用户。 Some of these are out edges (outE) and others are in edges (inE) depending on how the relationship was created.
其中一些是外边缘(outE),另一些是边缘(inE),具体取决于关系的创建方式。 I'm now trying to create a query which will return all 'knows' relationships for a given user (Vertex).
我现在正在尝试创建一个查询,它将返回给定用户(Vertex)的所有“已知”关系。 I can easily get the ID of either inE or outE via:
我可以通过以下方式轻松获取inE或outE的ID:
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). 其中
'7112138f-fae6-4272-92d8-4f42e331b5e1'
是我正在查询的用户的ID,但我不知道这是一个进出边缘,所以想要得到两者(例如,如果用户具有“已知”标签的进出边缘。 I've tried using a projection and OR operator and various combinations of things eg: 我尝试过使用投影和OR运算符以及各种组合,例如:
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. 我想要的只是所有inE和outE的Id的列表,其具有给定顶点的'已知'标签。
Or is there a simpler/better way to model bi-directional associations such as 'knows' or 'friendOf'? 或者是否有更简单/更好的方法来模拟双向关联,例如'knows'或'friendOf'?
Thanks 谢谢
You can use the bothE
step in this case. 在这种情况下,您可以使用
bothE
步骤。 gV('7112138f-fae6-4272-92d8-4f42e331b5e1').bothE('knows')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.