虚拟元素 | 意义 |
---|---|
粗体的关键字 |
图的索引 |
粗体加星的关键字 |
图的索引, 必须唯一 |
下划线的关键字 |
顶点中心索引 |
空心箭头的边 |
功能或者唯一的边(不能重复) |
尾巴带横线的边 |
单向的边, 只能按照一个方向进行访问 |
Important | |
---|---|
JanusGraph需要Java8(标准版本) 推荐使用Oracle Java8. JanusGraph 的脚本需要$JAVA_HOME环境变量指向JRE或者JDK的安装目录 |
$ unzip janusgraph-0.2.0-hadoop2.zip Archive: janusgraph-0.2.0-hadoop2.zip creating: janusgraph-0.2.0-hadoop2/ ... $ cd janusgraph-0.2.0-hadoop2 $ bin/gremlin.sh \,,,/ (o o) -----oOOo-(3)-oOOo----- 09:12:24 INFO org.apache.tinkerpop.gremlin.hadoop.structure.HadoopGraph - HADOOP_GREMLIN_LIBS is set to: /usr/local/janusgraph/lib plugin activated: tinkerpop.hadoop plugin activated: janusgraph.imports gremlin>
gremlin> 100-10 ==>90 gremlin> "JanusGraph:" + " The Rise of Big Graph Data" ==>JanusGraph: The Rise of Big Graph Data gremlin> [name:'aurelius', vocation:['philosopher', 'emperor']] ==>name=aurelius ==>vocation=[philosopher, emperor]
Tip | |
---|---|
Refer to Apache TinkerPop, SQL2Gremlin, and Gremlin Recipes for more information about using Gremlin. |
gremlin> graph = JanusGraphFactory.open('conf/janusgraph-berkeleyje-es.properties') ==>standardjanusgraph[berkeleyje:../db/berkeley] gremlin> GraphOfTheGodsFactory.load(graph) ==>null gremlin> g = graph.traversal() ==>graphtraversalsource[standardjanusgraph[berkeleyje:../db/berkeley], standard]
1. 为图创建了一系列全局, 顶点中心索引2. 为图添加了顶点, 和顶点的属性3. 为图添加了边, 和边的属性
gremlin> graph = JanusGraphFactory.open('conf/janusgraph-cassandra-es.properties') ==>standardjanusgraph[cassandrathrift:[127.0.0.1]] gremlin> GraphOfTheGodsFactory.load(graph) ==>null gremlin> g = graph.traversal() ==>graphtraversalsource[standardjanusgraph[cassandrathrift:[127.0.0.1]], standard]
gremlin> graph = JanusGraphFactory.open('conf/janusgraph-cassandra.properties') ==>standardjanusgraph[cassandrathrift:[127.0.0.1]] gremlin> GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true) ==>null gremlin> g = graph.traversal() ==>graphtraversalsource[standardjanusgraph[cassandrathrift:[127.0.0.1]], standard]
gremlin> saturn = g.V().has('name', 'saturn').next() ==>v[256] gremlin> g.V(saturn).valueMap() ==>[name:[saturn], age:[10000]] gremlin> g.V(saturn).in('father').in('father').values('name') ==>hercules
gremlin> g.E().has('place', geoWithin(Geoshape.circle(37.97, 23.72, 50))) ==>e[a9x-co8-9hx-39s][16424-battled->4240] ==>e[9vp-co8-9hx-9ns][16424-battled->12520] gremlin> g.E().has('place', geoWithin(Geoshape.circle(37.97, 23.72, 50))).as('source').inV().as('god2').select('source').outV().as('god1').select('god1', 'god2').by('name') ==>[god1:hercules, god2:hydra] ==>[god1:hercules, god2:nemean]
gremlin> hercules = g.V(saturn).repeat(__.in('father')).times(2).next() ==>v[1536]
gremlin> g.V(hercules).out('father', 'mother') ==>v[1024] ==>v[1792] gremlin> g.V(hercules).out('father', 'mother').values('name') ==>jupiter ==>alcmene gremlin> g.V(hercules).out('father', 'mother').label() ==>god ==>human gremlin> hercules.label() ==>demigod
gremlin> g.V(hercules).out('battled') ==>v[2304] ==>v[2560] ==>v[2816] gremlin> g.V(hercules).out('battled').valueMap() ==>[name:[nemean]] ==>[name:[hydra]] ==>[name:[cerberus]] gremlin> g.V(hercules).outE('battled').has('time', gt(1)).inV().values('name') ==>cerberus ==>hydra
gremlin> g.V(hercules).outE('battled').has('time', gt(1)).inV().values('name').toString() ==>[GraphStep([v[24744]],vertex), VertexStep(OUT,[battled],edge), HasStep([time.gt(1)]), EdgeVertexStep(IN), PropertiesStep([name],value)]
gremlin> pluto = g.V().has('name', 'pluto').next() ==>v[2048] gremlin> // who are pluto's cohabitants? gremlin> g.V(pluto).out('lives').in('lives').values('name') ==>pluto ==>cerberus gremlin> // pluto can't be his own cohabitant gremlin> g.V(pluto).out('lives').in('lives').where(is(neq(pluto))).values('name') ==>cerberus gremlin> g.V(pluto).as('x').out('lives').in('lives').where(neq('x')).values('name') ==>cerberus
gremlin> // where do pluto's brothers live? gremlin> g.V(pluto).out('brother').out('lives').values('name') ==>sky ==>sea gremlin> // which brother lives in which place? gremlin> g.V(pluto).out('brother').as('god').out('lives').as('place').select('god', 'place') ==>[god:v[1024], place:v[512]] ==>[god:v[1280], place:v[768]] gremlin> // what is the name of the brother and the name of the place? gremlin> g.V(pluto).out('brother').as('god').out('lives').as('place').select('god', 'place').by('name') ==>[god:jupiter, place:sky] ==>[god:neptune, place:sea]
普鲁托不畏惧死亡, 所以他住在冥界. 相反, 他的兄弟们选择住在充满爱的地方.
gremlin> g.V(pluto).outE('lives').values('reason') ==>no fear of death gremlin> g.E().has('reason', textContains('loves')) ==>e[6xs-sg-m51-e8][1024-lives->512] ==>e[70g-zk-m51-lc][1280-lives->768] gremlin> g.E().has('reason', textContains('loves')).as('source').values('reason').as('reason').select('source').outV().values('name').as('god').select('source').inV().values('name').as('thing').select('god', 'reason', 'thing') ==>[god:neptune, reason:loves waves, thing:sea] ==>[god:jupiter, reason:loves fresh breezes, thing:sky]