diff --git a/clients/restful-api/edge.md b/clients/restful-api/edge.md index 0c0455bf5..6ee7ed5ff 100644 --- a/clients/restful-api/edge.md +++ b/clients/restful-api/edge.md @@ -160,7 +160,134 @@ PUT http://localhost:8080/graphs/hugegraph/graph/edges/S1:peter>1>>S2:lop?action } ``` -#### 2.2.4 删除边属性 +#### 2.2.4 批量更新边属性 + +##### 功能说明 + +与批量更新顶点属性类似 + +假设原边及属性为: + +```json +{ + "edges":[ + { + "id":"S1:josh>2>>S2:ripple", + "label":"created", + "type":"edge", + "outV":"1:josh", + "outVLabel":"person", + "inV":"2:ripple", + "inVLabel":"software", + "properties":{ + "weight":1, + "date":1512835200000 + } + }, + { + "id":"S1:marko>1>7JooBil0>S1:josh", + "label":"knows", + "type":"edge", + "outV":"1:marko", + "outVLabel":"person", + "inV":"1:josh", + "inVLabel":"person", + "properties":{ + "weight":1, + "date":1361289600000 + } + } + ] +} +``` + +##### Method & Url + +``` +PUT http://127.0.0.1:8080/graphs/hugegraph/graph/edges/batch +``` + +##### Request Body + +```json +{ + "edges":[ + { + "id":"S1:josh>2>>S2:ripple", + "label":"created", + "outV":"1:josh", + "outVLabel":"person", + "inV":"2:ripple", + "inVLabel":"software", + "properties":{ + "weight":0.1, + "date":1522835200000 + } + }, + { + "id":"S1:marko>1>7JooBil0>S1:josh", + "label":"knows", + "outV":"1:marko", + "outVLabel":"person", + "inV":"1:josh", + "inVLabel":"person", + "properties":{ + "weight":0.2, + "date":1301289600000 + } + } + ], + "update_strategies":{ + "weight":"SUM", + "date":"BIGGER" + }, + "check_vertex": false, + "create_if_not_exist":true +} +``` + +##### Response Status + +```json +200 +``` + +##### Response Body + +```json +{ + "edges":[ + { + "id":"S1:josh>2>>S2:ripple", + "label":"created", + "type":"edge", + "outV":"1:josh", + "outVLabel":"person", + "inV":"2:ripple", + "inVLabel":"software", + "properties":{ + "weight":1.1, + "date":1522835200000 + } + }, + { + "id":"S1:marko>1>7JooBil0>S1:josh", + "label":"knows", + "type":"edge", + "outV":"1:marko", + "outVLabel":"person", + "inV":"1:josh", + "inVLabel":"person", + "properties":{ + "weight":1.2, + "date":1301289600000 + } + } + ] +} +``` + +#### 2.2.5 删除边属性 ##### Method & Url @@ -203,7 +330,7 @@ PUT http://localhost:8080/graphs/hugegraph/graph/edges/S1:peter>1>>S2:lop?action } ``` -#### 2.2.5 获取符合条件的边 +#### 2.2.6 获取符合条件的边 ##### Params @@ -401,7 +528,7 @@ GET http://127.0.0.1:8080/graphs/hugegraph/graph/edges?page=002500100753313a6a6f 此时`"page": null`表示已经没有下一页了。 -#### 2.2.6 根据Id获取边 +#### 2.2.7 根据Id获取边 ##### Method & Url @@ -433,7 +560,7 @@ GET http://localhost:8080/graphs/hugegraph/graph/edges/S1:peter>1>>S2:lop } ``` -#### 2.2.7 根据Id删除边 +#### 2.2.8 根据Id删除边 ##### Method & Url diff --git a/clients/restful-api/vertex.md b/clients/restful-api/vertex.md index da971a331..e7d2ad5da 100644 --- a/clients/restful-api/vertex.md +++ b/clients/restful-api/vertex.md @@ -171,7 +171,152 @@ PUT http://127.0.0.1:8080/graphs/hugegraph/graph/vertices/"1:marko"?action=appen } ``` -#### 2.1.4 删除顶点属性 +#### 2.1.4 批量更新顶点属性 + +##### 功能说明 + +批量更新顶点的属性,并支持多种更新策略,包括 + +- SUM: 数值累加 +- BIGGER: 两个数字/日期取更大的 +- SMALLER: 两个数字/日期取更小的 +- UNION: Set属性取并集 +- INTERSECTION: Set属性取交集 +- APPEND: List属性追加元素 +- ELIMINATE: List/Set属性删除元素 +- OVERRIDE: 覆盖已有属性,如果新属性为null,则仍然使用旧属性 + +假设原顶点及属性为: + +```json +{ + "vertices":[ + { + "id":"2:lop", + "label":"software", + "type":"vertex", + "properties":{ + "name":"lop", + "lang":"java", + "price":328 + } + }, + { + "id":"1:josh", + "label":"person", + "type":"vertex", + "properties":{ + "name":"josh", + "age":32, + "city":"Beijing", + "weight":0.1, + "hobby":[ + "reading", + "football" + ] + } + } + ] +} +``` + +##### Method & Url + +``` +PUT http://127.0.0.1:8080/graphs/hugegraph/graph/vertices/batch +``` + +##### Request Body + +```json +{ + "vertices":[ + { + "label":"software", + "type":"vertex", + "properties":{ + "name":"lop", + "lang":"c++", + "price":299 + } + }, + { + "label":"person", + "type":"vertex", + "properties":{ + "name":"josh", + "city":"Shanghai", + "weight":0.2, + "hobby":[ + "swiming" + ] + } + } + ], + "update_strategies":{ + "price":"BIGGER", + "age":"OVERRIDE", + "city":"OVERRIDE", + "weight":"SUM", + "hobby":"UNION" + }, + "create_if_not_exist":true +} +``` + +##### Response Status + +```json +200 +``` + +##### Response Body + +```json +{ + "vertices": [ + { + "id": "2:lop", + "label": "software", + "type": "vertex", + "properties": { + "name": "lop", + "lang": "c++", + "price": 328 + } + }, + { + "id": "1:josh", + "label": "person", + "type": "vertex", + "properties": { + "name": "josh", + "age": 32, + "city": "Shanghai", + "weight": 0.3, + "hobby": [ + "swiming", + "reading", + "football" + ] + } + } + ] +} +``` + +结果分析: + +- lang 属性未指定更新策略,直接用新值覆盖旧值,无论新值是否为null; +- price 属性指定 BIGGER 的更新策略,旧属性值为328,新属性值为299,所以仍然保留了旧属性值328; +- age 属性指定 OVERRIDE 更新策略,而新属性值中未传入age,相当于age为null,所以仍然保留了原属性值32; +- city 属性也指定了 OVERRIDE 更新策略,且新属性值不为null,所以覆盖了旧值; +- weight 属性指定了 SUM 更新策略,旧属性值为0.1,新属性值为0.2,最后的值为0.3; +- hobby 属性(基数为Set)指定了 UNION 更新策略,所以新值与旧值取了并集; + +其他的更新策略使用方式可以类推,不再赘述。 + +#### 2.1.5 删除顶点属性 ##### Method & Url @@ -222,7 +367,7 @@ PUT http://127.0.0.1:8080/graphs/hugegraph/graph/vertices/"1:marko"?action=elimi } ``` -#### 2.1.5 获取符合条件的顶点 +#### 2.1.6 获取符合条件的顶点 ##### Params @@ -446,7 +591,7 @@ GET http://localhost:8080/graphs/hugegraph/graph/vertices?page=001000100853313a7 此时`"page": null`表示已经没有下一页了。 -#### 2.1.6 根据Id获取顶点 +#### 2.1.7 根据Id获取顶点 ##### Method & Url @@ -484,7 +629,7 @@ GET http://localhost:8080/graphs/hugegraph/graph/vertices/"1:marko" } ``` -#### 2.1.7 根据Id删除顶点 +#### 2.1.8 根据Id删除顶点 ##### Method & Url @@ -496,4 +641,4 @@ DELETE http://localhost:8080/graphs/hugegraph/graph/vertices/"1:marko" ```json 204 -``` \ No newline at end of file +```