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/EsAddMappingByJson.go

32 lines
842 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import (
"dsTools/Utils/EsUtil"
"dsTools/Utils/FileUtil"
"fmt"
"io/ioutil"
"strings"
)
func main() {
//遍历目录下所有的文件
rd, _ := ioutil.ReadDir("MappingAddJson/")
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 + "不存在,无法创建!")
return
}
var jsonFile = "MappingAddJson/" + indexName + ".json"
//3、追加mapping定义
createMappingStr := FileUtil.ReadFileContent(jsonFile)
EsUtil.AddMapping(indexName, createMappingStr)
fmt.Println("索引"+indexName+"已成功追加Mapping")
}
}
fmt.Println("恭喜,追加索引工作成功完成!")
}