查找连接到所有当前顶点的顶点

Finding Vertices that are connected to all current vertices

我对图形数据库和 gremlin 还很陌生,我遇到了与其他人类似的问题,请参阅 ,因为我正在尝试获取满足所选的所有条件的资源顶点物品。所以对于下图

这是创建示例数据的脚本:

g.addV("Resource").property("name", "Resource1")
g.addV("Resource").property("name", "Resource2")

g.addV("Criteria").property("name", "Criteria1")
g.addV("Criteria").property("name", "Criteria2")

g.addV("Item").property("name", "Item1")
g.addV("Item").property("name", "Item2")


g.V().has("Resource", "name", "Resource1").addE("isOf").to(g.V().has("Criteria", "name", "Criteria1"))
g.V().has("Resource", "name", "Resource2").addE("isOf").to(g.V().has("Criteria", "name", "Criteria1"))
g.V().has("Resource", "name", "Resource2").addE("isOf").to(g.V().has("Criteria", "name", "Criteria2"))

g.V().has("Item", "name", "Item1").addE("needs").to(g.V().has("Criteria", "name", "Criteria1"))
g.V().has("Item", "name", "Item2").addE("needs").to(g.V().has("Criteria", "name", "Criteria1"))
g.V().has("Item", "name", "Item2").addE("needs").to(g.V().has("Criteria", "name", "Criteria2"))

当我尝试以下操作时,我得到了资源 1 和 2,因为它正在查看与这两个条件相关的所有资源,而我只想要与这两个条件(资源 2)匹配的资源。

g.V()
    .hasLabel('Item')
    .has('name', 'Item2')
    .outE('needs')
    .inV()
    .aggregate("x")
    .inE('isOf')
    .outV()
    .dedup()

因此,如果我按照参考问题的建议尝试以下操作。

g.V()
    .hasLabel('Item')
    .has('name', 'Item2')
    .outE('needs')
    .inV()
    .aggregate("x")
    .inE('isOf')
    .outV()
    .dedup()
    .filter(
        out("isOf")
        .where(within("x"))
        .count()
        .where(eq("x"))
        .by()
        .by(count(local)))
        .valueMap()

我收到以下异常,因为为另一个问题提供的答案在 Azure CosmosDB 图形数据库中不起作用,因为 it doesn't support the gremlin Filter statement

Failure in submitting query: g.V().hasLabel('Item').has('name', 'Item2').outE('needs').inV().aggregate("x").inE('isOf').outV().dedup().filter(out("isOf").where(within("x")).count().where(eq("x")).by().by(count(local))).valueMap(): "Script eval error: \r\n\nActivityId : d2eccb49-9ca5-4ac6-bfd7-b851d63662c9\nExceptionType : GraphCompileException\nExceptionMessage :\r\n\tGremlin Query Compilation Error: Unable to find any method 'filter' @ line 1, column 113.\r\n\t1 Error(s)\nSource : Microsoft.Azure.Cosmos.Gremlin.Core\n\tGremlinRequestId : d2eccb49-9ca5-4ac6-bfd7-b851d63662c9\n\tContext : graphcompute\n\tScope : graphparse-translate-csharpexpressionbinding\n\tGraphInterOpStatusCode : QuerySyntaxError\n\tHResult : 0x80131500\r\n"

我很想知道是否有办法使用 MS 在 Azure CosmosDB 中提供的 gremlin 步骤来解决我的问题 (these)。

只需将 filter 替换为 where。 查询将同样有效。