Files
elasticsearch-js/docs/reference/transport.md
Colleen McGinnis 3e5e568c07 [docs] Migrate docs from AsciiDoc to Markdown (#2635)
* delete asciidoc files

* add migrated files

* Apply suggestions from review

Co-authored-by: Josh Mock <josh@joshmock.com>

* Apply suggestions from review

Co-authored-by: Josh Mock <josh@joshmock.com>

* add the new ci checks (#2634)

---------

Co-authored-by: Marci W <333176+marciw@users.noreply.github.com>
Co-authored-by: Josh Mock <josh@joshmock.com>
2025-02-27 12:51:14 -05:00

1.5 KiB

mapped_pages
mapped_pages
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/transport.html

Transport [transport]

This class is responsible for performing the request to {{es}} and handling errors, it also handles sniffing.

const { Client } = require('@elastic/elasticsearch')
const { Transport } = require('@elastic/transport')

class MyTransport extends Transport {
  request (params, options, callback) {
    // your code
  }
}

const client = new Client({
    Transport: MyTransport
})

Sometimes you need to inject a small snippet of your code and then continue to use the usual client code. In such cases, call super.method:

class MyTransport extends Transport {
  request (params, options, callback) {
    // your code
    return super.request(params, options, callback)
  }
}

Supported content types [_supported_content_types]

Depending on the content-type of the response, the transport will return the body as different types:

Content-Type JavaScript type
application/json object
text/plain string
application/vnd.elasticsearch+json object
application/vnd.mapbox-vector-tile Buffer
application/vnd.apache.arrow.stream Buffer
application/vnd.elasticsearch+arrow+stream Buffer
application/smile Buffer
application/vnd.elasticsearch+smile Buffer
application/cbor Buffer
application/vnd.elasticsearch+cbor Buffer