跳转到主要内容

IndexLabel API

IndexLabel(索引标签)REST 接口:为顶点和边的属性创建索引,加速基于属性的查询和过滤操作。

1.5 IndexLabel

假设已经创建好了 1.1.3 中的 PropertyKeys、1.2.3 中的 VertexLabels 以及 1.3.3 中的 EdgeLabels

1.5.1 创建一个 IndexLabel

Method & Url
1POST http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/schema/indexlabels
Request Body
1{
2    "name": "personByCity",
3    "base_type": "VERTEX_LABEL",
4    "base_value": "person",
5    "index_type": "SECONDARY",
6    "fields": [
7        "city"
8    ]
9}
Response Status
1202
Response Body
 1{
 2    "index_label": {
 3        "id": 1,
 4        "base_type": "VERTEX_LABEL",
 5        "base_value": "person",
 6        "name": "personByCity",
 7        "fields": [
 8            "city"
 9        ],
10        "index_type": "SECONDARY"
11    },
12    "task_id": 2
13}

1.5.2 获取所有的 IndexLabel

Method & Url
1GET http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/schema/indexlabels
Response Status
1200
Response Body
 1{
 2    "indexlabels": [
 3        {
 4            "id": 3,
 5            "base_type": "VERTEX_LABEL",
 6            "base_value": "software",
 7            "name": "softwareByPrice",
 8            "fields": [
 9                "price"
10            ],
11            "index_type": "RANGE"
12        },
13        {
14            "id": 4,
15            "base_type": "EDGE_LABEL",
16            "base_value": "created",
17            "name": "createdByDate",
18            "fields": [
19                "date"
20            ],
21            "index_type": "SECONDARY"
22        },
23        {
24            "id": 1,
25            "base_type": "VERTEX_LABEL",
26            "base_value": "person",
27            "name": "personByCity",
28            "fields": [
29                "city"
30            ],
31            "index_type": "SECONDARY"
32        },
33        {
34            "id": 3,
35            "base_type": "VERTEX_LABEL",
36            "base_value": "person",
37            "name": "personByAgeAndCity",
38            "fields": [
39                "age",
40                "city"
41            ],
42            "index_type": "SECONDARY"
43        }
44    ]
45}

1.5.3 根据 name 获取 IndexLabel

Method & Url
1GET http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/schema/indexlabels/personByCity
Response Status
1200
Response Body
 1{
 2    "id": 1,
 3    "base_type": "VERTEX_LABEL",
 4    "base_value": "person",
 5    "name": "personByCity",
 6    "fields": [
 7        "city"
 8    ],
 9    "index_type": "SECONDARY"
10}

1.5.4 根据 name 删除 IndexLabel

删除 IndexLabel 会导致删除相关的索引数据,会产生一个异步任务

Method & Url
1DELETE http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/schema/indexlabels/personByCity
Response Status
1202
Response Body
1{
2    "task_id": 1
3}

注:

可以通过GET http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/tasks/1(其中"1"是 task_id)来查询异步任务的执行状态,更多异步任务 RESTful API

1.5.5 为已存在的 IndexLabel 添加或移除 userdata

该方式只能修改 user_data,请求体中不能带 base_type、base_value 和 index_type。

Params
  • action: 表示当前行为是添加还是移除,取值为 append(添加)和 eliminate(移除)
Method & Url
1PUT http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/schema/indexlabels/personByCity?action=append
Request Body
1{
2    "name": "personByCity",
3    "user_data": {
4        "comment": "index on city"
5    }
6}
Response Status
1200
Response Body
 1{
 2    "id": 1,
 3    "base_type": "VERTEX_LABEL",
 4    "base_value": "person",
 5    "name": "personByCity",
 6    "fields": [
 7        "city"
 8    ],
 9    "index_type": "SECONDARY",
10    "user_data": {
11        "comment": "index on city",
12        "~create_time": "2022-05-13 13:47:23.745"
13    }
14}