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

49 lines
1.3 KiB

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/FileUtil"
"fmt"
//这个库是目前我接触到最好用的json库强烈推荐
"github.com/tidwall/gjson"
)
var map1 = make(map[string]string)
var map2 = make(map[string]string)
func main() {
var indexName = "twitter"
var path = "mappings.properties"
var backupPath = "./MappingBackupJson/"
var createPath = "./MappingCreateJson/"
json1 := FileUtil.ReadFileContent(backupPath + indexName + ".json")
value1 := gjson.Get(json1, path)
value1.ForEach(printKeyValue1())
json2 := FileUtil.ReadFileContent(createPath + indexName + ".json")
value2 := gjson.Get(json2, path)
value2.ForEach(printKeyValue2())
//获取2比1多的字段生成可以增加字段的mapping
for k, v := range map2 {
//如果存在,表示不需要增加
if _, ok := map1[k]; ok {
//存在,就算是字段类型不一样,也无法变更,只能提供一下。
} else {
fmt.Println(k, v)
fmt.Println(fmt.Sprintf("发现新增字段%s,已成功增加!\n", k))
}
}
}
func printKeyValue1() func(key gjson.Result, value gjson.Result) bool {
return func(key, value gjson.Result) bool {
map1[key.String()] = value.String()
return true
}
}
func printKeyValue2() func(key gjson.Result, value gjson.Result) bool {
return func(key, value gjson.Result) bool {
map2[key.String()] = value.String()
return true
}
}