You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dsMin/dsTools/Tools/EsCreateIndexByJson.go

41 lines
1.1 KiB

package main
import (
"dsTools/Utils/EsUtil"
"dsTools/Utils/FileUtil"
"fmt"
"io/ioutil"
"strings"
)
func main() {
//遍历目录下所有的文件
rd, _ := ioutil.ReadDir("MappingCreateJson/")
for _, fi := range rd {
if strings.Index(fi.Name(), ".json") > 0 {
indexName := strings.Replace(fi.Name(), ".json", "", -1)
//1、判断指定的index是否存在
found := EsUtil.IndexIsExists(indexName)
if found {
fmt.Println("索引" + indexName + "已存在,无法创建!")
continue
}
found = EsUtil.IndexIsExists("real_" + indexName)
if found {
fmt.Println("索引" + "real_" + indexName + "已存在,无法创建!")
continue
}
var jsonFile = "MappingCreateJson/" + indexName + ".json"
//3、创建索引
createMappingStr := FileUtil.ReadFileContent(jsonFile)
EsUtil.CreateIndex(indexName, createMappingStr)
//4、添加别名
EsUtil.AddAliase("real_"+indexName,indexName)
fmt.Println("索引" + indexName + "已成功创建!")
}
}
fmt.Println("恭喜,创建索引工作成功完成!")
}