()
| 77 | } |
| 78 | |
| 79 | func main() { |
| 80 | log.SetFlags(0) |
| 81 | |
| 82 | type bulkResponse struct { |
| 83 | Errors bool `json:"errors"` |
| 84 | Items []struct { |
| 85 | Index struct { |
| 86 | ID string `json:"_id"` |
| 87 | Result string `json:"result"` |
| 88 | Status int `json:"status"` |
| 89 | Error struct { |
| 90 | Type string `json:"type"` |
| 91 | Reason string `json:"reason"` |
| 92 | Cause struct { |
| 93 | Type string `json:"type"` |
| 94 | Reason string `json:"reason"` |
| 95 | } `json:"caused_by"` |
| 96 | } `json:"error"` |
| 97 | } `json:"index"` |
| 98 | } `json:"items"` |
| 99 | } |
| 100 | |
| 101 | var ( |
| 102 | buf bytes.Buffer |
| 103 | res *esapi.Response |
| 104 | err error |
| 105 | raw map[string]interface{} |
| 106 | blk *bulkResponse |
| 107 | |
| 108 | articles []*Article |
| 109 | indexName = "articles" |
| 110 | |
| 111 | numItems int |
| 112 | numErrors int |
| 113 | numIndexed int |
| 114 | numBatches int |
| 115 | currBatch int |
| 116 | ) |
| 117 | |
| 118 | log.Printf( |
| 119 | "\x1b[1mBulk\x1b[0m: documents [%s] batch size [%s]", |
| 120 | humanize.Comma(int64(count)), humanize.Comma(int64(batch))) |
| 121 | log.Println(strings.Repeat("▁", 65)) |
| 122 | |
| 123 | // Create the Elasticsearch client |
| 124 | // |
| 125 | es, err := elasticsearch.New() |
| 126 | if err != nil { |
| 127 | log.Fatalf("Error creating the client: %s", err) |
| 128 | } |
| 129 | defer func() { |
| 130 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 131 | defer cancel() |
| 132 | if err := es.Close(ctx); err != nil { |
| 133 | log.Fatalf("Error closing the client: %s", err) |
| 134 | } |
| 135 | }() |
| 136 |
nothing calls this directly
no test coverage detected