7.1 Gremlin

7.1.1 向HugeGraphServer发送gremlin语句(GET),同步执行

Params
  • gremlin: 要发送给HugeGraphServer执行的gremlin语句
  • bindings: 可以给gremlin语句中的变量绑定值
  • language: 发送语句的语言类型,默认为gremlin-groovy
  • aliases: 为存在于图空间的已有变量添加别名

查询顶点

Method & Url
  1. GET http://127.0.0.1:8080/gremlin?gremlin=hugegraph.traversal().V('1:marko')
Response Status
  1. 200
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. }

7.1.2 向HugeGraphServer发送gremlin语句(POST),同步执行

Method & Url
  1. POST 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
  1. 200
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_hugegraphHugeGraphServer额外添加的变量, 每个图都会存在一个对应的这样格式(_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
  1. 200
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. }

7.1.3 向HugeGraphServer发送gremlin语句(POST),异步执行

Method & Url
  1. POST http://localhost:8080/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
  1. 201
Response Body
  1. {
  2. "task_id": 1
  3. }

注:

可以通过GET http://localhost:8080/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
  1. 200
Response Body
  1. {
  2. "task_id": 2
  3. }

注:

可以通过GET http://localhost:8080/graphs/hugegraph/tasks/2(其中”2”是task_id)来查询异步任务的执行状态,更多异步任务RESTful API