【问题标题】:How to exclude certain vertices in gremlin titan如何排除gremlin titan中的某些顶点
【发布时间】:2017-01-13 06:44:53
【问题描述】:

例如,我想在查询时排除一些顶点 ID。

第 1 步:我正在让用户跟着我(1234):

g.V(1234).outE("关注")

输出: 9876,3246,2343,3452,1233,6545


第 2 步:我必须排除或删除某些 ID

用户 = [3452,1233,6545]; g.V(1234).outE("关注").inV().except(users)

输出: 9876,3246,2343。 它应该是这样的,但是 except 功能不起作用。是否有过滤特定顶点 ID 的解决方案。

【问题讨论】:

    标签: titan gremlin tinkerpop3


    【解决方案1】:

    很简单:

    users = [3452, 1233, 6545]
    g.V(1234).out("following").hasId(without(users))
    

    或者只是:

    g.V(1234).out("following").hasId(without(3452, 1233, 6545))
    

    【讨论】:

    • 这是正确答案。与这个相比,我的版本过于复杂!
    • 上述方法对我不起作用。有没有其他方法。
    • 不是错误。给定的顶点没有被过滤。例如,我给出这样的 1.g.V().out("following") ==> v[204804320] ==>v[204808416 ] ==>v[286724152]
    • 2 步:g.V().out("following").hasId(without(204804320, 204808416))。输出为:==>v[204804320] ==>v[204808416] ==>v[286724152]
    • 抱歉忘记添加这样的引号 g.V().out("following").hasId(without("3452","1233"));感谢它的工作
    【解决方案2】:

    您可以使用where 步骤过滤顶点。这允许您根据 id 排除顶点。以下查询应该会给您预期的结果:

    users = [3452,1233,6545];
    g.V(1234).out("following").where(__.not(hasId(within(users))))
    

    请注意,我使用out() 作为outE().inV() 的缩写形式,它允许直接遍历相邻顶点。

    【讨论】:

      猜你喜欢
      • 2016-09-15
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-18
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      相关资源
      最近更新 更多