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] MappingFieldResp struct is not parsed correctly. #560

Closed
agnivade opened this issue Jun 4, 2024 · 2 comments · Fixed by #572
Closed

[BUG] MappingFieldResp struct is not parsed correctly. #560

agnivade opened this issue Jun 4, 2024 · 2 comments · Fixed by #572
Assignees
Labels
bug Something isn't working

Comments

@agnivade
Copy link

agnivade commented Jun 4, 2024

What is the bug?

MappingFieldResp struct is not parsed correctly.

How can one reproduce the bug?

A short snippet

mappingFieldResp, err := client.Indices.Mapping.Field(ctx, &opensearchapi.MappingFieldReq{
		Fields:  []string{"type"},
		Indices: []string{indexName},
	})
	fmt.Println("---------------------")
	io.Copy(os.Stderr, mappingFieldResp.Inspect().Response.Body)
	fmt.Printf("\n%+v\n", mappingFieldResp.Indices)
	fmt.Printf("\n---------------------\n")

prints

---------------------
{"channels":{"mappings":{"type":{"full_name":"type","mapping":{"type":{"type":"keyword"}}}}}}
map[]
---------------------

What is the expected behavior?

It should parse the data correctly

What is your host/environment?

Linux

Do you have any additional context?

The issue is that there is an additional Indices field which is there inside the struct which is not allowing the response to be parsed properly.

Here:

if data.response, err = c.apiClient.do(ctx, req, &data); err != nil {
, we need to pass data.Indices instead of data.

I am not sure how the unit tests are passing. But it seems like a pretty straightforward bug to me.

EDIT: Something like this works:

var mappingFieldResp map[string]struct {
  Mappings json.RawMessage `json:"mappings"`
}
httpResp, err := es.client.Client.Do(ctx, &opensearchapi.MappingFieldReq{
  Fields:  []string{"type"},
  Indices: []string{indexName},
}, &mappingFieldResp)
@agnivade agnivade added bug Something isn't working untriaged labels Jun 4, 2024
@dblock
Copy link
Member

dblock commented Jun 4, 2024

Looks like a miss. Want to fix it here?

Also note that we would like to generate the client from spec to catch all this kind of problems (#284), so would be great to check the spec for correctness for this API.

@dblock dblock removed the untriaged label Jun 4, 2024
@agnivade
Copy link
Author

agnivade commented Jun 4, 2024

I can, but currently I have a workaround so it's not urgent for me. I'll see if I can find some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants