传输

编辑

此类负责执行到 Elasticsearch 的请求并处理错误,它还处理嗅探。

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
})

有时您需要注入一小段代码,然后继续使用通常的客户端代码。在这种情况下,调用 super.method

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

支持的内容类型

编辑

根据响应的 content-type,传输将以不同的类型返回主体

Content-Type JavaScript 类型

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