func newBulkProcessorStats(workers int) *BulkProcessorStats {
	stats := &BulkProcessorStats{
		Workers: make([]*BulkProcessorWorkerStats, workers),
	}
	for i := 0; i < workers; i++ {
		stats.Workers[i] = &BulkProcessorWorkerStats{}
	}
	return stats
}
newBulkProcessorStats initializes and returns a BulkProcessorStats struct.
package elastic
import (
	"sync"
	"sync/atomic"
	"time"
	"gopkg.in/olivere/elastic.v3/backoff"
)
type BulkProcessorService struct {
	c              *Client
	beforeFn       BulkBeforeFunc
	afterFn        BulkAfterFunc
	name           string         
	numWorkers     int            
	bulkActions    int            
	bulkSize       int            
	flushInterval  time.Duration  
	wantStats      bool           
	initialTimeout time.Duration  
	maxTimeout     time.Duration  
}
func NewBulkProcessorService(client *Client) *BulkProcessorService {
	return &BulkProcessorService{
		c:              client,
		numWorkers:     1,
		bulkActions:    1000,
		bulkSize:       5 << 20,  
		initialTimeout: time.Duration(200) * time.Millisecond,
		maxTimeout:     time.Duration(10000) * time.Millisecond,
	}
}
type BulkBeforeFunc func(executionId int64, requests []BulkableRequest)
type BulkAfterFunc func(executionId int64, requests []BulkableRequest, response *BulkResponse, err error)
func (s *BulkProcessorService) Before(fn BulkBeforeFunc) *BulkProcessorService {
	s.beforeFn = fn
	return s
}
func (s *BulkProcessorService) After(fn BulkAfterFunc) *BulkProcessorService {
	s.afterFn = fn
	return s
}
func (s *BulkProcessorService) Name(name string) *BulkProcessorService {
	s.name = name
	return s
}
func (s *BulkProcessorService) Workers(num int) *BulkProcessorService {
	s.numWorkers = num
	return s
}
func (s *BulkProcessorService) BulkActions(bulkActions int) *BulkProcessorService {
	s.bulkActions = bulkActions
	return s
}
func (s *BulkProcessorService) BulkSize(bulkSize int) *BulkProcessorService {
	s.bulkSize = bulkSize
	return s
}
func (s *BulkProcessorService) FlushInterval(interval time.Duration) *BulkProcessorService {
	s.flushInterval = interval
	return s
}
func (s *BulkProcessorService) Stats(wantStats bool) *BulkProcessorService {
	s.wantStats = wantStats
	return s
}
func (s *BulkProcessorService) Do() (*BulkProcessor, error) {
	p := newBulkProcessor(
		s.c,
		s.beforeFn,
		s.afterFn,
		s.name,
		s.numWorkers,
		s.bulkActions,
		s.bulkSize,
		s.flushInterval,
		s.wantStats,
		s.initialTimeout,
		s.maxTimeout)
	err := p.Start()
	if err != nil {
		return nil, err
	}
	return p, nil
}
type BulkProcessorStats struct {
	Flushed   int64  
	Committed int64  
	Indexed   int64  
	Created   int64  
	Updated   int64  
	Deleted   int64  
	Succeeded int64  
	Failed    int64  
	Workers []*BulkProcessorWorkerStats  
}
type BulkProcessorWorkerStats struct {
	Queued       int64          
	LastDuration time.Duration  
}