You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Gremlin查询所有Person到Person的连接(附Tinker Modern示例)

Finding All Person-to-Person Connections with Gremlin

Sure thing! If you need to pull every direct connection between Person nodes in the Tinker Modern sample graph—regardless of the edge type linking them—this Gremlin query will get you exactly what you need:

g.V().hasLabel("Person").bothE().bothV().hasLabel("Person").path().by(label())

Query Breakdown

Let’s break down each part to make it clear how this works:

  • g.V().hasLabel("Person"): Starts by selecting all vertices labeled Person in the graph
  • .bothE(): Grabs every edge connected to these Person vertices (covers both outgoing and incoming edges)
  • .bothV().hasLabel("Person"): Traverses to the opposite end of each edge, filtering to only keep vertices that are also labeled Person
  • .path().by(label()): Returns the full path for each valid connection, showing the label of each element (vertex or edge) in the sequence

Sample Results

When run against the Tinker Modern dataset, you’ll get these path results that map out all Person -> Edge -> Person relationships:

  • ['Person', 'knows', 'Person']
  • ['Person', 'knows', 'Person']
  • ['Person', 'created', 'Person']
  • ['Person', 'knows', 'Person']
  • ['Person', 'knows', 'Person']
  • ['Person', 'knows', 'Person']
  • ['Person', 'knows', 'Person']
  • ['Person', 'created', 'Person']
  • ['Person', 'created', 'Person']
  • ['Person', 'knows', 'Person']
  • ['Person', 'knows', 'Person']
  • ['Person', 'created', 'Person']

内容的提问来源于stack exchange,提问作者Srinath Ganesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:27:00