Skip to content

Tinkerpop gremlin cheat sheet

Erwan Demairy edited this page Sep 5, 2017 · 3 revisions

Create a TitanDb graph

Graph graph = TinkerGraph.open();

Open/Create a TitanDb graph

graph_store = TitanFactory.open('berkeleyje:/tmp/graph')

Add a property key of type String

mgr.makePropertyKey("v_value").dataType(String.class).make()

Create an index on a property key

mgr = graph_store.openManagement() keyV = mgr.getPropertyKey("v_value") mgr.buildIndex("vertices", Vertex.class).addKey(keyV).buildCompositeIndex() mgr.commit()

Store and reindex data

import com.thinkaurelius.titan.graphdb.database.management.ManagementSystem mgr = graph_store.openManagement() ManagementSystem.awaitGraphIndexStatus(graph_store, "vertices").status(SchemaStatus.REGISTERED).call() mgr.updateIndex(mgr.getGraphIndex("vertices"), SchemaAction.REINDEX).get()

list open transactions

graph.getOpenTransactions() commit opened transactions

txs = graph_store.getOpenTransactions()

txs.forEach( a -> a.commit() ) `

Add a vertex

v1 = graph_store.addVertex(T.label, "Type1", "v_value", sb.toString())

Use the gremlin console

`$ ~/Developpement/apache-tinkerpop-gremlin-console-3.2.4/bin/gremlin.sh

path="path_to_db_root" g = Neo4jGraph.open(path)

`