文档 1.7 版本已不再积极维护,你当前浏览的是一份归档快照。
最新文档请参阅 最新版本。
Gremlin API
8.1 Gremlin
8.1.1 向 HugeGraphServer 发送 gremlin 语句(GET),同步执行
Params
- gremlin: 要发送给
HugeGraphServer执行的gremlin语句 - bindings: 用来绑定参数,key 是字符串,value 是绑定的值(只能是字符串或者数字),功能类似于 MySQL 的 Prepared Statement,用于加速语句执行
- language: 发送语句的语言类型,默认为
gremlin-groovy - aliases: 为存在于图空间的已有变量添加别名
查询顶点
Method & Url
1GET http://127.0.0.1:8080/gremlin?gremlin=hugegraph.traversal().V('1:marko')
Response Status
Response Body
1{
2 "requestId": "c6ef47a8-b634-4b07-9d38-6b3b69a3a556",
3 "status": {
4 "message": "",
5 "code": 200,
6 "attributes": {}
7 },
8 "result": {
9 "data": [{
10 "id": "1:marko",
11 "label": "person",
12 "type": "vertex",
13 "properties": {
14 "city": [{
15 "id": "1:marko>city",
16 "value": "Beijing"
17 }],
18 "name": [{
19 "id": "1:marko>name",
20 "value": "marko"
21 }],
22 "age": [{
23 "id": "1:marko>age",
24 "value": 29
25 }]
26 }
27 }],
28 "meta": {}
29 }
30}
8.1.2 向 HugeGraphServer 发送 gremlin 语句(POST),同步执行
Method & Url
1POST http://localhost:8080/gremlin
查询顶点
Request Body
1{
2 "gremlin": "hugegraph.traversal().V('1:marko')",
3 "bindings": {},
4 "language": "gremlin-groovy",
5 "aliases": {}
6}
Response Status
Response Body
1{
2 "requestId": "c6ef47a8-b634-4b07-9d38-6b3b69a3a556",
3 "status": {
4 "message": "",
5 "code": 200,
6 "attributes": {}
7 },
8 "result": {
9 "data": [{
10 "id": "1:marko",
11 "label": "person",
12 "type": "vertex",
13 "properties": {
14 "city": [{
15 "id": "1:marko>city",
16 "value": "Beijing"
17 }],
18 "name": [{
19 "id": "1:marko>name",
20 "value": "marko"
21 }],
22 "age": [{
23 "id": "1:marko>age",
24 "value": 29
25 }]
26 }
27 }],
28 "meta": {}
29 }
30}
注意:
这里是直接使用图对象(hugegraph),先获取其遍历器(traversal()),再获取顶点。
不能直接写成graph.traversal().V()或g.V(),可以通过"aliases": {"graph": "hugegraph", "g": "__g_hugegraph"}
为图和遍历器添加别名后使用别名操作。其中,hugegraph是原生存在的变量,__g_hugegraph是HugeGraphServer额外添加的变量,
每个图都会存在一个对应的这样格式(_g${graph})的遍历器对象。
响应体的结构与其他 Vertex 或 Edge 的 RESTful API 的结构有区别,用户可能需要自行解析。
查询边
Request Body
1{
2 "gremlin": "g.E('S1:marko>2>>S2:lop')",
3 "bindings": {},
4 "language": "gremlin-groovy",
5 "aliases": {
6 "graph": "hugegraph",
7 "g": "__g_hugegraph"
8 }
9}
Response Status
Response Body
1{
2 "requestId": "3f117cd4-eedc-4e08-a106-ee01d7bb8249",
3 "status": {
4 "message": "",
5 "code": 200,
6 "attributes": {}
7 },
8 "result": {
9 "data": [{
10 "id": "S1:marko>2>>S2:lop",
11 "label": "created",
12 "type": "edge",
13 "inVLabel": "software",
14 "outVLabel": "person",
15 "inV": "2:lop",
16 "outV": "1:marko",
17 "properties": {
18 "weight": 0.4,
19 "date": "20171210"
20 }
21 }],
22 "meta": {}
23 }
24}
8.1.3 向 HugeGraphServer 发送 gremlin 语句(POST),异步执行
Method & Url
1POST http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/jobs/gremlin
查询顶点
Request Body
1{
2 "gremlin": "g.V('1:marko')",
3 "bindings": {},
4 "language": "gremlin-groovy",
5 "aliases": {}
6}
注意:
异步执行 Gremlin 语句暂不支持 aliases,可以使用 graph 代表要操作的图,也可以直接使用图的名字,例如 hugegraph;
另外g代表 traversal,等价于 graph.traversal() 或者 hugegraph.traversal()
Response Status
Response Body
注:
可以通过GET http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/tasks/1(其中"1"是 task_id)来查询异步任务的执行状态,更多异步任务 RESTful API
查询边
Request Body
1{
2 "gremlin": "g.E('S1:marko>2>>S2:lop')",
3 "bindings": {},
4 "language": "gremlin-groovy",
5 "aliases": {}
6}
Response Status
Response Body
注:
可以通过GET http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/tasks/2(其中"2"是 task_id)来查询异步任务的执行状态,更多异步任务 RESTful API