From 1c68dfdd8f9f729a5b24febe92b163de3e7049f3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 2 Nov 2023 10:20:39 -0500 Subject: [PATCH] [Backport 8.11] Add more docs about keep-alive connections (#2050) (cherry picked from commit f1e83ae853da8743688eee0f9b3f120a0080b00b) Co-authored-by: Josh Mock --- docs/connecting.asciidoc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/connecting.asciidoc b/docs/connecting.asciidoc index 5e1bd2366..77c2e7d11 100644 --- a/docs/connecting.asciidoc +++ b/docs/connecting.asciidoc @@ -11,6 +11,7 @@ This page contains the information you need to connect and use the Client with * <> * <> * <> +* <> * <> [[authentication]] @@ -659,6 +660,37 @@ a|* `name` - `string` * `headers` - `object`, the response status code |=== +[[keep-alive]] +[discrete] +=== Keep-alive connections + +By default, the client uses persistent, keep-alive connections to reduce the overhead of creating a new HTTP connection for each Elasticsearch request. +If you are using the default `UndiciConnection` connection class, it maintains a pool of 256 connections with a keep-alive of 10 minutes. +If you are using the legacy `HttpConnection` connection class, it maintains a pool of 256 connections with a keep-alive of 1 minute. + +If you need to disable keep-alive connections, you can override the HTTP agent with your preferred https://nodejs.org/api/http.html#http_new_agent_options[HTTP agent options]: + +[source,js] +---- +const client = new Client({ + node: 'http://localhost:9200', + // the function takes as parameter the option + // object passed to the Connection constructor + agent: (opts) => new CustomAgent() +}) +---- + +Or you can disable the HTTP agent entirely: + +[source,js] +---- +const client = new Client({ + node: 'http://localhost:9200', + // Disable agent and keep-alive + agent: false +}) +---- + [discrete] [[product-check]] === Automatic product check