【问题标题】:Can we filter multiple labels simultaneously我们可以同时过滤多个标签吗
【发布时间】:2018-09-12 18:35:19
【问题描述】:

我有一个场景,我必须检查具有不同标签的多个顶点并在父顶点下匹配它们的属性。如果一切正常,则返回父顶点。

我尝试使用“and”子句和“where”子句编写查询,但没有一个有效:

这是我的试验:

g.V().hasLabel('schedule').inE().outV().hasLabel('url').as('a').outE().inV().aggregate('x').hasLabel('schedule').has('name', '3').as('b').select('x').hasLabel('states').has('name', 'federal').as('c').select('a')

g.V().hasLabel('schedule').inE().outV().hasLabel('url').as('a').outE().where(inV().hasLabel('schedule').has('name', '3')).where(inV().hasLabel('states').has('name', 'federal')).select('a')

g.V().hasLabel('schedule').inE().outV().hasLabel('url').as('a').outE().and(inV().hasLabel('schedule').has('name', '3'),inV().hasLabel('states').has('name', 'federal')).select('a')

g.V().hasLabel('schedule').inE().outV().hasLabel('url').as('a').outE().inV().aggregate('x').hasLabel('schedule').has('name', '3').as('b').select('x').unfold().hasLabel('states').has('name', 'federal').as('c').select('a')

请引导我走正确的道路

【问题讨论】:

    标签: graph azure-cosmosdb gremlin tinkerpop3


    【解决方案1】:

    您绝对可以简化您的方法。我认为你不需要步骤标签和select() 来做你正在做的事情,这很好,因为它们会增加你的遍历成本。我试图重写你提供的第一个遍历,我希望我的逻辑是正确的,但无论如何,我想你会在看到变化时明白你需要做什么:

    g.V().hasLabel('schedule').in().hasLabel('url').
      where(and(out().hasLabel('schedule').has('name', '3'),
                out().hasLabel('states').has('name', 'federal')))
    

    您已经有了要在第一行返回的“父级”,因此只需使用where() 进行过滤,并在那里添加您的过滤逻辑以遍历每个“父级”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 2021-09-24
      • 2012-02-19
      • 2020-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多