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

Do we support CBOR format communicating

Open junchih opened this issue 5 years ago • 3 comments

hi guys,

I just noticed https://github.com/elastic/go-elasticsearch/blob/v6.8.5/esapi/api.search.go#L316, seems all the data format we could support is json.

and from the official document https://www.elastic.co/guide/en/elasticsearch/reference/6.8/common-options.html#_content_type_requirements. I got a little confused, will we support the data format other than json in this library.

junchih avatar Feb 11 '20 16:02 junchih

Hello, I don't think any of the official libraries support CBOR.

There's no built-support for CBOR in go-elasticsearch, but since the body is passed as an io.Reader, you can play with it, and setting the request header to a corresponding value — but again, I've never tried.

If you're after faster JSON encoding, have a look into examples in https://github.com/elastic/go-elasticsearch/tree/master/_examples/encoding.

karmi avatar Feb 11 '20 16:02 karmi

hi @karmi , I've tried with original non-modified this library. it doesn't work, since we just combined all the values of a same-key-header.

I'm considering a PR to fix it, and based on two reasons,

  1. it even will fail if I set the Content-Type to application/json manually.
  2. to let this library to be compatible with official document.

junchih avatar Feb 12 '20 02:02 junchih

Agreed, I think these lines should be wrapped in a condition like req.Header[headerContentType] == "":

https://github.com/elastic/go-elasticsearch/blob/aff00e5adfde9994ddeb2619ecb7b2131071c338/esapi/api.search.go#L315-L317

What if you play with it eg. with the Search (etc) API, and I can later update the generator.

karmi avatar Feb 12 '20 07:02 karmi