我们可以同时过滤多个标签吗

Can we filter multiple labels simultaneously

我有一个场景,我必须检查具有不同标签的多个顶点并匹配它们在父顶点下的属性。然后 return 父顶点,如果一切都匹配的话。

我尝试使用 'and' 子句和 'where' 子句编写查询,但 none 有效:

这是我的试验:

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')

请引导我走正确的道路

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

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

您已经在第一行有了想要 return 的 "parent",所以只需使用 where() 进行过滤并在其中添加过滤逻辑以遍历每个其中 "parents"。