EdgeId是由 拼接而成,但是这里的顶点id类型不是通过引号区分的,而是根据前缀区分:

    • 当 id 类型为 number 时,EdgeId 的顶点 id 前有一个前缀L ,形如 “L123456>1>>L987654”
    • 当 id 类型为 string 时,EdgeId 的顶点 id 前有一个前缀S ,形如 “S1:peter>1>>S2:lop”

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

    2.2.1 创建一条边

    Method & Url
    Request Body
    1. {
    2. "label": "created",
    3. "outV": "1:peter",
    4. "inV": "2:lop",
    5. "outVLabel": "person",
    6. "inVLabel": "software",
    7. "properties": {
    8. "date": "2017-5-18",
    9. "weight": 0.2
    10. }
    11. }
    Response Status
    1. 201
    Response Body
    1. {
    2. "id": "S1:peter>1>>S2:lop",
    3. "label": "created",
    4. "type": "edge",
    5. "inVLabel": "software",
    6. "outVLabel": "person",
    7. "inV": "2:lop",
    8. "outV": "1:peter",
    9. "properties": {
    10. "date": "2017-5-18",
    11. "weight": 0.2
    12. }
    13. }

    2.2.2 创建多条边

    Params
    • check_vertex: 是否检查顶点存在(true | false),当设置为 true 而待插入边的源顶点或目标顶点不存在时会报错。
    Method & Url
    1. POST http://localhost:8080/graphs/hugegraph/graph/edges/batch
    Request Body
    1. [
    2. {
    3. "label": "created",
    4. "outV": "1:peter",
    5. "inV": "2:lop",
    6. "outVLabel": "person",
    7. "inVLabel": "software",
    8. "properties": {
    9. "date": "2017-5-18",
    10. "weight": 0.2
    11. }
    12. },
    13. {
    14. "label": "knows",
    15. "outV": "1:marko",
    16. "inV": "1:vadas",
    17. "outVLabel": "person",
    18. "inVLabel": "person",
    19. "properties": {
    20. "date": "2016-01-10",
    21. "weight": 0.5
    22. }
    23. }
    24. ]
    Response Status
    1. 201
    Response Body
    1. [
    2. "S1:marko>2>>S1:vadas"
    3. ]

    2.2.3 更新边属性

    Method & Url
    1. PUT http://localhost:8080/graphs/hugegraph/graph/edges/S1:peter>1>>S2:lop?action=append
    Request Body
    1. {
    2. "properties": {
    3. "weight": 1.0
    4. }
    5. }
    Response Status
    Response Body
    1. {
    2. "id": "S1:peter>1>>S2:lop",
    3. "label": "created",
    4. "type": "edge",
    5. "inVLabel": "software",
    6. "outVLabel": "person",
    7. "inV": "2:lop",
    8. "outV": "1:peter",
    9. "properties": {
    10. "date": "2017-5-18",
    11. "weight": 1
    12. }
    13. }

    2.2.4 删除边属性

    Method & Url
    1. PUT http://localhost:8080/graphs/hugegraph/graph/edges/S1:peter>1>>S2:lop?action=eliminate
    Request Body
    1. "properties": {
    2. "weight": 1.0
    3. }
    4. }

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

    Response Status
    1. 200
    Response Body
    1. {
    2. "id": "S1:peter>1>>S2:lop",
    3. "label": "created",
    4. "type": "edge",
    5. "inVLabel": "software",
    6. "outVLabel": "person",
    7. "inV": "2:lop",
    8. "outV": "1:peter",
    9. "properties": {
    10. "date": "20170324"
    11. }
    12. }

    2.2.5 获取符合条件的边

    Params
    • vertex_id: 顶点id
    • direction: 边的方向(OUT | IN | BOTH)
    • label: 边的标签
    • properties: 属性键值对(根据属性查询的前提是建立了索引)
    • offset:偏移,默认为0
    • limit: 查询数目,默认为100
    • page: 页号

    支持的查询有以下几种:

    • 提供vertex_id参数时,不可以使用参数page,direction、label、properties可选,offset和limit可以限制结果范围
    • 不提供vertex_id参数时,label和properties可选
      • 如果使用page参数,则:offset参数不可用(不填或者为0),direction不可用,properties最多只能有一个
      • 如果不使用page参数,则:offset和limit可以用来限制结果范围,direction参数忽略
    Method & Url
    1. GET http://127.0.0.1:8080/graphs/hugegraph/graph/edges?vertex_id="1:josh"&direction=BOTH&label=created&properties={}
    Response Status
    1. 200
    Response Body
    1. {
    2. "edges": [
    3. {
    4. "id": "S1:josh>1>>S2:lop",
    5. "label": "created",
    6. "type": "edge",
    7. "inVLabel": "software",
    8. "outVLabel": "person",
    9. "inV": "2:lop",
    10. "outV": "1:josh",
    11. "properties": {
    12. "date": "20091111",
    13. "weight": 0.4
    14. }
    15. },
    16. {
    17. "id": "S1:josh>1>>S2:ripple",
    18. "label": "created",
    19. "type": "edge",
    20. "inVLabel": "software",
    21. "outVLabel": "person",
    22. "inV": "2:ripple",
    23. "outV": "1:josh",
    24. "properties": {
    25. "date": "20171210",
    26. "weight": 1
    27. }
    28. }
    29. ]
    30. }

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

    Method & Url
    1. GET http://127.0.0.1:8080/graphs/hugegraph/graph/edges?page&limit=3
    Response Status
    Response Body
    1. {
    2. "edges": [{
    3. "id": "S1:peter>2>>S2:lop",
    4. "label": "created",
    5. "type": "edge",
    6. "inVLabel": "software",
    7. "outVLabel": "person",
    8. "inV": "2:lop",
    9. "outV": "1:peter",
    10. "properties": {
    11. "date": "20170324"
    12. }
    13. },
    14. {
    15. "id": "S1:josh>2>>S2:lop",
    16. "label": "created",
    17. "type": "edge",
    18. "inVLabel": "software",
    19. "outVLabel": "person",
    20. "inV": "2:lop",
    21. "outV": "1:josh",
    22. "properties": {
    23. "weight": 0.4,
    24. "date": "20091111"
    25. }
    26. },
    27. "id": "S1:josh>2>>S2:ripple",
    28. "label": "created",
    29. "type": "edge",
    30. "inVLabel": "software",
    31. "outVLabel": "person",
    32. "inV": "2:ripple",
    33. "outV": "1:josh",
    34. "properties": {
    35. "weight": 1,
    36. "date": "20171210"
    37. }
    38. }
    39. ],
    40. "page": "002500100753313a6a6f73681210010004000000020953323a726970706c65f07ffffffcf07ffffffd8460d63f4b398dd2721ed4fdb7716b420004"
    41. }

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

    Method & Url
    1. GET http://127.0.0.1:8080/graphs/hugegraph/graph/edges?page=002500100753313a6a6f73681210010004000000020953323a726970706c65f07ffffffcf07ffffffd8460d63f4b398dd2721ed4fdb7716b420004&limit=3
    Response Status
    1. 200
    Response Body
    1. {
    2. "edges": [{
    3. "id": "S1:marko>1>20130220>S1:josh",
    4. "label": "knows",
    5. "type": "edge",
    6. "inVLabel": "person",
    7. "outVLabel": "person",
    8. "inV": "1:josh",
    9. "outV": "1:marko",
    10. "properties": {
    11. "weight": 1,
    12. "date": "20130220"
    13. }
    14. },
    15. {
    16. "id": "S1:marko>1>20160110>S1:vadas",
    17. "label": "knows",
    18. "type": "edge",
    19. "inVLabel": "person",
    20. "outVLabel": "person",
    21. "inV": "1:vadas",
    22. "outV": "1:marko",
    23. "properties": {
    24. "weight": 0.5,
    25. "date": "20160110"
    26. }
    27. },
    28. {
    29. "id": "S1:marko>2>>S2:lop",
    30. "label": "created",
    31. "type": "edge",
    32. "inVLabel": "software",
    33. "outVLabel": "person",
    34. "inV": "2:lop",
    35. "outV": "1:marko",
    36. "properties": {
    37. "weight": 0.4,
    38. "date": "20171210"
    39. }
    40. }
    41. ],
    42. "page": null
    43. }

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

    2.2.6 根据Id获取边

    Method & Url
    1. GET http://localhost:8080/graphs/hugegraph/graph/edges/S1:peter>1>>S2:lop
    Response Status
    1. 200
    Response Body
    1. {
    2. "id": "S1:peter>1>>S2:lop",
    3. "label": "created",
    4. "type": "edge",
    5. "inVLabel": "software",
    6. "outVLabel": "person",
    7. "inV": "2:lop",
    8. "outV": "1:peter",
    9. "properties": {
    10. "date": "2017-5-18",
    11. "weight": 0.2
    12. }
    13. }

    2.2.7 根据Id删除边

    Method & Url
    Response Status
    1. 204