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

Bug: Typedapi Nodes.Info().Do() returns json unmarshalling error. #911

Open
hellconnon opened this issue Oct 15, 2024 · 2 comments
Open

Comments

@hellconnon
Copy link

hellconnon commented Oct 15, 2024

Hey,

when using the typed api client like this:

	esClientSbx, _ := elasticsearch.NewTypedClient(config)
	ctx := context.Background()

	nodesInfo, err := esClientSbx.Nodes.Info().Do(ctx)
	if err != nil {
		fmt.Println("Err: ", err)
	}
	fmt.Println("Info: ",nodesInfo)

i get the following error:

❯ go run .
Err:  Settings | Data | json: cannot unmarshal string into Go value of type []string
Info:  <nil>

I couldn't exactly track down which specific field causes the error.

Edit: I used the filter_path incorrectly and removed the part. The main issue is that the json response cannot be unmarshalled into the info.Response struct anyways.

@hellconnon hellconnon changed the title Bug: Typedapi Nodes.Info().Do() returns json unmarshalling error. Nodes.Info().Filterpath().Do() supresses Error and just returns nil. Bug: Typedapi Nodes.Info().Do() returns json unmarshalling error. Oct 16, 2024
@hellconnon
Copy link
Author

It looks like it is the NodesInfoPath struct in types.nodeinfopath.go, at least that is one place, where it seems to be incorrect.
The struct definition is:

type NodeInfoPath struct {
	Data []string `json:"data,omitempty"`
	Home *string  `json:"home,omitempty"`
	Logs *string  `json:"logs,omitempty"`
	Repo []string `json:"repo,omitempty"`
}

While the API returns:

        "path": {
          "data": "/srv/elasticsearch",
          "logs": "/var/log/elasticsearch/xyz",
          "home": "/usr/share/elasticsearch"

@hellconnon
Copy link
Author

In my case changing this definition resolves the error and my api seems to never return an array of strings.
New definition:

// NodeInfoPath type.
//
// https://github.com/elastic/elasticsearch-specification/blob/19027dbdd366978ccae41842a040a636730e7c10/specification/nodes/info/types.ts#L158-L163
type NodeInfoPath struct {
	Data string   `json:"data,omitempty"`
	Home *string  `json:"home,omitempty"`
	Logs *string  `json:"logs,omitempty"`
	Repo []string `json:"repo,omitempty"`
}

But one could also use a custom Type StringOrSliceto cover both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant