gremlin 操作 janusgraph 的基本语句
核心概念:
- Vertex, Edge, Property.
- Graph, Directed.
- 图数据库即是内存密集型也是CPU密集型.
- 图数据库做为其它数据库的一个补充.
建立本地连接
:remote connect tinkerpop.server conf/remote.yaml session
:remote console timeout none
打印 schema
mgmt = graph.openManagement()
mgmt.printSchema()
mgmt.printVertexLabels()
mgmt.printEdgeLabels()
mgmt.printPropertyKeys()
mgmt.printIndexes()
create schema & index
mgmt = graph.openManagement()
batch = mgmt.makeVertexLabel('batch').make()
date = mgmt.makePropertyKey('date').dataType(String.class).make()
hour = mgmt.makePropertyKey('hour').dataType(Integer.class).make()
mgmt.addProperties(batch, date, hour)
mgmt.buildIndex('indexBatchByDateHour', Vertex.class).addKey(date).addKey(hour).buildCompositeIndex()
# 只在这个 Vertex 上的 index
mgmt.buildIndex('indexBatchByDateHour', Vertex.class).addKey(date).addKey(hour).indexOnly(batch).unique().buildCompositeIndex()
mgmt.commit()
g.tx().commit();
对已有数据建立 index
graph.tx().rollback()
mgmt = graph.openManagement()
key = mgmt.getPropertyKey('key')
myIndex = mgmt.buildIndex('byKey', Vertex.class).addKey(key).unique().buildCompositeIndex()
mgmt.commit()
graph.tx().commit();
//Wait for the index to become available
ManagementSystem.awaitGraphIndexStatus(graph, 'byKey').call()
//Reindex the existing data
mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("byKey"), SchemaAction.REINDEX).get()
mgmt.commit()
未结束的 transactions
graph.getOpenTransactions()
graph.getOpenTransactions().getAt(0).rollback()
graph.getOpenTransactions().getAt(0).commit()
查看 index
mgmt.getGraphIndexes(Vertex.class)
mgmt.getGraphIndexes(Edge.class)
mgmt.getGraphIndex("indexBatchByDateHour")
查看 console 信息
$> Gremlin.version()
$> :show imports
查看当前 Graph 支持的 features
$ graph.features()
$ graph.toString()
使用 tinkergraph
$ :plugin use tinkerpop.tinkergraph
$ graph = TinkerGraph.open()
$ g = graph.traversal()