Search code examples
graphtitangremlingremlin-server

How Can I group by Gremlin Server (Titan 1.0) Response on Basis of Vertex Id?


I'm trying following query :

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

and I'm getting following response :

{

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

}

since same post is posted on two different Id's it is coming twice in response. I want to group by response on basis of vertex id ( both have same vertex id. or i just want to get one object out of them as both are same only.

I've tried following queries but nothing worked for me :

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

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

How can I group by the result on basis of vertex id.


Solution

  • The query

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

    should work, although order().by() and range() will have no effect. However, I don'tthink you really want to group(), you more likely want to dedup():

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