【问题标题】:In Gremlin, how to query two or more vertices with same value on one property?在 Gremlin 中,如何在一个属性上查询两个或多个具有相同值的顶点?
【发布时间】:2019-10-14 07:59:18
【问题描述】:

我想找到两个或多个具有相同属性的顶点。例如,找到两个具有相同名称的不同 Person vretice。 我尝试了以下方法:

graph.traversal().V().hasLabel("Person").as("a").where("a", P.eq("a")).by("name").where("a", P.neq("a")).by("vid").toList()

但结果为空(我很确定图中有合格的顶点。) 任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: gremlin tinkerpop3


    【解决方案1】:

    您必须扫描顶点两次。对于当前的遍历,您只需将每个顶点与其自身进行比较。

    g.V().hasLabel("Person").as("a").
      V().hasLabel("Person").as("b").
      where("a", P.eq("b")).by("name").
      where("a", P.neq("b"))
    

    【讨论】:

      猜你喜欢
      • 2021-09-05
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 2015-07-06
      • 2021-01-24
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      相关资源
      最近更新 更多