I am using this Query
g.E().as('ID').select('ID').properties().as('PROP').select('PROP','ID')
It searches for all Edges with Properties but ignores every Edge who has no property.
I want to know How can I improve this query to search for every Edge with and without properties and give all the Data of the Edge (for example ID,SourceVertic, TargetVertic, label and the propeties).
In general looking at all edges in a graph can be expensive if you have a lot of edges. It is in general not a good idea to do this on large graphs. I used a limit step in my example below which is one way to look at just some edges. However, that said, you can see all of the properties on an edge using valueMap
. For example (from a graph I have that tracks soccer matches):
gremlin> g.E().valueMap().with(WithOptions.tokens).limit(5)
==>[id:400,label:played,date:12 Apr 2014,result:1-0]
==>[id:401,label:played,date:12 Apr 2014,result:1-0]
==>[id:402,label:played,date:12 Apr 2014,result:0-1]
==>[id:403,label:played,date:12 Apr 2014,result:1-0]
==>[id:404,label:played,date:12 Apr 2014,result:0-1]
EDITED to add:
If you want to include the adjacent vertices in the result and the graph database you are using supports Apache TinkerPop at the 3.4.4 level or higher you may be able to use the elementMap
step. An example is shown below.
gremlin> g.E().limit(5).elementMap()
==>[id:34,label:member,IN:[id:1,label:EPL],OUT:[id:2,label:Team],years:22]
==>[id:35,label:member,IN:[id:1,label:EPL],OUT:[id:3,label:Team],years:22]
==>[id:36,label:member,IN:[id:1,label:EPL],OUT:[id:4,label:Team],years:22]
==>[id:37,label:member,IN:[id:1,label:EPL],OUT:[id:5,label:Team],years:22]
==>[id:38,label:member,IN:[id:1,label:EPL],OUT:[id:6,label:Team],years:22]
If the database you are using does not support elementMap
you would need to do something like:
gremlin> g.E().limit(5).
......1> project('EDGE','IN','OUT').
......2> by(valueMap().with(WithOptions.tokens)).
......3> by(inV().union(id(),label()).fold()).
......4> by(outV().union(id(),label()).fold())
==>[EDGE:[id:34,label:member,years:22],IN:[1,EPL],OUT:[2,Team]]
==>[EDGE:[id:35,label:member,years:22],IN:[1,EPL],OUT:[3,Team]]
==>[EDGE:[id:36,label:member,years:22],IN:[1,EPL],OUT:[4,Team]]
==>[EDGE:[id:37,label:member,years:22],IN:[1,EPL],OUT:[5,Team]]
==>[EDGE:[id:38,label:member,years:22],IN:[1,EPL],OUT:[6,Team]]