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)
| 313 | // elasticsearch.WithAPIKey("base64-encoded-key"), |
| 314 | // ) |
| 315 | func 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 |
nothing calls this directly
no test coverage detected