Version 1.0 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot.
For up-to-date documentation, see the latest version .
EdgeLabel API 1.4 EdgeLabel 假设已经创建好了1.2.3中的 PropertyKeys 和 1.3.3中的 VertexLabels
Params说明
name:顶点类型名称,必填 source_label: 源顶点类型的名称,必填 target_label: 目标顶点类型的名称,必填 frequency:两个点之间是否可以有多条边,可以取值SINGLE和MULTIPLE,非必填,默认值SINGLE properties: 边类型关联的属性类型,选填 sort_keys: 当允许关联多次时,指定区分键属性列表 nullable_keys:可为空的属性,选填,默认可为空 enable_label_index: 是否开启类型索引,默认关闭 1.4.1 创建一个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 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 } 从 hugegraph-server v0.11.2 版本开始支持边的 TTL 功能。边的 TTL 是通过 EdgeLabel 来设置的。比如希望 knows 类型的边存活时间为一天,需要在创建 knows EdgeLabel 的时候将 TTL 字段设置为 86400000,即单位为毫秒。
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 } 另外,当边中带有"创建时间"的属性且希望以"创建时间"属性作为计算边存活时间的起点时,可以设置 EdgeLabel 中的 ttl_start_time 字段。比如 knows EdgeLabel 有 createdTime 属性,且 createdTime 是 Date 类型的参数,希望 knows 类型的边从创建开始存活一天的时间,那么创建 knows EdgeLabel 的 Request Body 如下:
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 为已存在的EdgeLabel添加properties或userdata,或者移除userdata(目前不支持移除properties) Params action: 表示当前行为是添加还是移除,取值为append(添加)和eliminate(移除) 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 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 获取所有的EdgeLabel Method & Url
1 GET http://localhost:8080/graphs/hugegraph/schema/edgelabels Response Status 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 根据name获取EdgeLabel Method & Url
1 GET http://localhost:8080/graphs/hugegraph/schema/edgelabels/created Response Status 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 根据name删除EdgeLabel 删除 EdgeLabel 会导致删除对应的边以及相关的索引数据,会产生一个异步任务
Method & Url
1 DELETE http://localhost:8080/graphs/hugegraph/schema/edgelabels/created Response Status Response Body 注:
可以通过GET http://localhost:8080/graphs/hugegraph/tasks/1(其中"1"是task_id)来查询异步任务的执行状态,更多异步任务RESTful API