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

Function New

elasticsearch.go:315–334  ·  view source on GitHub ↗

New creates a new [Client] configured with the given options. With no options the client connects to http://localhost:9200, or to the address(es) in the ELASTICSEARCH_URL environment variable when set. client, err := elasticsearch.New( elasticsearch.WithAddresses("https://localhost:9200"),

(opts ...Option)

Source from the content-addressed store, hash-verified

313// elasticsearch.WithAPIKey("base64-encoded-key"),
314// )
315func New(opts ...Option) (*Client, error) {
316 ro, err := resolveOptions(opts, "")
317 if err != nil {
318 return nil, err
319 }
320 client := &Client{
321 BaseClient: BaseClient{
322 Transport: ro.transport,
323 disableMetaHeader: ro.disableMetaHeader,
324 metaHeader: ro.metaHeader,
325 compatibilityHeader: ro.compatibilityHeader,
326 autoDrainBody: ro.autoDrainBody,
327 },
328 }
329 client.API = esapi.New(client)
330 if ro.discoverNodesOnStart {
331 go func() { _ = client.DiscoverNodes() }()
332 }
333 return client, nil
334}
335
336// NewBase creates a new [BaseClient] configured with the given options.
337// It does not attach the esapi or typed API surface, which keeps the

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
resolveOptionsFunction · 0.85
DiscoverNodesMethod · 0.80

Tested by

no test coverage detected