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

Function NewClient

elasticsearch.go:243–268  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

241//
242// Deprecated: Use [New] with [Option] values instead.
243func 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//

Calls 4

NewFunction · 0.92
newTransportFunction · 0.85
initMetaHeaderFunction · 0.85
DiscoverNodesMethod · 0.80