Skip to content

Commit 2fd7421

Browse files
committed
完善输出
1 parent d4c02d0 commit 2fd7421

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

csv2es/cmd/import.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,12 @@ csv2es import --host=locahost --port=9200 --mapping=mapping_filename.json --inde
9292
for {
9393
row, err := reader.Read()
9494
if err == io.EOF {
95-
fmt.Printf("the file is over")
95+
fmt.Println("the file is over")
9696
break
9797
}
9898
if err != nil {
9999
panic(err)
100100
}
101-
fmt.Printf("Row 1: %+v\n", row)
102101

103102
req := elastic.NewBulkIndexRequest().Index(cParams.IndexName).Type(cParams.DocType).Doc(row)
104103
bulk.Add(req)

csv2es/cmd/root.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
)
2525

2626
type CommonParams struct {
27+
Debug bool
28+
2729
// es config
2830
Host string
2931
Port int
@@ -69,6 +71,7 @@ func init() {
6971
// Here you will define your flags and configuration settings.
7072
// Cobra supports persistent flags, which, if defined here,
7173
// will be global for your application.
74+
rootCmd.PersistentFlags().BoolVar(&cParams.Debug, "debug", false, "debug mode")
7275
rootCmd.PersistentFlags().StringVar(&cParams.Host, "host", "localhost", "es host")
7376
rootCmd.PersistentFlags().IntVar(&cParams.Port, "port", 9200, "es port")
7477
rootCmd.PersistentFlags().StringVar(&cParams.IndexName, "index", "", "es index name")
@@ -77,7 +80,7 @@ func init() {
7780

7881
// Cobra also supports local flags, which will only run
7982
// when this action is called directly.
80-
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
83+
//rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
8184
}
8285

8386
// initConfig reads in config file and ENV variables if set.

examples/import.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ if [ -f csv2es ]; then
99
cmd="./csv2es"
1010
fi
1111

12-
$cmd --host=100.115.147.50 --port=9200 --index=test --type=test --mapping=./eyenlp_area2016.json --csv=./eyenlp_area2016.csv
12+
$cmd import --host=100.115.147.50 --port=9200 --index=test --type=test --mapping=./eyenlp_area2016.json --csv=./eyenlp_area2016.csv --delete-index=true
1313

0 commit comments

Comments
 (0)