1. 创建工作实例
graph = TitanFactory.open(‘conf/titan-hbase-es.properties’)
2. 创建遍历器
g = graph.traversal(standard())
3. 创建顶点
jack = graph.addVertex(T.label, “person”,“name”, “jack”, “age”, 29)
marry = graph.addVertex(“name”, “marry”, “age”, 29)
mofan = g.addV(‘name’,‘mofan’,‘sex’,‘man’)
4. 创建边
marry.addEdge(‘know’,jack)
5. 顶点属性
marry.property(‘sex’,‘man’) // 设置属性和修改
marry.properties(‘sex’) //查看属性
6. and操作,可以根据and里边的条件进行过滤
g.V().and(outE(‘lives’),values(‘age’).is(lt(5000))).values(‘name’)
7. 顶点获取边
g.V().has(‘name’,‘pluto’).both(‘pet’).values() //获取双向边顶点
g.V().has(‘name’,‘pluto’).outE() // 获取出边
g.V().has(‘name’,‘pluto’).inE() //获取入边
8. 边获取顶点
g.V().has(‘name’,‘pluto’).outE(‘pet’).inV().values(‘name’) //边in方向顶点
g.V().has(‘name’,‘pluto’).outE(‘pet’).outV().values(‘name’) // 边out方向顶点
g.V().has(‘name’,‘pluto’).outE(‘pet’).bothV().values(‘name’) // 边双方向顶点
9. 查询集合条数限制
g.V().count() //统计顶点个数
g.V().range(m,n) // 指定上下界,左闭右开
g.V().limit(n) // 从0开始查询n个
g.V().tail(n) //从尾部查询n个
10. 获取查询路径
g.V().has(‘name’,‘hercules’).as(‘h’).out(‘father’).out(‘brother’).out(‘pet’).path()
11. 循环操作
g.V().has(‘name’,‘hercules’).repeat(out()).times(3).emit(hasLabel(‘god’)).values(‘name’)
// repeat 重复的操作,times 重复次数,emit 重复查询结果进行保存
12. 排序
g.V().has(‘age’).order().by(‘age’,decr).values(‘age’) // decr 降序, incr升序
13. 分组
g.V().has(‘age’).group().by(‘age’)
14. 条件判断
g.V().has(‘name’,‘jupiter’).as(‘j’).out(‘brother’).out(‘brother’).as(‘b’).where(‘j’,neq(‘b’)).values()
g.V().filter{it.get().label() == ‘god’}.values() // 进行过滤
15. 逻辑判断
g.V().values(‘age’).is(28) //判断年龄等于28的
g.V().values(‘age’).is(gte(28)) // 判断年龄大于等于28的,gt、lt 、lte
g.V().values(‘age’).is(inside(27, 29)) // 区间判断,开区间不包含27,与29
// and逻辑
g.V().and(outE(‘created’), values(‘age’).is(28)).values(‘name’)
g.V().where(outE(‘created’) .and() .values(‘age’).is(28)) .values(‘name’)
// or逻辑
g.V().or(outE(‘created’), values(‘age’).is(28)).values(‘name’)
16. 统计运算
sum()、max()、min()、mean() // 平均值
待完善。。。
这个作者整理的很全,比官方文档看着爽:https://blog.csdn.net/javeme/article/details/82631834