go-elasticsearch icon indicating copy to clipboard operation
go-elasticsearch copied to clipboard

Where are all the Response structs?

Open ansoni opened this issue 4 years ago • 5 comments

Where are all the Response structs at? I don't think they exist.

If not, I struggle to understand why they are not implemented. Is the expectation that I am going to write my own models to parse every API's Body response? This is a massive waste of time and maintenance burden on the consumers of this SDK and is a missed opportunity to address some of the challenges with consuming the Elasticsearch APIs (such as _cat apis returning strings for everything).

ansoni avatar Mar 08 '20 18:03 ansoni

Hello, this question comes up periodically — I think the last time I've responded in detail was in https://github.com/elastic/go-elasticsearch/issues/120.

The short answer "why they are not implemented" is that there's no specification to generate them, as opposed to the surface of the API, which is fully generated, and therefory fully in sync with three major versions of Elasticsearch.

I will find some time to write up a summary and pin it to the issues page, so it's easier to find. Also, I have some ideas how to make it hurt a little less.


(...) such as _cat apis returning strings for everything (...)

That is by design — Cat APIs are usually consumed in a shell script. In Go, you probably want to set the format parameter to "json".

karmi avatar Mar 12 '20 06:03 karmi

I upvoted this issue, because I agree with the basic premise the API needs Response structs to be an effective tool for developers. There is some discussion in elastic/elasticsearch#25152 that might be helpful regarding automating the client apis.

dekimsey avatar Dec 16 '20 23:12 dekimsey

I upvoted this issue, because I agree with the basic premise the API needs Response structs to be an effective tool for developers. There is some discussion in elastic/elasticsearch#25152 that might be helpful regarding automating the client apis.

I totally agree. I am running into this issue now. I guess this is a larger problem for Elasticsearch. I often struggle to find the definition of response bodies in their documentation. Isn't it standard practice to document your API's response types?

johnbuonassisi avatar Feb 23 '21 21:02 johnbuonassisi

@johnbuonassisi So I ran into similar issues with the docs. Prior to 7.x, the rest endpoints weren't explicitly documented. Since our major cluster is 6.x, I frequently have both open so I can look at the API docs and finh roughly what I need.

They still don't really document error conditions, so it can still be a bit challenging to write against. Especially in something like go. But that's somewhat off topic.

That all aside, the suggested tidwall/gjson library is helpful. But it is a wierd way to handle the API. It seems more appropriate for reading arbitrary json off some third-party source than to be the recommended interface for the official go library.

dekimsey avatar Feb 24 '21 00:02 dekimsey

Do the concerns from the comment above still apply today? I'm not sure if we're still inhibited by the same limitations

SomniVertix avatar Jun 28 '22 16:06 SomniVertix

Is there any progress on this matter soon? I have been told the Elasticsearch is already public product since years ago, but it is hard to believe that the error response is not clearly defined.

yamada-wacul avatar Oct 27 '22 10:10 yamada-wacul

The Elasticsearch Java API does have requests/responses classes generated somehow e.g. IndexResponse. I'd at least expect to have the same in all ES libraries/modules 😕

kevinnoel-be avatar Nov 10 '22 09:11 kevinnoel-be