【问题标题】:Retrieve all vertices from root vertex joined by edges with Gremlin query使用 Gremlin 查询从由边连接的根顶点检索所有顶点
【发布时间】:2021-10-11 11:31:30
【问题描述】:

如何在 Gremlin 查询中检索从根顶点开始的所有顶点属性?

我们有以下结构:
根顶点:员工

优势:教育公司、教育部门、教育角色
顶点:公司、部门、角色

我们正在尝试接收与根顶点连接的其他顶点的数据。 有这样的想法:

{
    "employee": [
        {
            "id": "1",
            "label": "Employee",
            "type": "vertex",
            "properties": { ... },
            "company": { 
                "id": "A220",
                "label": "Company",
                "type": "vertex",
                "properties": { ... }, 
            },
            "department": { ... },
            "edge": { ... }
        },
        { ... }
    ]
}

我们已经尝试过该查询,但返回了一个复杂的 JSON:

g.V().hasLabel("Employee").inE().outV().tree()

编辑:

我们也尝试过 Kelvin 建议的查询:

g.V().hasLabel("Employee").inE().outV().tree().by(valueMap())  

Stacktrace:
提交查询失败:gV().hasLabel("Employee").inE().outV().tree().by(valueMap()):服务器序列化错误: ActivityId:29f4b64e-c476-44b8-8e35-a07dd31d4242 ExceptionType:GraphSerializeException ExceptionMessage:Gremlin 序列化错误:GraphSON V1_0 序列化程序无法将类型对象序列化:MapField 为原始值以执行所需的 Gremlin 步骤

【问题讨论】:

    标签: json gremlin azure-cosmosdb-gremlinapi gremlinnet


    【解决方案1】:

    如果您只需要来自根的树,您只需在查询中添加by(valueMap()) 即可获取包含的属性。如:

    g.V().hasLabel("Employee").
      inE().
      outV().
      tree().
        by(valueMap())
    

    【讨论】:

    • 我已经尝试过您的查询,但它不起作用。请检查我的编辑
    • 看起来您正在使用 GraphSON V1 序列化程序 - 请尝试使用 V3 序列化程序或 GraphBinary 序列化程序。这不是查询。这是正在使用的序列化程序。
    • 我无法使用 V3,因为 Azure Cosmos DB + Gremlin 仅支持 V1/V2 序列化程序。在这种情况下我该怎么办?
    • 我不确定 Cosmos 支持和不支持什么。您可以尝试仅使用单个属性键名称而不是 valueMap。您是否尝试过 V2 序列化程序以防万一?是否支持 GraphBinary?
    • 我会尝试使用单个属性键,但是 V2 和 GraphBinary 不起作用。感谢支持
    猜你喜欢
    • 2023-01-15
    • 1970-01-01
    • 1970-01-01
    • 2018-07-14
    • 1970-01-01
    • 2017-03-02
    • 2023-01-15
    • 2017-11-03
    • 1970-01-01
    相关资源
    最近更新 更多