diff --git a/dsSupport/Test/ElasticsearchToCsv/ReadElasticsearchToCsv.go b/dsSupport/Test/ElasticsearchToGreenPlum/ElasticsearchToGreenPlum.go similarity index 69% rename from dsSupport/Test/ElasticsearchToCsv/ReadElasticsearchToCsv.go rename to dsSupport/Test/ElasticsearchToGreenPlum/ElasticsearchToGreenPlum.go index 1e49f83b..0fae34d2 100644 --- a/dsSupport/Test/ElasticsearchToCsv/ReadElasticsearchToCsv.go +++ b/dsSupport/Test/ElasticsearchToGreenPlum/ElasticsearchToGreenPlum.go @@ -3,7 +3,6 @@ package main import ( "context" "dsSupport/Utils/PgUtil" - "encoding/csv" "encoding/json" "fmt" "github.com/olivere/elastic/v7" @@ -67,12 +66,9 @@ func main() { for i := range result.Hits.Hits { resByte, _ := json.Marshal(result.Hits.Hits[i].Source) - jsonStr := string(resByte) - m := make(map[string]interface{}) - json.Unmarshal([]byte(jsonStr), &m) - for k, v := range m { - fmt.Printf("%v: %v\n", k, v) - } + resStr := string(resByte) + value := gjson.Get(resStr, "data_content") + fmt.Println(value.String()) } } else { //没有数据了 @@ -81,19 +77,3 @@ func main() { } } -func SaveToCsv(csvFileName string, _map []map[string]interface{}) { - file, err := os.OpenFile(csvFileName, os.O_CREATE|os.O_RDWR, 0644) - if err != nil { - fmt.Println("open file is failed, err: ", err) - } - defer file.Close() - // 写入UTF-8 BOM,防止中文乱码 - file.WriteString("\xEF\xBB\xBF") - w := csv.NewWriter(file) - //for i := range _map { - // //_map[i] - //} - w.Write([]string{"开发者名称", "开发者邮箱", "应用名称"}) - // 写文件需要flush,不然缓存满了,后面的就写不进去了,只会写一部分 - w.Flush() -}