【问题标题】:How Can I group by Gremlin Server (Titan 1.0) Response on Basis of Vertex Id?如何根据顶点 ID 按 Gremlin Server (Titan 1.0) 响应分组?
【发布时间】:2016-10-26 00:38:14
【问题描述】:

我正在尝试以下查询:

g.V(835776).out('Follow').in('WallPost').order().by('PostedTimeLong', decr).range(0,2)

我收到以下回复:

{

"requestId": "524462bc-5e46-40bf-aafd-64d00351dc87",
"status": {
    "message": "",
    "code": 200,
    "attributes": { }
},
"result": {
    "data": [
        {
            "id": 1745112,
            "label": "Post",
            "type": "vertex",
            "properties": {
                "PostImage": [
                    {
                        "id": "sd97-11ejc-2wat",
                        "value": ""
                    }
                ],
                "PostedByUser": [
                    {
                        "id": "sc2j-11ejc-2txh",
                        "value": "orbitpage@gmail.com"
                    }
                ],
                "PostedTime": [
                    {
                        "id": "scgr-11ejc-2upx",
                        "value": "2016-06-19T09:17:27.6791521Z"
                    }
                ],
                "PostMessage": [
                    {
                        "id": "sbob-11ejc-2t51",
                        "value": "Hello @[tag:Urnotice_Profile|835776|1]   , @[tag:Abhinav_Srivastava|872488|1]  and @[tag:Rituraj_Rathore|839840|1]"
                    }
                ],
                "PostedTimeLong": [
                    {
                        "id": "scuz-11ejc-2vid",
                        "value": 636019246476802029
                    }
                ]
            }
        },
        {
            "id": 1745112,
            "label": "Post",
            "type": "vertex",
            "properties": {
                "PostImage": [
                    {
                        "id": "sd97-11ejc-2wat",
                        "value": ""
                    }
                ],
                "PostedByUser": [
                    {
                        "id": "sc2j-11ejc-2txh",
                        "value": "orbitpage@gmail.com"
                    }
                ],
                "PostedTime": [
                    {
                        "id": "scgr-11ejc-2upx",
                        "value": "2016-06-19T09:17:27.6791521Z"
                    }
                ],
                "PostMessage": [
                    {
                        "id": "sbob-11ejc-2t51",
                        "value": "Hello @[tag:Urnotice_Profile|835776|1]   , @[tag:Abhinav_Srivastava|872488|1]  and @[tag:Rituraj_Rathore|839840|1]"
                    }
                ],
                "PostedTimeLong": [
                    {
                        "id": "scuz-11ejc-2vid",
                        "value": 636019246476802029
                    }
                ]
            }
        }
    ],
    "meta": { }
}

}

由于同一帖子发布在两个不同的 ID 上,因此它会出现两次响应。我想根据顶点 id 按响应分组(两者都有相同的顶点 id。或者我只想从它们中取出一个对象,因为它们都是相同的。

我尝试了以下查询,但对我没有任何帮助:

gV(835776).out('Follow').in('WallPost').groupBy{it.id}.order().by('PostedTimeLong', decr).range(0,3)

gV(835776).out('Follow').in('WallPost').group().by(id).order().by('PostedTimeLong', decr).range(0,3)

如何根据顶点 ID 对结果进行分组。

【问题讨论】:

    标签: graph titan gremlin gremlin-server


    【解决方案1】:

    查询

    g.V(835776).out('Follow').in('WallPost').group().by(id).order().by('PostedTimeLong', decr).range(0,3)
    

    应该可以工作,尽管order().by()range() 将不起作用。不过,我不认为你真的想group(),你更可能想dedup()

    g.V(835776).out('Follow').in('WallPost').dedup().order().by('PostedTimeLong', decr).limit(3)
    

    【讨论】:

      猜你喜欢
      • 2016-09-15
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 2016-12-02
      • 2021-09-14
      • 1970-01-01
      • 2013-06-28
      相关资源
      最近更新 更多