Skip to content

[Backport 9.0] Merge serverless functionality from @elastic/elasticsearch-serverless #2696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions docs/reference/basic-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ const client = new Client({

### `node` or `nodes`

The Elasticsearch endpoint to use. It can be a single string or an array of strings:
The {{es}} endpoint to use. It can be a single string or an array of strings:

```js
node: 'http://localhost:9200'
```

```js
nodes: ['http://localhost:9200', 'http://localhost:9201']
```

Or it can be an object (or an array of objects) that represents the node:

```js
Expand All @@ -52,7 +56,6 @@ Default: `null`

Your authentication data. You can use both basic authentication and [ApiKey](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-create-api-key).
See [Authentication](/reference/connecting.md#authentication) for more details.


Basic authentication:

Expand Down Expand Up @@ -113,7 +116,7 @@ Max ping request timeout in milliseconds for each request.
Type: `number, boolean`<br>
Default: `false`

Perform a sniff operation every `n` milliseconds.
Perform a sniff operation every `n` milliseconds.

:::{tip}
Sniffing might not be the best solution. Before using the various `sniff` options, review this [blog post](https://www.elastic.co/blog/elasticsearch-sniffing-best-practices-what-when-why-how).
Expand Down Expand Up @@ -182,7 +185,7 @@ Options: `'gzip'`, `false`
Type: `http.SecureContextOptions`<br>
Default: `null`

The [tls configuraton](https://nodejs.org/api/tls.md).
The [tls configuraton](https://nodejs.org/api/tls.html).

---

Expand All @@ -192,7 +195,6 @@ Type: `string, URL`<br>
Default: `null`

If you are using an http(s) proxy, you can put its url here. The client will automatically handle the connection to it.


```js
const client = new Client({
Expand All @@ -213,7 +215,7 @@ const client = new Client({
Type: `http.AgentOptions, function`<br>
Default: `null`

http agent [options](https://nodejs.org/api/http.md#http_new_agent_options), or a function that returns an actual http agent instance. If you want to disable the http agent use entirely (and disable the `keep-alive` feature), set the agent to `false`.
http agent [options](https://nodejs.org/api/http.html#http_new_agent_options), or a function that returns an actual http agent instance. If you want to disable the http agent use entirely (and disable the `keep-alive` feature), set the agent to `false`.

```js
const client = new Client({
Expand Down Expand Up @@ -394,4 +396,26 @@ When configured, `maxResponseSize` verifies that the uncompressed response size
Type: `number`<br>
Default: `null`

When configured, `maxCompressedResponseSize` verifies that the compressed response size is lower than the configured number. If it’s higher, the request will be canceled. The `maxCompressedResponseSize` cannot be higher than the value of `buffer.constants.MAX_STRING_LENGTH`.
When configured, `maxCompressedResponseSize` verifies that the compressed response size is lower than the configured number. If it’s higher, the request will be canceled. The `maxCompressedResponseSize` cannot be higher than the value of `buffer.constants.MAX_STRING_LENGTH`.

---

### `redaction`

Type: `object`<br>
Default: A configuration that will replace known sources of sensitive data in `Error` metadata

Options for how to redact potentially sensitive data from metadata attached to `Error` objects

::::{note}
[Read about redaction](/reference/advanced-config.md#redaction) for more details
::::

---

### `serverMode`

Type: `string`<br>
Default: `"stack"`

Setting to `"stack"` sets defaults assuming a traditional (non-serverless) {{es}} instance. Setting to `"serverless"` sets defaults to work more seamlessly with [Elastic Cloud Serverless](https://www.elastic.co/guide/en/serverless/current/intro.html), like enabling compression and disabling features that assume the possibility of multiple {{es}} nodes.
27 changes: 0 additions & 27 deletions docs/reference/client-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ The client comes with an handy collection of helpers to give you a more comforta
The client helpers are experimental, and the API may change in the next minor releases. The helpers will not work in any Node.js version lower than 10.
::::



## Bulk helper [bulk-helper]

Added in `v7.7.0`

Running bulk requests can be complex due to the shape of the API, this helper aims to provide a nicer developer experience around the Bulk API.


### Usage [_usage_3]

```js
Expand Down Expand Up @@ -67,10 +64,8 @@ To create a new instance of the Bulk helper, access it as shown in the example a
| `wait` | How much time to wait before retries in milliseconds.<br> *Default:* 5000.<br><br>```js<br>const b = client.helpers.bulk({<br> wait: 3000<br>})<br>```<br> |
| `refreshOnCompletion` | If `true`, at the end of the bulk operation it runs a refresh on all indices or on the specified indices.<br> *Default:* false.<br><br>```js<br>const b = client.helpers.bulk({<br> refreshOnCompletion: true<br> // or<br> refreshOnCompletion: 'index-name'<br>})<br>```<br> |


### Supported operations [_supported_operations]


#### Index [_index_2]

```js
Expand All @@ -84,7 +79,6 @@ client.helpers.bulk({
})
```


#### Create [_create_4]

```js
Expand All @@ -98,7 +92,6 @@ client.helpers.bulk({
})
```


#### Update [_update_3]

```js
Expand All @@ -116,7 +109,6 @@ client.helpers.bulk({
})
```


#### Delete [_delete_10]

```js
Expand All @@ -130,7 +122,6 @@ client.helpers.bulk({
})
```


### Abort a bulk operation [_abort_a_bulk_operation]

If needed, you can abort a bulk operation at any time. The bulk helper returns a [thenable](https://promisesaplus.com/), which has an `abort` method.
Expand All @@ -139,7 +130,6 @@ If needed, you can abort a bulk operation at any time. The bulk helper returns a
The abort method stops the execution of the bulk operation, but if you are using a concurrency higher than one, the operations that are already running will not be stopped.
::::


```js
const { createReadStream } = require('fs')
const split = require('split2')
Expand All @@ -164,7 +154,6 @@ const b = client.helpers.bulk({
console.log(await b)
```


### Passing custom options to the Bulk API [_passing_custom_options_to_the_bulk_api]

You can pass any option supported by the link: [Bulk API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-bulk) to the helper, and the helper uses those options in conjunction with the Bulk API call.
Expand All @@ -181,7 +170,6 @@ const result = await client.helpers.bulk({
})
```


### Usage with an async generator [_usage_with_an_async_generator]

```js
Expand Down Expand Up @@ -214,7 +202,6 @@ const result = await client.helpers.bulk({
console.log(result)
```


### Modifying a document before operation [_modifying_a_document_before_operation]

Added in `v8.8.2`
Expand All @@ -241,14 +228,12 @@ const result = await client.helpers.bulk({
console.log(result)
```


## Multi search helper [multi-search-helper]

Added in `v7.8.0`

If you send search request at a high rate, this helper might be useful for you. It uses the multi search API under the hood to batch the requests and improve the overall performances of your application. The `result` exposes a `documents` property as well, which allows you to access directly the hits sources.


### Usage [_usage_4]

```js
Expand Down Expand Up @@ -278,7 +263,6 @@ To create a new instance of the multi search (msearch) helper, you should access
| `retries` | How many times an operation is retried before to resolve the request. An operation is retried only in case of a 429 error.<br> *Default:* Client max retries.<br><br>```js<br>const m = client.helpers.msearch({<br> retries: 3<br>})<br>```<br> |
| `wait` | How much time to wait before retries in milliseconds.<br> *Default:* 5000.<br><br>```js<br>const m = client.helpers.msearch({<br> wait: 3000<br>})<br>```<br> |


### Stopping the msearch helper [_stopping_the_msearch_helper]

If needed, you can stop an msearch processor at any time. The msearch helper returns a [thenable](https://promisesaplus.com/), which has an `stop` method.
Expand All @@ -291,7 +275,6 @@ The `stop` method accepts an optional error, that will be dispatched every subse
The stop method stops the execution of the msearch processor, but if you are using a concurrency higher than one, the operations that are already running will not be stopped.
::::


```js
const { Client } = require('@elastic/elasticsearch')

Expand All @@ -318,7 +301,6 @@ m.search(
setImmediate(() => m.stop())
```


## Search helper [search-helper]

Added in `v7.7.0`
Expand All @@ -340,7 +322,6 @@ for (const doc of documents) {
}
```


## Scroll search helper [scroll-search-helper]

Added in `v7.7.0`
Expand All @@ -362,7 +343,6 @@ for await (const result of scrollSearch) {
}
```


### Clear a scroll search [_clear_a_scroll_search]

If needed, you can clear a scroll search by calling `result.clear()`:
Expand All @@ -375,7 +355,6 @@ for await (const result of scrollSearch) {
}
```


### Quickly getting the documents [_quickly_getting_the_documents]

If you only need the documents from the result of a scroll search, you can access them via `result.documents`:
Expand All @@ -386,7 +365,6 @@ for await (const result of scrollSearch) {
}
```


## Scroll documents helper [scroll-documents-helper]

Added in `v7.7.0`
Expand All @@ -408,15 +386,12 @@ for await (const doc of scrollSearch) {
}
```


## ES|QL helper [esql-helper]

ES|QL queries can return their results in [several formats](docs-content://explore-analyze/query-filter/languages/esql-rest.md#esql-rest-format). The default JSON format returned by ES|QL queries contains arrays of values for each row, with column names and types returned separately:


### Usage [_usage_5]


#### `toRecords` [_torecords]

Added in `v8.14.0`
Expand Down Expand Up @@ -494,7 +469,6 @@ const result = await client.helpers
.toRecords<EventLog>()
```


#### `toArrowReader` [_toarrowreader]

Added in `v8.16.0`
Expand All @@ -516,7 +490,6 @@ for (const recordBatch of reader) {
}
```


#### `toArrowTable` [_toarrowtable]

Added in `v8.16.0`
Expand Down
15 changes: 5 additions & 10 deletions docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ mapped_pages:

The client is designed to be easily configured for your needs. In the following section, you can see the possible options that you can use to configure it.

* [Basic configuration](/reference/basic-config.md)
* [Advanced configuration](/reference/advanced-config.md)
* [Timeout best practices](docs-content://troubleshoot/elasticsearch/elasticsearch-client-javascript-api/nodejs.md)
* [Creating a child client](/reference/child.md)
* [Testing](/reference/client-testing.md)





- [Basic configuration](/reference/basic-config.md)
- [Advanced configuration](/reference/advanced-config.md)
- [Timeout best practices](docs-content://troubleshoot/elasticsearch/elasticsearch-client-javascript-api/nodejs.md)
- [Creating a child client](/reference/child.md)
- [Testing](/reference/client-testing.md)
Loading