Index操作
更新时间:2021-01-13
创建Index
通过以下代码,为指定的日志集创建索引。
indexMappings := map[string]api.LogField{
"age": {
Type: "long",
},
"salary": {
Type: "text",
},
"name": {
Type: "text",
},
}
err := blsClient.CreateIndex("demo", true, indexMappings) // true表示索引开启状态
if err != nil {
fmt.Println("Create index failed: ", err)
} else {
fmt.Println("Create index success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档CreateIndex
更新指定Index
通过以下代码,更新指定日志集的索引结构。
indexMappings := map[string]api.LogField{
"age": {
Type: "long",
},
"wage": {
Type: "float",
},
"name": {
Type: "text",
},
}
err := blsClient.UdpateIndex("demo", true, indexMappings)
if err != nil {
fmt.Println("Update index failed: ", err)
} else {
fmt.Println("Update index success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档UpdateIndex
获取指定Index
通过以下代码,获取指定日志集的索引结构。
res, err := blsClient.DescribeIndex("demo")
if err != nil {
fmt.Println("Get index failed: ", err)
} else {
fmt.Println("Index info: ", res)
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档DescribeIndex
删除指定Index
通过以下代码,删除指定日志集的索引,该操作会将索引数据清空。
res, err := blsClient.DeleteIndex("demo")
if err != nil {
fmt.Println("Delete index failed: ", err)
} else {
fmt.Println("Delete index success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档DeleteIndex