顶点的GET/PUT/DELETE API中url的 id 部分传入的应是带有类型信息的id值,这个类型信息用 json 串是否带引号表示,也就是说:

    • 当 id 类型为 number 时,url 中的 id 不带引号,形如 xxx/vertices/123456
    • 当 id 类型为 string 时,url 中的 id 带引号,形如 xxx/vertices/“123456”

    接下来的示例均假设已经创建好了前述的各种schema信息

    2.1.1 创建一个顶点

    Method & Url
    Request Body
    1. "label": "person",
    2. "properties": {
    3. "name": "marko",
    4. "age": 29
    5. }
    6. }
    Response Status
    1. 201
    Response Body
    1. {
    2. "id": "1:marko",
    3. "label": "person",
    4. "type": "vertex",
    5. "properties": {
    6. "name": [
    7. {
    8. "id": "1:marko>name",
    9. "value": "marko"
    10. }
    11. ],
    12. "age": [
    13. {
    14. "id": "1:marko>age",
    15. "value": 29
    16. }
    17. ]
    18. }
    19. }

    2.1.2 创建多个顶点

    Method & Url
    1. POST http://localhost:8080/graphs/hugegraph/graph/vertices/batch
    Request Body
    1. [
    2. {
    3. "label": "person",
    4. "properties": {
    5. "name": "marko",
    6. "age": 29
    7. }
    8. },
    9. {
    10. "label": "software",
    11. "properties": {
    12. "name": "ripple",
    13. "lang": "java",
    14. "price": 199
    15. }
    16. }
    17. ]
    Response Status
    1. 201
    Response Body
    1. [
    2. "1:marko",
    3. "2:ripple"
    4. ]

    2.1.3 更新顶点属性

    Method & Url
    1. PUT http://127.0.0.1:8080/graphs/hugegraph/graph/vertices/"1:marko"?action=append
    Request Body
    1. {
    2. "label": "person",
    3. "properties": {
    4. "age": 30,
    5. "city": "Beijing"
    6. }
    7. }
    Response Status
    Response Body
    1. {
    2. "id": "1:marko",
    3. "label": "person",
    4. "type": "vertex",
    5. "properties": {
    6. "city": [
    7. {
    8. "id": "1:marko>city",
    9. "value": "Beijing"
    10. }
    11. ],
    12. "name": [
    13. "id": "1:marko>name",
    14. "value": "marko"
    15. }
    16. ],
    17. "age": [
    18. {
    19. "id": "1:marko>age",
    20. "value": 30
    21. }
    22. ]
    23. }
    24. }

    2.1.4 删除顶点属性

    Method & Url
    1. PUT http://127.0.0.1:8080/graphs/hugegraph/graph/vertices/"1:marko"?action=eliminate
    Request Body
    1. {
    2. "label": "person",
    3. "properties": {
    4. "city": "Beijing"
    5. }
    6. }

    注意:这里会直接删除属性(删除key和所有value),无论其属性的取值是single、set或list。

    Response Status
    1. 200
    Response Body
    1. {
    2. "id": "1:marko",
    3. "label": "person",
    4. "type": "vertex",
    5. "properties": {
    6. "name": [
    7. "id": "1:marko>name",
    8. "value": "marko"
    9. }
    10. ],
    11. "age": [
    12. {
    13. "id": "1:marko>age",
    14. "value": 30
    15. }
    16. ]
    17. }
    18. }

    2.1.5 获取符合条件的顶点

    Params
    • label: 顶点类型
    • properties: 属性键值对(根据属性查询的前提是建立了索引)
    • limit: 查询最大数目
    • page: 页号

    以上参数都是可选的,如果提供page参数,必须提供limit参数,不允许带其他参数。label, propertieslimit可以任意组合。

    Method & Url
    1. GET http://localhost:8080/graphs/hugegraph/graph/vertices?label=person&properties={"age":29}&limit=1
    Response Status
    1. 200
    Response Body
    1. {
    2. "vertices": [
    3. {
    4. "id": "1:marko",
    5. "label": "person",
    6. "type": "vertex",
    7. "properties": {
    8. "city": [
    9. {
    10. "id": "1:marko>city",
    11. "value": "Beijing"
    12. }
    13. ],
    14. "name": [
    15. {
    16. "id": "1:marko>name",
    17. "value": "marko"
    18. }
    19. ],
    20. "age": [
    21. {
    22. "id": "1:marko>age",
    23. "value": 29
    24. }
    25. ]
    26. }
    27. }
    28. ]
    29. }

    分页查询所有顶点,获取第一页(page不带参数值),限定3条

    Method & Url
    1. GET http://localhost:8080/graphs/hugegraph/graph/vertices?page&limit=3
    Response Status
    Response Body
    1. {
    2. "vertices": [{
    3. "id": "2:ripple",
    4. "label": "software",
    5. "type": "vertex",
    6. "properties": {
    7. "price": [{
    8. "id": "2:ripple>price",
    9. "value": 199
    10. }],
    11. "name": [{
    12. "id": "2:ripple>name",
    13. "value": "ripple"
    14. }],
    15. "lang": [{
    16. "id": "2:ripple>lang",
    17. "value": "java"
    18. }]
    19. }
    20. },
    21. {
    22. "id": "1:vadas",
    23. "label": "person",
    24. "type": "vertex",
    25. "properties": {
    26. "city": [{
    27. "id": "1:vadas>city",
    28. "value": "Hongkong"
    29. }],
    30. "name": [{
    31. "id": "1:vadas>name",
    32. "value": "vadas"
    33. }],
    34. "age": [{
    35. "id": "1:vadas>age",
    36. }]
    37. }
    38. },
    39. {
    40. "id": "1:peter",
    41. "label": "person",
    42. "type": "vertex",
    43. "properties": {
    44. "city": [{
    45. "id": "1:peter>city",
    46. "value": "Shanghai"
    47. }],
    48. "name": [{
    49. "id": "1:peter>name",
    50. }],
    51. "age": [{
    52. "id": "1:peter>age",
    53. "value": 35
    54. }]
    55. }
    56. }
    57. ],
    58. "page": "001000100853313a706574657200f07ffffffc00e797c6349be736fffc8699e8a502efe10004"
    59. }

    返回的body里面是带有下一页的页号信息的,"page": "001000100853313a706574657200f07ffffffc00e797c6349be736fffc8699e8a502efe10004",在查询下一页的时候将该值赋给page参数。

    Method & Url
    1. GET http://localhost:8080/graphs/hugegraph/graph/vertices?page=001000100853313a706574657200f07ffffffc00e797c6349be736fffc8699e8a502efe10004&limit=3
    Response Status
    1. 200
    Response Body
    1. {
    2. "vertices": [{
    3. "id": "1:josh",
    4. "label": "person",
    5. "type": "vertex",
    6. "properties": {
    7. "city": [{
    8. "id": "1:josh>city",
    9. "value": "Beijing"
    10. }],
    11. "name": [{
    12. "id": "1:josh>name",
    13. "value": "josh"
    14. }],
    15. "age": [{
    16. "id": "1:josh>age",
    17. "value": 32
    18. }]
    19. }
    20. },
    21. {
    22. "id": "1:marko",
    23. "label": "person",
    24. "type": "vertex",
    25. "properties": {
    26. "city": [{
    27. "id": "1:marko>city",
    28. "value": "Beijing"
    29. }],
    30. "name": [{
    31. "id": "1:marko>name",
    32. "value": "marko"
    33. }],
    34. "age": [{
    35. "id": "1:marko>age",
    36. "value": 29
    37. }]
    38. }
    39. },
    40. {
    41. "id": "2:lop",
    42. "label": "software",
    43. "type": "vertex",
    44. "properties": {
    45. "price": [{
    46. "id": "2:lop>price",
    47. "value": 328
    48. }],
    49. "name": [{
    50. "id": "2:lop>name",
    51. "value": "lop"
    52. }],
    53. "lang": [{
    54. "id": "2:lop>lang",
    55. "value": "java"
    56. }]
    57. }
    58. }
    59. ],
    60. "page": null
    61. }

    此时"page": null表示已经没有下一页了。

    2.1.6 根据Id获取顶点

    Method & Url
    1. GET http://localhost:8080/graphs/hugegraph/graph/vertices/"1:marko"
    Response Status
    1. 200
    Response Body
    1. {
    2. "id": "1:marko",
    3. "label": "person",
    4. "type": "vertex",
    5. "properties": {
    6. "name": [
    7. {
    8. "id": "1:marko>name",
    9. "value": "marko"
    10. }
    11. ],
    12. "age": [
    13. {
    14. "id": "1:marko>age",
    15. "value": 29
    16. }
    17. ]
    18. }
    19. }

    2.1.7 根据Id删除顶点

    Method & Url
    Response Status