NewClient creates a new client with configuration from cfg. It will use http://localhost:9200 as the default address. It will use the ELASTICSEARCH_URL environment variable, if set, to configure the addresses; use a comma to separate multiple URLs. If either cfg.Addresses or cfg.CloudID is set, t
(cfg Config)
| 241 | // |
| 242 | // Deprecated: Use [New] with [Option] values instead. |
| 243 | func NewClient(cfg Config) (*Client, error) { |
| 244 | tp, err := newTransport(cfg) |
| 245 | if err != nil { |
| 246 | return nil, err |
| 247 | } |
| 248 | |
| 249 | compatHeaderEnv := os.Getenv(esCompatHeader) |
| 250 | compatibilityHeader, _ := strconv.ParseBool(compatHeaderEnv) |
| 251 | |
| 252 | client := &Client{ |
| 253 | BaseClient: BaseClient{ |
| 254 | Transport: tp, |
| 255 | disableMetaHeader: cfg.DisableMetaHeader, |
| 256 | metaHeader: initMetaHeader(tp), |
| 257 | compatibilityHeader: cfg.EnableCompatibilityMode || compatibilityHeader, |
| 258 | autoDrainBody: cfg.AutoDrainBody, |
| 259 | }, |
| 260 | } |
| 261 | client.API = esapi.New(client) |
| 262 | |
| 263 | if cfg.DiscoverNodesOnStart { |
| 264 | go func() { _ = client.DiscoverNodes() }() |
| 265 | } |
| 266 | |
| 267 | return client, nil |
| 268 | } |
| 269 | |
| 270 | // NewTypedClient create a new client with the configuration from cfg. |
| 271 | // |