【问题标题】:How does searching for a vertex happen in graph databases using gremlin (Apache TinkerPop)?如何使用 gremlin (Apache TinkerPop) 在图形数据库中搜索顶点?
【发布时间】:2019-10-28 19:55:16
【问题描述】:

我正在对我的数据进行建模,例如 ->

data: [
 {
  id:"123",
  type:"a",
  attributes: [...]
 },
 {entity 2 ...},
 {entity 3 ...},
 ...
]

是否有一个 gremlin 查询可以用来按类型和 id 而不是 id 来获取/获取顶点? 如果没有,我是否必须遍历和搜索,如果是,性能会是什么样子?

【问题讨论】:

    标签: java graph-databases gremlin amazon-neptune


    【解决方案1】:

    Gremlin 中的实体类型称为Label

    要通过 id 获取顶点并验证它是否具有特定标签,您可以运行查询:

    g.V('123').hasLabel('a').next()
    

    如果 type 只是一个常规属性(属性),您可以运行:

    g.V('123').has('type', 'a').next()
    

    性能取决于实现,但在任何情况下通过 id 获取顶点都应该是 O(1)。

    【讨论】:

    • 我接受了,我还没有足够的声望来投票。另一个问题:我可以有 2 个具有相同 id 但不同标签的独立节点吗?例如: Vertex 1 label="Customer" id="123" Vertex 2 label="Account" id="123"
    • 不,不同的顶点不能有相同的ID。
    猜你喜欢
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2023-01-15
    • 2021-12-25
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 2017-05-06
    相关资源
    最近更新 更多