I have an array of documents to bulk indexusing the github.com/elastic/go-elasticsearch/v8 library.
Each document may be added to one of a handful of different indexes, so my code is something like:
var indexers map[string]esutil.BulkIndexer = make(map[string]esutil.BulkIndexer)
for i := range documents {
var bi esutil.BulkIndexer
var ok bool
var err error
if bi, ok = indexers[documents[i].index]; !ok {
bi, err = esutil.NewBulkIndexer(esutil.BulkIndexerConfig{
Index: documents[i].index, // The index name
Client: client, // The Elasticsearch client* Same isntance for all indexers*
NumWorkers: BULK_NUM_WORKERS, // The number of worker goroutines
FlushBytes: int(BULK_FLUSHBYTES), // The flush threshold in bytes
FlushInterval: 5 * time.Second, // The periodic flush interval
})
if err != nil {
fmt.Printf("Error creating the indexer: %s", err)
continue
}
indexers[documents[i].indexName] = bi
}
The idea is I have a map of esutil.BulkIndexer , an they all share the same elasticsearch.Client instance. So my question is if it's ok and safe for several
esutil.BulkIndexer to share the same elasticsearch.Client, or do they each need a separate instance of a elasticsearch.Client ?