1.2 VertexLabel

假设已经创建好了1.1.3中列出来的 PropertyKeys

1.2.1 创建一个VertexLabel

Method & Url
  1. POST http://localhost:8080/graphs/hugegraph/schema/vertexlabels
Request Body
  1. {
  2. "name": "person",
  3. "id_strategy": "DEFAULT",
  4. "properties": [
  5. "name",
  6. "age"
  7. ],
  8. "primary_keys": [
  9. "name"
  10. ],
  11. "nullable_keys": [],
  12. "enable_label_index": true
  13. }
Response Status
  1. 201
Response Body
  1. {
  2. "id": 1,
  3. "primary_keys": [
  4. "name"
  5. ],
  6. "id_strategy": "PRIMARY_KEY",
  7. "name": "person2",
  8. "index_names": [
  9. ],
  10. "properties": [
  11. "name",
  12. "age"
  13. ],
  14. "nullable_keys": [
  15. ],
  16. "enable_label_index": true,
  17. "user_data": {}
  18. }

从 hugegraph-server v0.11.2 版本开始支持顶点的 TTL 功能。顶点的 TTL 是通过 VertexLabel 来设置的。比如希望 person 类型的顶点存活时间为一天,需要在创建 person VertexLabel 的时候将 TTL 字段设置为 86400000,即单位为毫秒。

  1. {
  2. "name": "person",
  3. "id_strategy": "DEFAULT",
  4. "properties": [
  5. "name",
  6. "age"
  7. ],
  8. "primary_keys": [
  9. "name"
  10. ],
  11. "nullable_keys": [],
  12. "ttl": 86400000,
  13. "enable_label_index": true
  14. }

另外,当顶点中带有”创建时间”的属性且希望以”创建时间”属性作为计算顶点存活时间的起点时,可以设置 VertexLabel 中的 ttl_start_time 字段。比如 person VertexLabel 有 createdTime 属性,且 createdTime 是 Date 类型的参数,希望 person 类型的顶点从创建开始存活一天的时间,那么创建 person VertexLabel 的 Request Body 如下:

  1. {
  2. "name": "person",
  3. "id_strategy": "DEFAULT",
  4. "properties": [
  5. "name",
  6. "age",
  7. "createdTime"
  8. ],
  9. "primary_keys": [
  10. "name"
  11. ],
  12. "nullable_keys": [],
  13. "ttl": 86400000,
  14. "ttl_start_time": "createdTime",
  15. "enable_label_index": true
  16. }

1.2.2 为已存在的VertexLabel添加properties或userdata,或者移除userdata(目前不支持移除properties)

Params
  • action: 表示当前行为是添加还是移除,取值为append(添加)和eliminate(移除)
Method & Url
  1. PUT http://localhost:8080/graphs/hugegraph/schema/vertexlabels/person?action=append
Request Body
  1. {
  2. "name": "person",
  3. "properties": [
  4. "city"
  5. ],
  6. "nullable_keys": ["city"],
  7. "user_data": {
  8. "super": "animal"
  9. }
  10. }
Response Status
  1. 200
Response Body
  1. {
  2. "id": 1,
  3. "primary_keys": [
  4. "name"
  5. ],
  6. "id_strategy": "PRIMARY_KEY",
  7. "name": "person",
  8. "index_names": [
  9. ],
  10. "properties": [
  11. "city",
  12. "name",
  13. "age"
  14. ],
  15. "nullable_keys": [
  16. "city"
  17. ],
  18. "enable_label_index": true,
  19. "user_data": {
  20. "super": "animal"
  21. }
  22. }

1.2.3 获取所有的VertexLabel

Method & Url
  1. GET http://localhost:8080/graphs/hugegraph/schema/vertexlabels
Response Status
  1. 200
Response Body
  1. {
  2. "vertexlabels": [
  3. {
  4. "id": 1,
  5. "primary_keys": [
  6. "name"
  7. ],
  8. "id_strategy": "PRIMARY_KEY",
  9. "name": "person",
  10. "index_names": [
  11. ],
  12. "properties": [
  13. "city",
  14. "name",
  15. "age"
  16. ],
  17. "nullable_keys": [
  18. "city"
  19. ],
  20. "enable_label_index": true,
  21. "user_data": {
  22. "super": "animal"
  23. }
  24. },
  25. {
  26. "id": 2,
  27. "primary_keys": [
  28. "name"
  29. ],
  30. "id_strategy": "PRIMARY_KEY",
  31. "name": "software",
  32. "index_names": [
  33. ],
  34. "properties": [
  35. "price",
  36. "name",
  37. "lang"
  38. ],
  39. "nullable_keys": [
  40. "price"
  41. ],
  42. "enable_label_index": false,
  43. "user_data": {}
  44. }
  45. ]
  46. }

1.2.4 根据name获取VertexLabel

Method & Url
  1. GET http://localhost:8080/graphs/hugegraph/schema/vertexlabels/person
Response Status
  1. 200
Response Body
  1. {
  2. "id": 1,
  3. "primary_keys": [
  4. "name"
  5. ],
  6. "id_strategy": "PRIMARY_KEY",
  7. "name": "person",
  8. "index_names": [
  9. ],
  10. "properties": [
  11. "city",
  12. "name",
  13. "age"
  14. ],
  15. "nullable_keys": [
  16. "city"
  17. ],
  18. "enable_label_index": true,
  19. "user_data": {
  20. "super": "animal"
  21. }
  22. }

1.2.5 根据name删除VertexLabel

删除 VertexLabel 会导致删除对应的顶点以及相关的索引数据,会产生一个异步任务

Method & Url
  1. DELETE http://localhost:8080/graphs/hugegraph/schema/vertexlabels/person
Response Status
  1. 202
Response Body
  1. {
  2. "task_id": 1
  3. }

注:

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