EdgeLabel API

1.4 EdgeLabel

Assuming PropertyKeys from version 1.2.3 and VertexLabels from version 1.3.3 have already been created.

Params Explanation

  • name: Name of the vertex type, required.
  • source_label: Name of the source vertex type, required.
  • target_label: Name of the target vertex type, required.
  • frequency: Whether there can be multiple edges between two points, can have values SINGLE or MULTIPLE, optional (default value: SINGLE).
  • properties: Property types associated with the edge type, optional.
  • sort_keys: Specifies a list of differentiating key properties when multiple associations are allowed.
  • nullable_keys: Nullable properties, optional (default: nullable).
  • enable_label_index: Whether to enable type indexing, disabled by default.

1.4.1 Create an EdgeLabel

Method & Url
  1. POST http://localhost:8080/graphs/hugegraph/schema/edgelabels
Request Body
  1. {
  2. "name": "created",
  3. "source_label": "person",
  4. "target_label": "software",
  5. "frequency": "SINGLE",
  6. "properties": [
  7. "date"
  8. ],
  9. "sort_keys": [],
  10. "nullable_keys": [],
  11. "enable_label_index": true
  12. }
Response Status
  1. 201
Response Body
  1. {
  2. "id": 1,
  3. "sort_keys": [
  4. ],
  5. "source_label": "person",
  6. "name": "created",
  7. "index_names": [
  8. ],
  9. "properties": [
  10. "date"
  11. ],
  12. "target_label": "software",
  13. "frequency": "SINGLE",
  14. "nullable_keys": [
  15. ],
  16. "enable_label_index": true,
  17. "user_data": {}
  18. }

Starting from version 0.11.2 of hugegraph-server, the TTL (Time to Live) feature for edges is supported. The TTL for edges is set through EdgeLabel. For example, if you want the “knows” type of edge to have a lifespan of one day, you need to set the TTL field to 86400000 when creating the “knows” EdgeLabel, where the unit is milliseconds.

  1. {
  2. "id": 1,
  3. "sort_keys": [
  4. ],
  5. "source_label": "person",
  6. "name": "knows",
  7. "index_names": [
  8. ],
  9. "properties": [
  10. "date",
  11. "createdTime"
  12. ],
  13. "target_label": "person",
  14. "frequency": "SINGLE",
  15. "nullable_keys": [
  16. ],
  17. "enable_label_index": true,
  18. "ttl": 86400000,
  19. "user_data": {}
  20. }

Additionally, when the edge has a property called “createdTime” and you want to use the “createdTime” property as the starting point for calculating the edge’s lifespan, you can set the ttl_start_time field in the EdgeLabel. For example, if the knows EdgeLabel has a property called “createdTime” which is of type Date, and you want the “knows” type of edge to live for one day from the time of creation, the Request Body for creating the knows EdgeLabel would be as follows:

  1. {
  2. "id": 1,
  3. "sort_keys": [
  4. ],
  5. "source_label": "person",
  6. "name": "knows",
  7. "index_names": [
  8. ],
  9. "properties": [
  10. "date",
  11. "createdTime"
  12. ],
  13. "target_label": "person",
  14. "frequency": "SINGLE",
  15. "nullable_keys": [
  16. ],
  17. "enable_label_index": true,
  18. "ttl": 86400000,
  19. "ttl_start_time": "createdTime",
  20. "user_data": {}
  21. }

1.4.2 Add properties or userdata to an existing EdgeLabel, or remove userdata (removing properties is currently not supported)

Params
  • action: Indicates whether the current action is to add or remove, with values append (add) and eliminate (remove).
Method & Url
  1. PUT http://localhost:8080/graphs/hugegraph/schema/edgelabels/created?action=append
Request Body
  1. {
  2. "name": "created",
  3. "properties": [
  4. "weight"
  5. ],
  6. "nullable_keys": [
  7. "weight"
  8. ]
  9. }
Response Status
  1. 200
Response Body
  1. {
  2. "id": 2,
  3. "sort_keys": [
  4. ],
  5. "source_label": "person",
  6. "name": "created",
  7. "index_names": [
  8. ],
  9. "properties": [
  10. "date",
  11. "weight"
  12. ],
  13. "target_label": "software",
  14. "frequency": "SINGLE",
  15. "nullable_keys": [
  16. "weight"
  17. ],
  18. "enable_label_index": true,
  19. "user_data": {}
  20. }

1.4.3 Get all EdgeLabels

Method & Url
  1. GET http://localhost:8080/graphs/hugegraph/schema/edgelabels
Response Status
  1. 200
Response Body
  1. {
  2. "edgelabels": [
  3. {
  4. "id": 1,
  5. "sort_keys": [
  6. ],
  7. "source_label": "person",
  8. "name": "created",
  9. "index_names": [
  10. ],
  11. "properties": [
  12. "date",
  13. "weight"
  14. ],
  15. "target_label": "software",
  16. "frequency": "SINGLE",
  17. "nullable_keys": [
  18. "weight"
  19. ],
  20. "enable_label_index": true,
  21. "user_data": {}
  22. },
  23. {
  24. "id": 2,
  25. "sort_keys": [
  26. ],
  27. "source_label": "person",
  28. "name": "knows",
  29. "index_names": [
  30. ],
  31. "properties": [
  32. "date",
  33. "weight"
  34. ],
  35. "target_label": "person",
  36. "frequency": "SINGLE",
  37. "nullable_keys": [
  38. ],
  39. "enable_label_index": false,
  40. "user_data": {}
  41. }
  42. ]
  43. }

1.4.4 Get EdgeLabel by name

Method & Url
  1. GET http://localhost:8080/graphs/hugegraph/schema/edgelabels/created
Response Status
  1. 200
Response Body
  1. {
  2. "id": 1,
  3. "sort_keys": [
  4. ],
  5. "source_label": "person",
  6. "name": "created",
  7. "index_names": [
  8. ],
  9. "properties": [
  10. "date",
  11. "city",
  12. "weight"
  13. ],
  14. "target_label": "software",
  15. "frequency": "SINGLE",
  16. "nullable_keys": [
  17. "city",
  18. "weight"
  19. ],
  20. "enable_label_index": true,
  21. "user_data": {}
  22. }

1.4.5 Delete EdgeLabel by name

Deleting an EdgeLabel will result in the deletion of corresponding edges and related index data. This operation will generate an asynchronous task.

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

Note:

You can query the execution status of an asynchronous task by using GET http://localhost:8080/graphs/hugegraph/tasks/1 (where “1” is the task_id). For more information, refer to the Asynchronous Task RESTful API.

Last modified May 19, 2023: Update edgelabel.md (#242) (537ccf5d)