0

I need some help because im very new in graph databases.

Im running this Gremlin query on my DSE Graph:

g.V('user:589435392:512').out('events').inE('events')

The Graph view return

graph view

But Raw JSON return:

{
  "id": "{out_vertex={member_id=512, community_id=589435392, ~label=user}, local_id=d2e29e60-5fc2-11e6-87aa-8d7f17e3c204, in_vertex={member_id=0, community_id=100599424, ~label=events}, ~type=events}",
  "label": "events",
  "type": "edge",
  "inVLabel": "events",
  "outVLabel": "user",
  "inV": "events:100599424:0",
  "outV": "user:589435392:512"
},
{
  "id": "{out_vertex={member_id=1, community_id=1205145984, ~label=user}, local_id=7c838fd0-6327-11e6-87aa-8d7f17e3c204, in_vertex={member_id=0, community_id=100599424, ~label=events}, ~type=events}",
  "label": "events",
  "type": "edge",
  "inVLabel": "events",
  "outVLabel": "user",
  "inV": "events:100599424:0",
  "outV": "user:1205145984:1"
}

And I need something like this:

{ 
    "event": {"some infos about this event"},
    "users": [{"user1"}, {"user2"},...]
}

How can I achieve a JSON output which show all events for a user and all involved user for the Events?

stephen mallette
  • 45,298
  • 5
  • 67
  • 135

3 Answers3

1

You should try this query:

g.V('user:589435392:512').out('events').
  project('event','users').by().by(__.in('events').fold())
Daniel Kuppitz
  • 10,846
  • 1
  • 25
  • 34
0

You may want to look at the data model with this item. It appears as if a User is a Vertex and an Event is an edge. Did you think about creating events as edges?

To help with the gremlin syntax based on the existing User --Event--> User model

g.V().outE('Events') // will give you all edges for Events, including the vertices pointing in and out of the edge

in the query you wrote you are using out() which is equivalent to using outE().inV()

jlacefie
  • 614
  • 3
  • 5
0

When the description is a property of the event vertex, then the following query should work:

g.V().has('user','name','user1').out().as('event').in().as('user').select('event','user').by('description').by('name')
==>{event=some infos about this event, user=user1}
==>{event=some infos about this event, user=user2}

Apart from that, I wouldn't use events as an edge label and instead choose something more descriptive like triggeredEvent, hadEvent, or something like that.

Florian Hockmann
  • 2,634
  • 13
  • 24