简体   繁体   English

Gremlin查询进入和退出给定顶点的边缘

[英]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.

相关问题 Gremlin 查询 select 顶点基于输出顶点的特定子集上的输出边数 - Gremlin query to select vertex based on count of out edges on a particular subset of out vertex Gremlin的边共享相同的顶点 - Gremlin get edges sharing the same vertex Gremlin获取所有传入和传出的顶点,包括它们的边缘和方向 - Gremlin get all incoming and outgoing vertex, including their edges and directions Gremlin:从给定顶点查找所有下游(出)路径 - Gremlin: Find all downstream (out) paths from given Vertex Gremlin 查询:到目前为止如何获取查询中的所有“内部”边缘? - Gremlin Query: How to get all "internal" edges in the query so far? 对于给定的遍历 gremlin 查询,如何在所有访问过的节点/边上应用静态步骤 - How to apply a static has step on all the visited nodes/edges for a given traversal gremlin query 如果在 1 Gremlin 查询中不存在顶点和边,则创建 - Create if not exist Vertex and Edge in 1 Gremlin Query 删除所有接触给定顶点的边 - Remove all edges touching a given vertex 在boost graph lib中,如何在不遍历该顶点的所有边缘的情况下获得该顶点的特定边缘? - in boost graph lib, how do I get a specific out-edge of a vertex without iterating over all the out-edges of that vertex? 如何在 Amazon Neptune 中使用 Gremlin 有条件地添加顶点和多条边? - How can I conditionally add a vertex and multiple edges using Gremlin in Amazon Neptune?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM