Steps | Meaning |
---|---|
|
get all vertices in the graph |
|
get all edges in the graph |
|
get all vertices with the specified labels |
|
get all vertices with the specified label and the property |
|
get the vertex with the id |
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V()
==>v[1]
==>v[2]
==>v[3]
==>v[4]
==>v[5]
==>v[6]
gremlin> g.V().hasLabel("person")
==>v[1]
==>v[2]
==>v[4]
==>v[6]
gremlin> g.V().has("person","name","marko")
==>v[1]
gremlin> g.V(1)
==>v[1]
Steps | Meaning |
---|---|
|
get all specified properties for the current element |
|
get all specified property values for the current element |
|
get all specified property values for the current element as a map |
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().hasLabel("person").properties("name")
==>vp[name->marko]
==>vp[name->vadas]
==>vp[name->josh]
==>vp[name->peter]
gremlin> g.V().hasLabel("person").values("name")
==>marko
==>vadas
==>josh
==>peter
gremlin> g.V().hasLabel("person").valueMap("name","age")
==>[name:[marko],age:[29]]
==>[name:[vadas],age:[27]]
==>[name:[josh],age:[32]]
==>[name:[peter],age:[35]]
Steps | Meaning |
---|---|
|
get all adjacent vertices connected by outgoing edges with the specified labels |
|
get all adjacent vertices connected by incoming edges with the specified labels |
|
get all outgoing edges with the specified labels |
|
get all incoming edges with the specified labels |
|
get all adjacent vertices connected by an edge with the specified labels |
|
traverse to all incident edges with the specified labels and then to the respective other vertices |
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V(1).outE("created")
==>e[9][1-created->3]
gremlin> g.V(1).out("created")
==>v[3]
gremlin> g.V().has("software","name","lop").in("created").values("name")
==>marko
==>josh
==>peter
Steps | Meaning |
---|---|
|
keep the current element if the specified property has the given value |
|
keep the current element if the specified property matches the given predicate |
|
keep the current element if the provided traversal emits a result |
|
keep the current element if the provided traversal doesn’t emit a result |
|
keep the current element if it matches the predicate referencing another element |
Note
|
Predicates are used to compare values based on equality, ranges or certain patterns. All TinkerPop predicates are implemented as static methods; a full list of TinkerPop predicates can be found in the JavaDocs for P and TextP. |
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().has("age",29).valueMap("name","age")
==>[name:[marko],age:[29]]
gremlin> g.V().has("age",gt(30)).valueMap("name","age")
==>[name:[josh],age:[32]]
==>[name:[peter],age:[35]]
gremlin> g.V().filter(outE())
==>v[1]
==>v[4]
==>v[6]
gremlin> g.V().not(outE())
==>v[2]
==>v[3]
==>v[5]
gremlin> g.V(1).as("other").
......1> out("knows").where(gt("other")).by("age").
......2> valueMap()
==>[name:[josh],age:[32]]
Steps | Meaning |
---|---|
|
store the current element in the side-effect with the provided key |
|
store all elements held by all current traversers in the side-effect with the provided key |
|
group all current elements by the provided |
|
fold all current elements into a single list |
|
unfold the incoming list and continue processing each element individually |
|
count the number of current elements |
|
find the min/max value |
|
compute the sum of all current values |
|
compute the mean value of all current values |
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().hasLabel("person").store("x").select("x")
==>[v[1]]
==>[v[1],v[2]]
==>[v[1],v[2],v[4]]
==>[v[1],v[2],v[4],v[6]]
gremlin> g.V().hasLabel("person").aggregate("x").select("x")
==>[v[1],v[2],v[4],v[6]]
==>[v[1],v[2],v[4],v[6]]
==>[v[1],v[2],v[4],v[6]]
==>[v[1],v[2],v[4],v[6]]
gremlin> g.V().group().by(label)
==>[software:[v[3],v[5]],person:[v[1],v[2],v[4],v[6]]]
gremlin> g.V().fold()
==>[v[1],v[2],v[3],v[4],v[5],v[6]]
gremlin> g.V().count()
==>6
gremlin> g.V().fold().count(local)
==>6
Steps | Meaning |
---|---|
|
execute all branches and emit their results |
|
|
|
value-based traversal; If an option value matches the value emitted by the |
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().hasLabel("person").union(out("knows"), count())
==>v[2]
==>v[4]
==>4
gremlin> g.V().hasLabel("person").
......1> choose(has("age",gt(30)), constant("senior"), constant("junior"))
==>junior
==>junior
==>senior
==>senior
gremlin> g.V().hasLabel("person").values("age").
......1> union(min(), max(), sum(), mean(), count())
==>27
==>35
==>123
==>30.75
==>4
Steps | Meaning |
---|---|
|
add a new vertex |
|
adds a new edge between the two given vertices |
|
adds or updates the property with the given |
gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV('company').
......1> property('name','datastax').as('ds').
......2> addV('software').
......3> property('name','dse graph').as('dse').
......4> addV('software').
......5> property('name','tinkerpop').as('tp').
......6> addE('develops').from('ds').to('dse').
......7> addE('uses').from('dse').to('tp').
......8> addE('likes').from('ds').to('tp').iterate()
gremlin> g.V().outE().inV().path().by('name').by(label)
==>[datastax,develops,dse graph]
==>[datastax,likes,tinkerpop]
==>[dse graph,uses,tinkerpop]