简体   繁体   English

什么是Gremlin查询可以让我直接或间接连接到一个特定顶点的所有顶点

[英]What is the Gremlin query that can get me all the vertices either directly or indirectly connected to one specific vertex

I need help with a Gremlin query that can output all the vertices related to one specific vertex A and their cascading related vertices (which means all the vertices related directly or indirectly to A). 我需要一个Gremlin查询的帮助,该查询可以输出与一个特定顶点A及其级联相关顶点相关的所有顶点(这意味着所有顶点直接或间接与A相关)。

For example, in a graph 例如,在图表中

A -> B -> C
D

Running this query on A will give me B and C. 在A上运行此查询将给我B和C.

The solution I have right now is an ugly one: 我现在的解决方案是一个丑陋的解决方案:

gV('A').both(); gV('A').both().both();

etc 等等

Any help would be really appreciated. 任何帮助将非常感激。

Your solution isn't ugly; 你的解决方案并不难看; it only lacks a bit of iteration and an exit condition. 它只缺少一点迭代和退出条件。

Do you require a maximum depth? 你需要最大深度吗? Depending on the shape of your graph, the query you want to execute could be returning all vertices of that graph. 根据图形的形状,您要执行的查询可能会返回该图形的所有顶点。

Assuming a toy modern TinkerGraph created in the Gremlin console: 假设在Gremlin控制台中创建了一个玩具现代TinkerGraph:

gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]

This query could be helpful: 此查询可能会有所帮助:

gremlin> g.V(1).repeat(both().simplePath()).emit().times(3).dedup()
==>v[3]
==>v[2]
==>v[4]
==>v[6]
==>v[5]

"Starting from vertex with id=1, traverse the graph in all directions up to a maximum depth of 3 while discarding previously visited paths. The emit() step ensures that all traversed vertices found along the way, and not just leaves, are returned." “从id = 1的顶点开始,在所有方向上遍历图形,最大深度为3,同时丢弃先前访问过的路径emit()步骤确保返回沿途找到的所有遍历顶点,而不仅仅是叶子返回“。

Chances are high that you want to figure out which vertices are linked to that vertex only via specific edges. 您想要确定哪些顶点仅通过特定边链接到该顶点的机会很高。 In such case, you could be passing label(s) to the both() step, and/or maybe chain a few filters. 在这种情况下,您可以将标签传递给both()步骤,和/或链接一些过滤器。

When developing your query, feel free to chain the path() step to better understand the output. 在开发查询时,请随意链接path()步骤以更好地理解输出。

gremlin> g.V(1).repeat(both().simplePath()).emit().times(3).dedup().path()
==>[v[1],v[3]]
==>[v[1],v[2]]
==>[v[1],v[4]]
==>[v[1],v[3],v[6]]
==>[v[1],v[4],v[5]]

There are other ways to solve this, but this query should get you started and familiarize yourself with basic Gremlin steps and concepts. 还有其他方法可以解决这个问题,但是这个查询应该让您开始并熟悉基本的Gremlin步骤和概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gremlin 查询以获取所有直接和间接相关的顶点 - Gremlin query to get all the directly as well as indirectly related vertices 如何使用gremlin将所有顶点连接到组中至少两个其他顶点? - How to get all vertices connected to at least two other vertices in a group using gremlin? Gremlin - 获取映射到每个顶点的边类型的顶点列表 - Gremlin - get list of vertices mapped to edge type for each vertex Gremlin查询进入和退出给定顶点的边缘 - Gremlin query to get in and out edges for a given Vertex 带嵌套顶点的Gremlin查询 - Gremlin query with nested vertices Gremlin 查询以覆盖顶点 - Gremlin query to override the Vertex Gremlin查询Cosmos Graph DB以获取围绕单个顶点的图结构,过滤出具有特定标签的节点 - Gremlin query for Cosmos Graph DB to get the graph structure surrounding a single vertex, filtering out nodes with specific labels Gremlin 查询将顶点与不相关的顶点 CosmosDB 结合起来 - Gremlin query combine vertices with unrelated vertices CosmosDB 更新 Gremlin 中所有顶点的属性 - Update a property in all Vertices in Gremlin Gremlin 3-获取所有传入和传出的顶点,包括它们的边和方向,包括没有边的顶点 - Gremlin 3 - get all incoming and outgoing vertices, including their edges and directions and including vertices without edges
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM