Index操作
更新时间:2024-09-11
创建Index
通过以下代码,为指定的日志集创建索引
createIndexRequest := CreateIndexRequest{
Project: "default",
LogStoreName: "test",
Fulltext: true,
Fields: map[string]api.LogField{
"test1": {
Type: "float",
},
},
}
err := BLS_CLIENT.CreateIndexV2(createIndexRequest)
if err != nil {
fmt.Println("Create index failed: ", err)
} else {
fmt.Println("Create index success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档CreateIndex
更新指定Index
通过以下代码,更新指定日志集的索引结构
updateIndexRequest := UpdateIndexRequest{
Project: "default",
LogStoreName: "test",
Fulltext: true,
Fields: map[string]api.LogField{
"test1": {
Type: "float",
},
"test2": {
Type: "bool",
},
},
}
err := BLS_CLIENT.UpdateIndexV2(updateIndexRequest)
if err != nil {
fmt.Println("Update index failed: ", err)
} else {
fmt.Println("Update index success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档UpdateIndex
获取指定Index
通过以下代码,获取指定日志集的索引结构。
describeIndexRequest := DescribeIndexRequest{
Project: "default",
LogStoreName: "test",
}
res, err := BLS_CLIENT.DescribeIndexV2(describeIndexRequest)
if err != nil {
fmt.Println("Get index failed: ", err)
} else {
fmt.Println("Index info: ", res)
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档DescribeIndex
删除指定Index
通过以下代码,删除指定日志集的索引,该操作会将索引数据清空
deleteIndexRequest := DeleteIndexRequest{
Project: "default",
LogStoreName: "test",
}
err := BLS_CLIENT.DeleteIndexV2(deleteIndexRequest)
if err != nil {
fmt.Println("Delete index failed: ", err)
} else {
fmt.Println("Delete index success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档DeleteIndex