Documentation
¶
Overview ¶
Package esbulk implements a few helpers for performant indexing operations for elasticsearch.
Index ¶
- Variables
- func BulkIndex(ctx context.Context, docs []string, options Options) error
- func CreateHTTPClient(insecureSkipVerify bool, timeout time.Duration) *pester.Client
- func CreateHTTPRequest(method, url string, body io.Reader, options Options) (*http.Request, error)
- func CreateHTTPRequestWithContext(ctx context.Context, method, url string, body io.Reader, options Options) (*http.Request, error)
- func CreateIndex(options Options, body io.Reader) error
- func DeleteIndex(options Options) error
- func FlushIndex(idx int, options Options) error
- func GetSettings(idx int, options Options) (map[string]interface{}, error)
- func PutMapping(options Options, body io.Reader) error
- func Worker(ctx context.Context, id string, options Options, lines chan string, ...) error
- type ArrayFlags
- type BulkResponse
- type Item
- type Options
- type Runner
Constants ¶
This section is empty.
Variables ¶
var ( // Worker errors ErrWorkerCopyFailed = errors.New("worker failed to copy document batch") ErrWorkerBulkIndex = errors.New("worker bulk index operation failed") )
Functions ¶
func BulkIndex ¶ added in v0.3.0
BulkIndex takes a set of documents as strings and indexes them into elasticsearch.
func CreateHTTPClient ¶ added in v0.7.29
CreateHTTPClient creates a pester client with optional TLS configuration and timeout.
func CreateHTTPRequest ¶ added in v0.7.29
CreateHTTPRequest builds an HTTP request with authentication and headers. It handles basic authentication, content-type headers, and returns a ready-to-use request. Deprecated: Use CreateHTTPRequestWithContext instead.
func CreateHTTPRequestWithContext ¶ added in v0.7.29
func CreateHTTPRequestWithContext(ctx context.Context, method, url string, body io.Reader, options Options) (*http.Request, error)
CreateHTTPRequest builds an HTTP request with authentication and headers. It handles basic authentication, content-type headers, and returns a ready-to-use request.
func CreateIndex ¶ added in v0.6.0
CreateIndex creates a new index.
func DeleteIndex ¶ added in v0.6.0
DeleteIndex removes an index.
func FlushIndex ¶ added in v0.6.0
FlushIndex flushes index.
func GetSettings ¶ added in v0.6.0
GetSettings fetches the settings of the index.
func PutMapping ¶ added in v0.6.0
PutMapping applies a mapping from a reader.
func Worker ¶ added in v0.3.0
func Worker(ctx context.Context, id string, options Options, lines chan string, wg *sync.WaitGroup, errChan chan<- error) error
Worker will batch index documents that come in on the lines channel. Errors are sent to the provided error channel; the function always returns nil to satisfy the WaitGroup contract.
Types ¶
type ArrayFlags ¶ added in v0.6.0
type ArrayFlags []string
ArrayFlags allows to store lists of flag values.
func (*ArrayFlags) Set ¶ added in v0.6.0
func (f *ArrayFlags) Set(value string) error
Set appends a value.
func (*ArrayFlags) String ¶ added in v0.6.0
func (f *ArrayFlags) String() string
String representation.
type BulkResponse ¶ added in v0.6.0
type BulkResponse struct {
Took int `json:"took"`
HasErrors bool `json:"errors"`
Items []Item `json:"items"`
}
BulkResponse is a response to a bulk request.
type Item ¶ added in v0.6.0
type Item struct {
IndexAction struct {
Index string `json:"_index"`
Type string `json:"_type"`
ID string `json:"_id"`
Status int `json:"status"`
Error struct {
Type string `json:"type"`
Reason string `json:"reason"`
IndexUUID string `json:"index_uuid"`
Shard string `json:"shard"`
Index string `json:"index"`
} `json:"error"`
} `json:"index"`
}
Item represents a bulk action.
type Options ¶ added in v0.3.0
type Options struct {
Servers []string
Index string
OpType string
DocType string
BatchSize int
Verbose bool
IDField string
Scheme string // http or https; deprecated, use: Servers.
Username string
Password string
ApiKey string
Pipeline string
IncludeTypeName bool // https://www.elastic.co/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0
InsecureSkipVerify bool
// Timeout for HTTP requests (default: 30s)
RequestTimeout time.Duration
}
Options represents bulk indexing options.
func (*Options) RandomServer ¶ added in v0.7.29
RandomServer returns a random server from the Servers slice. Uses the global random generator seeded at program startup.
type Runner ¶ added in v0.7.0
type Runner struct {
ApiKey string
BatchSize int
Config string
CpuProfile string
OpType string
DocType string
File *os.File
FileGzipped bool
IdentifierField string
IndexName string
Mapping string
MemProfile string
NumWorkers int
Password string
Pipeline string
Purge bool
PurgePause time.Duration
RefreshInterval string
Scheme string
Servers []string
Settings string
ShowVersion bool
SkipBroken bool
Username string
Verbose bool
InsecureSkipVerify bool
ZeroReplica bool
// Request timeout for HTTP operations
RequestTimeout time.Duration
// contains filtered or unexported fields
}
Runner bundles various options. Factored out of a former main func and should be further split up (TODO).
