Austin Osborne
Austin Osborne

Reputation: 45

Gremlin Python: Returning vertex IDs and edge properties in a list

I'm having a hard time returning the exact information I'm looking for. Essentially, I want to return all edges (in either direction) of a certain type. I'd like to get the vertex IDs and the edge parameters in a list. Ideally, my output format looks like this:

{
    "from": "vertex_id_1",
    "to": "vertex_id_2",
    "similarity": 0.45
}

I've been using g.both().vertexMap().toList() to get the similarities, but I'm not able to get the vertex IDs this way.

Upvotes: 1

Views: 1354

Answers (1)

stephen mallette
stephen mallette

Reputation: 46206

Using the toy graph as an example, you can best do this with project():

gremlin> g.V().bothE('knows').
......1>   project('from','to','weight').
......2>     by(outV().id()).
......3>     by(inV().id()).
......4>     by('weight')
==>[from:1,to:2,weight:0.5]
==>[from:1,to:4,weight:1.0]
==>[from:1,to:2,weight:0.5]
==>[from:1,to:4,weight:1.0]

Upvotes: 3

Related Questions