0

我正在使用以下查询:

g.V(741440).outE('Notification').order().by('PostedDateLong', decr).range(0,1).as('notificationInfo').match(
    __.as('notificationInfo').inV().as('postInfo'),
).select('notificationInfo','postInfo')

它给出以下结果:

{

"requestId": "9846447c-4217-4103-ac2e-de3536a3c62a",
"status": {
    "message": "",
    "code": ​200,
    "attributes": { }
},
"result": {
    "data": [
        {
            "notificationInfo": {
                "id": "c0zs-fw3k-347p-g2g0",
                "label": "Notification",
                "type": "edge",
                "inVLabel": "Comment",
                "outVLabel": "User",
                "inV": ​749664,
                "outV": ​741440,
                "properties": {
                    "ParentPostId": "823488",
                    "PostedDate": "2016-05-26T02:35:52.3889982Z",
                    "PostedDateLong": ​635998269523889982,
                    "Type": "CommentedOnPostNotification",
                    "NotificationInitiatedByVertexId": "1540312"
                }
            },
            "postInfo": {
                "id": ​749664,
                "label": "Comment",
                "type": "vertex",
                "properties": {
                    "PostImage": [
                        {
                            "id": "amto-g2g0-2wat",
                            "value": ""
                        }
                    ],
                    "PostedByUser": [
                        {
                            "id": "am18-g2g0-2txh",
                            "value": "orbitpage@gmail.com"
                        }
                    ],
                    "PostedTime": [
                        {
                            "id": "amfg-g2g0-2upx",
                            "value": "2016-05-26T02:35:39.1489483Z"
                        }
                    ],
                    "PostMessage": [
                        {
                            "id": "aln0-g2g0-2t51",
                            "value": "hi"
                        }
                    ]
                }
            }
        }
    ],
    "meta": { }
}

}

我也想在响应中获取顶点“NotificationInitiatedByVertexId”(边缘属性)的信息。为此,我尝试了以下查询:

g.V(741440).outE('Notification').order().by('PostedDateLong', decr).range(0,2).as('notificationInfo').match(
  __.as('notificationInfo').inV().as('postInfo'),
  g.V(1540312).next().as('notificationByUser')
).select('notificationInfo','postInfo','notificationByUser')

注意:我直接尝试在子查询中使用顶点 ID,因为我不知道如何从查询本身的边缘属性中动态获取值。

它给出了错误。我尝试了很多,但找不到任何解决方案。

4

1 回答 1

1

我假设您将 Titan 生成的标识符存储在名为NotificationInitiatedByVertexId. 如果是这样,请考虑以下内容,即使第一部分并没有真正回答您的问题。我认为您不应该在边缘存储顶点标识符。您的图形模型应该明确地跟踪NotificationInitiatedBy与边缘的关系,并通过将顶点的标识符存储在边缘本身上,您可以绕过它。此外,如果您必须以某种方式迁移数据,则不会保留 id(Titan 会生成新的),并且尝试对其进行分类将是一团糟。

Even if that is not a Titan generated identifier and a logical one you created, I still think I would look to adjust your graph schema and promote that Notification to a vertex. Then your Gremlin traversals would flow more easily.

Now, assuming you don't change that, then I don't see a reason to not just issue two queries in the same request and then combine the results to one data structure. You just need to do a lookup with the vertex id which is going to be pretty fast and inexpensive:

edgeStuff = g.V(741440).outE('Notification').
              order().by('PostedDateLong', decr).range(0,1).as('notificationInfo').
              ...  // whatever logic you have
              select('notificationInfo','postInfo').next()
vertexStuff = g.V(edgeStuff.get('notificationInfo').value('NotificationInitiatedByVertexId')).next()
[notificationInitiatedBy: vertexStuff, notification: edgeStuff]
于 2016-05-26T20:06:00.183 回答