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": { }
}

}

応答で Vertex "NotificationInitiatedByVertexId" (Edge Property ) の情報も取得したい。そのために、次のクエリを試しました:

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 が新しい ID を生成します)、それを整理しようとすると混乱します。

Notificationそれが Titan で生成された識別子ではなく、あなたが作成した論理的な識別子である場合でも、グラフ スキーマを調整し、それを頂点に昇格させることを検討すると思います。そうすれば、Gremlin トラバーサルがより簡単に流れるようになります。

これを変更しないと仮定すると、同じリクエストで 2 つのクエリを発行して、結果を 1 つのデータ構造に結合しない理由がわかりません。頂点 ID を使用してルックアップを行うだけで、非常に高速で安価になります。

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 に答える