Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose individual apis #177

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
41 changes: 33 additions & 8 deletions elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,38 @@ func NewDefaultClient() (*Client, error) {
// It's an error to set both cfg.Addresses and cfg.CloudID.
//
func NewClient(cfg Config) (*Client, error) {
tp, err := NewTransportClient(cfg)
if err != nil {
return nil, err
}

client := &Client{Transport: tp, API: esapi.New(tp)}

if cfg.DiscoverNodesOnStart {
go client.DiscoverNodes()
}
Comment on lines +106 to +108
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for starting discovery in NewClient and not NewTransportClient?

It seems surprising that cfg.DiscoverNodesOnStart would be ignored when calling NewTransportClient, and probably not a desired change in behaviour for users who are only trying to slim down the API surface area.

Maybe we should add a DiscoverNodesOnStart flag to estransport.Config, and start the goroutine there?


return client, nil
}

// NewTransportClient creates a new low-level transport client
// with configuration from cfg. Generally, you'll only want to
// use this if you want to be selective of the APIs your client
// uses. In most cases use NewClient, which attempts to discover
// additional Elasticsearch nodes and automatically instantiates
// all Elasticsearch API clients for you.
//
// 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, the ELASTICSEARCH_URL
// environment variable is ignored.
//
// It's an error to set both cfg.Addresses and cfg.CloudID.
//
func NewTransportClient(cfg Config) (*estransport.Client, error) {
var addrs []string

if len(cfg.Addresses) == 0 && cfg.CloudID == "" {
Expand Down Expand Up @@ -163,14 +195,7 @@ func NewClient(cfg Config) (*Client, error) {
if err != nil {
return nil, fmt.Errorf("error creating transport: %s", err)
}

client := &Client{Transport: tp, API: esapi.New(tp)}

if cfg.DiscoverNodesOnStart {
go client.DiscoverNodes()
}

return client, nil
return tp, nil
}

// Perform delegates to Transport to execute a request and return a response.
Expand Down
Loading