()
| 78 | } |
| 79 | |
| 80 | func main() { |
| 81 | log.SetFlags(0) |
| 82 | |
| 83 | var ( |
| 84 | articles []*Article |
| 85 | countSuccessful uint64 |
| 86 | |
| 87 | res *esapi.Response |
| 88 | err error |
| 89 | ) |
| 90 | |
| 91 | log.Printf( |
| 92 | "\x1b[1mBulkIndexer\x1b[0m: documents [%s] workers [%d] flush [%s]", |
| 93 | humanize.Comma(int64(numItems)), numWorkers, humanize.Bytes(uint64(flushBytes))) |
| 94 | log.Println(strings.Repeat("▁", 65)) |
| 95 | |
| 96 | // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 97 | // |
| 98 | // Use a third-party package for implementing the backoff function |
| 99 | // |
| 100 | retryBackoff := backoff.NewExponentialBackOff() |
| 101 | // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 102 | |
| 103 | // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 104 | // |
| 105 | // Create the Elasticsearch client |
| 106 | // |
| 107 | // NOTE: For optimal performance, consider using a third-party HTTP transport package. |
| 108 | // See an example in the "benchmarks" folder. |
| 109 | // |
| 110 | es, err := elasticsearch.New( |
| 111 | // Retry on 429 TooManyRequests statuses, up to 5 attempts |
| 112 | // |
| 113 | elasticsearch.WithRetry(5, 502, 503, 504, 429), |
| 114 | |
| 115 | // Configure the backoff function |
| 116 | // |
| 117 | elasticsearch.WithTransportOptions( |
| 118 | elastictransport.WithRetryBackoff(func(i int) time.Duration { |
| 119 | if i == 1 { |
| 120 | retryBackoff.Reset() |
| 121 | } |
| 122 | return retryBackoff.NextBackOff() |
| 123 | }), |
| 124 | ), |
| 125 | ) |
| 126 | if err != nil { |
| 127 | log.Fatalf("Error creating the client: %s", err) |
| 128 | } |
| 129 | // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 130 | |
| 131 | // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 132 | // |
| 133 | // Create the BulkIndexer |
| 134 | // |
| 135 | // NOTE: For optimal performance, consider using a third-party JSON decoding package. |
| 136 | // See an example in the "benchmarks" folder. |
| 137 | // |
nothing calls this directly
no test coverage detected