MCPcopy
hub / github.com/elastic/go-elasticsearch / NewBase

Function NewBase

elasticsearch.go:347–363  ·  view source on GitHub ↗

NewBase creates a new [BaseClient] configured with the given options. It does not attach the esapi or typed API surface, which keeps the binary smaller for programs that only need [BaseClient.Perform]. With no options the client connects to http://localhost:9200, or to the address(es) in the ELASTI

(opts ...Option)

Source from the content-addressed store, hash-verified

345// elasticsearch.WithAPIKey("base64-encoded-key"),
346// )
347func NewBase(opts ...Option) (*BaseClient, error) {
348 ro, err := resolveOptions(opts, "")
349 if err != nil {
350 return nil, err
351 }
352 client := &BaseClient{
353 Transport: ro.transport,
354 disableMetaHeader: ro.disableMetaHeader,
355 metaHeader: ro.metaHeader,
356 compatibilityHeader: ro.compatibilityHeader,
357 autoDrainBody: ro.autoDrainBody,
358 }
359 if ro.discoverNodesOnStart {
360 go func() { _ = client.DiscoverNodes() }()
361 }
362 return client, nil
363}
364
365// NewTyped creates a new [TypedClient] configured with the given options.
366//

Callers 4

TestNewBase_DefaultFunction · 0.70
TestNewBase_CloseFunction · 0.70
TestCloseFunction · 0.70

Calls 2

DiscoverNodesMethod · 0.95
resolveOptionsFunction · 0.85

Tested by 4

TestNewBase_DefaultFunction · 0.56
TestNewBase_CloseFunction · 0.56
TestCloseFunction · 0.56