Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 833c248a62 | |||
| c3efb90d39 | |||
| 521e0a3781 | |||
| 85459370bc | |||
| e68dec802a | |||
| 8d6ecbb636 | |||
| 42565240a9 | |||
| d6b9c2a844 | |||
| 40c4d98451 | |||
| 40fb4ef345 | |||
| 7c0b95da33 | |||
| b7b94e2dec | |||
| 63d4e139b3 | |||
| a42abc8f12 | |||
| 4745ee77ca | |||
| d228a2f68b | |||
| 5086a19512 | |||
| 221f9a9798 |
@ -1,13 +1,13 @@
|
||||
---
|
||||
- job:
|
||||
name: elastic+elasticsearch-js+7.15
|
||||
display-name: 'elastic / elasticsearch-js # 7.15'
|
||||
description: Testing the elasticsearch-js 7.15 branch.
|
||||
name: elastic+elasticsearch-js+7.17
|
||||
display-name: 'elastic / elasticsearch-js # 7.17'
|
||||
description: Testing the elasticsearch-js 7.17 branch.
|
||||
junit_results: "*-junit.xml"
|
||||
parameters:
|
||||
- string:
|
||||
name: branch_specifier
|
||||
default: refs/heads/7.15
|
||||
default: refs/heads/7.17
|
||||
description: the Git branch specifier to build (<branchName>, <tagName>,
|
||||
<commitId>, etc.)
|
||||
triggers:
|
||||
15
.ci/jobs/elastic+elasticsearch-js+8.0.yml
Normal file
15
.ci/jobs/elastic+elasticsearch-js+8.0.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
- job:
|
||||
name: elastic+elasticsearch-js+8.0
|
||||
display-name: 'elastic / elasticsearch-js # 8.0'
|
||||
description: Testing the elasticsearch-js 8.0 branch.
|
||||
junit_results: "*-junit.xml"
|
||||
parameters:
|
||||
- string:
|
||||
name: branch_specifier
|
||||
default: refs/heads/8.0
|
||||
description: the Git branch specifier to build (<branchName>, <tagName>,
|
||||
<commitId>, etc.)
|
||||
triggers:
|
||||
- github
|
||||
- timed: 'H */12 * * *'
|
||||
15
.ci/jobs/elastic+elasticsearch-js+8.1.yml
Normal file
15
.ci/jobs/elastic+elasticsearch-js+8.1.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
- job:
|
||||
name: elastic+elasticsearch-js+8.1
|
||||
display-name: 'elastic / elasticsearch-js # 8.1'
|
||||
description: Testing the elasticsearch-js 8.1 branch.
|
||||
junit_results: "*-junit.xml"
|
||||
parameters:
|
||||
- string:
|
||||
name: branch_specifier
|
||||
default: refs/heads/8.1
|
||||
description: the Git branch specifier to build (<branchName>, <tagName>,
|
||||
<commitId>, etc.)
|
||||
triggers:
|
||||
- github
|
||||
- timed: 'H */12 * * *'
|
||||
@ -2,10 +2,9 @@
|
||||
|
||||
source /usr/local/bin/bash_standard_lib.sh
|
||||
|
||||
DOCKER_IMAGES="node:14-alpine
|
||||
DOCKER_IMAGES="node:16-alpine
|
||||
node:14-alpine
|
||||
node:12-alpine
|
||||
node:10-alpine
|
||||
node:8-alpine
|
||||
"
|
||||
|
||||
for di in ${DOCKER_IMAGES}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
# Export the TEST_SUITE variable, eg. 'free' or 'platinum' defaults to 'free'.
|
||||
# Export the NUMBER_OF_NODES variable to start more than 1 node
|
||||
|
||||
# Version 1.5.0
|
||||
# Version 1.6.1
|
||||
# - Initial version of the run-elasticsearch.sh script
|
||||
# - Deleting the volume should not dependent on the container still running
|
||||
# - Fixed `ES_JAVA_OPTS` config
|
||||
@ -18,7 +18,9 @@
|
||||
# - Added flags to make local CCR configurations work
|
||||
# - Added action.destructive_requires_name=false as the default will be true in v8
|
||||
# - Added ingest.geoip.downloader.enabled=false as it causes false positives in testing
|
||||
# - Moved ELASTIC_PASSWORD to the base arguments for "Security On by default"
|
||||
# - Moved ELASTIC_PASSWORD and xpack.security.enabled to the base arguments for "Security On by default"
|
||||
# - Use https only when TEST_SUITE is "platinum", when "free" use http
|
||||
# - Set xpack.security.enabled=false for "free" and xpack.security.enabled=true for "platinum"
|
||||
|
||||
script_path=$(dirname $(realpath -s $0))
|
||||
source $script_path/functions/imports.sh
|
||||
@ -44,12 +46,13 @@ environment=($(cat <<-END
|
||||
--env repositories.url.allowed_urls=http://snapshot.test*
|
||||
--env action.destructive_requires_name=false
|
||||
--env ingest.geoip.downloader.enabled=false
|
||||
--env cluster.deprecation_indexing.enabled=false
|
||||
END
|
||||
))
|
||||
if [[ "$TEST_SUITE" == "platinum" ]]; then
|
||||
environment+=($(cat <<-END
|
||||
--env xpack.license.self_generated.type=trial
|
||||
--env xpack.security.enabled=true
|
||||
--env xpack.license.self_generated.type=trial
|
||||
--env xpack.security.http.ssl.enabled=true
|
||||
--env xpack.security.http.ssl.verification_mode=certificate
|
||||
--env xpack.security.http.ssl.key=certs/testnode.key
|
||||
@ -68,6 +71,12 @@ END
|
||||
--volume $ssl_ca:/usr/share/elasticsearch/config/certs/ca.crt
|
||||
END
|
||||
))
|
||||
else
|
||||
environment+=($(cat <<-END
|
||||
--env xpack.security.enabled=false
|
||||
--env xpack.security.http.ssl.enabled=false
|
||||
END
|
||||
))
|
||||
fi
|
||||
|
||||
cert_validation_flags=""
|
||||
|
||||
90
README.md
90
README.md
@ -51,6 +51,7 @@ of `^7.10.0`).
|
||||
| --------------- |------------------| ---------------------- |
|
||||
| `8.x` | `December 2019` | `7.11` (early 2021) |
|
||||
| `10.x` | `April 2021` | `7.12` (mid 2021) |
|
||||
| `12.x` | `April 2022` | `8.2` (early 2022) |
|
||||
|
||||
### Compatibility
|
||||
|
||||
@ -59,7 +60,7 @@ Elasticsearch language clients are only backwards compatible with default distri
|
||||
|
||||
| Elasticsearch Version | Client Version |
|
||||
| --------------------- |----------------|
|
||||
| `master` | `master` |
|
||||
| `8.x` | `8.x` |
|
||||
| `7.x` | `7.x` |
|
||||
| `6.x` | `6.x` |
|
||||
| `5.x` | `5.x` |
|
||||
@ -80,11 +81,9 @@ We recommend that you write a lightweight proxy that uses this client instead, y
|
||||
- [Usage](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#client-usage)
|
||||
- [Client configuration](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-configuration.html)
|
||||
- [API reference](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html)
|
||||
- [Breaking changes coming from the old client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/breaking-changes.html)
|
||||
- [Authentication](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#authentication)
|
||||
- [Observability](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/observability.html)
|
||||
- [Creating a child client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/child.html)
|
||||
- [Extend the client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/extend.html)
|
||||
- [Client helpers](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-helpers.html)
|
||||
- [Typescript support](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/typescript.html)
|
||||
- [Testing](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-testing.html)
|
||||
@ -92,60 +91,20 @@ We recommend that you write a lightweight proxy that uses this client instead, y
|
||||
|
||||
## Quick start
|
||||
|
||||
First of all, require the client and initialize it:
|
||||
```js
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
```
|
||||
|
||||
You can use both the callback-style API and the promise-style API, both behave the same way.
|
||||
```js
|
||||
// promise API
|
||||
const result = await client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// callback API
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
```
|
||||
The returned value of **every** API call is formed as follows:
|
||||
```ts
|
||||
{
|
||||
body: object | boolean
|
||||
statusCode: number
|
||||
headers: object
|
||||
warnings: [string]
|
||||
meta: object
|
||||
}
|
||||
```
|
||||
|
||||
Let's see a complete example!
|
||||
```js
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
// Let's start by indexing some data
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
|
||||
body: {
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.'
|
||||
}
|
||||
@ -153,8 +112,7 @@ async function run () {
|
||||
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
|
||||
body: {
|
||||
document: {
|
||||
character: 'Daenerys Targaryen',
|
||||
quote: 'I am the blood of the dragon.'
|
||||
}
|
||||
@ -162,8 +120,7 @@ async function run () {
|
||||
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
|
||||
body: {
|
||||
document: {
|
||||
character: 'Tyrion Lannister',
|
||||
quote: 'A mind needs books like a sword needs a whetstone.'
|
||||
}
|
||||
@ -174,17 +131,14 @@ async function run () {
|
||||
await client.indices.refresh({ index: 'game-of-thrones' })
|
||||
|
||||
// Let's search!
|
||||
const { body } = await client.search({
|
||||
const result= await client.search({
|
||||
index: 'game-of-thrones',
|
||||
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
|
||||
body: {
|
||||
query: {
|
||||
match: { quote: 'winter' }
|
||||
}
|
||||
query: {
|
||||
match: { quote: 'winter' }
|
||||
}
|
||||
})
|
||||
|
||||
console.log(body.hits.hits)
|
||||
console.log(result.hits.hits)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
@ -214,16 +168,22 @@ You will require the packages from your code by using the alias you have defined
|
||||
const { Client: Client6 } = require('es6')
|
||||
const { Client: Client7 } = require('es7')
|
||||
|
||||
const client6 = new Client6({ node: 'http://localhost:9200' })
|
||||
const client7 = new Client7({ node: 'http://localhost:9201' })
|
||||
const client6 = new Client6({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
const client7 = new Client7({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
client6.info(console.log)
|
||||
client7.info(console.log)
|
||||
client6.info().then(console.log, console.log)
|
||||
client7.info().then(console.log, console.log)
|
||||
```
|
||||
|
||||
Finally, if you want to install the client for the next version of Elasticsearch *(the one that lives in Elasticsearch’s master branch)*, you can use the following command:
|
||||
Finally, if you want to install the client for the next version of Elasticsearch *(the one that lives in Elasticsearch’s main branch)*, you can use the following command:
|
||||
```sh
|
||||
npm install esmaster@github:elastic/elasticsearch-js
|
||||
npm install esmain@github:elastic/elasticsearch-js
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
@ -30,7 +30,9 @@ class MyConnectionPool extends ConnectionPool {
|
||||
}
|
||||
|
||||
const client = new Client({
|
||||
ConnectionPool: MyConnectionPool
|
||||
ConnectionPool: MyConnectionPool,
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
----
|
||||
|
||||
@ -45,16 +47,18 @@ is performed here, this means that if you want to swap the default HTTP client
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client, Connection } = require('@elastic/elasticsearch')
|
||||
const { Client, BaseConnection } = require('@elastic/elasticsearch')
|
||||
|
||||
class MyConnection extends Connection {
|
||||
class MyConnection extends BaseConnection {
|
||||
request (params, callback) {
|
||||
// your code
|
||||
}
|
||||
}
|
||||
|
||||
const client = new Client({
|
||||
Connection: MyConnection
|
||||
Connection: MyConnection,
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
----
|
||||
|
||||
@ -81,7 +85,9 @@ class MySerializer extends Serializer {
|
||||
}
|
||||
|
||||
const client = new Client({
|
||||
Serializer: MySerializer
|
||||
Serializer: MySerializer,
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
----
|
||||
|
||||
|
||||
@ -10,7 +10,8 @@ offers.
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
maxRetries: 5,
|
||||
requestTimeout: 60000,
|
||||
sniffOnStart: true
|
||||
@ -32,7 +33,7 @@ Or it can be an object (or an array of objects) that represents the node:
|
||||
----
|
||||
node: {
|
||||
url: new URL('http://localhost:9200'),
|
||||
ssl: 'ssl options',
|
||||
tls: 'tls options',
|
||||
agent: 'http agent options',
|
||||
id: 'custom node id',
|
||||
headers: { 'custom': 'headers' }
|
||||
@ -48,8 +49,7 @@ node: {
|
||||
|`auth`
|
||||
a|Your authentication data. You can use both basic authentication and
|
||||
{ref}/security-api-create-api-key.html[ApiKey]. +
|
||||
See https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/auth-reference.html[Authentication]
|
||||
for more details. +
|
||||
See <<authentication,Authentication>> for more details. +
|
||||
_Default:_ `null`
|
||||
|
||||
Basic authentication:
|
||||
@ -118,8 +118,8 @@ _Default:_ `false`
|
||||
_Options:_ `'gzip'`, `false` +
|
||||
_Default:_ `false`
|
||||
|
||||
|`ssl`
|
||||
|`http.SecureContextOptions` - ssl https://nodejs.org/api/tls.html[configuraton]. +
|
||||
|`tls`
|
||||
|`http.SecureContextOptions` - tls https://nodejs.org/api/tls.html[configuraton]. +
|
||||
_Default:_ `null`
|
||||
|
||||
|`proxy`
|
||||
@ -242,7 +242,7 @@ _Cloud configuration example:_
|
||||
----
|
||||
const client = new Client({
|
||||
cloud: {
|
||||
id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA=='
|
||||
id: '<cloud-id>'
|
||||
},
|
||||
auth: {
|
||||
username: 'elastic',
|
||||
@ -267,24 +267,4 @@ _Default:_ `null`
|
||||
|`number` - When configured, it verifies that the compressed response size is lower than the configured number, if it's higher it will abort the request. It cannot be higher than buffer.constants.MAX_LENTGH +
|
||||
_Default:_ `null`
|
||||
|
||||
|===
|
||||
|
||||
[discrete]
|
||||
==== Performances considerations
|
||||
|
||||
By default, the client will protection you against prototype poisoning attacks.
|
||||
Read https://web.archive.org/web/20200319091159/https://hueniverse.com/square-brackets-are-the-enemy-ff5b9fd8a3e8?gi=184a27ee2a08[this article] to learn more.
|
||||
If needed you can disable prototype poisoning protection entirely or one of the two checks.
|
||||
Read the `secure-json-parse` https://github.com/fastify/secure-json-parse[documentation] to learn more.
|
||||
|
||||
While it's good to be safe, you should know that security always comes with a cost.
|
||||
With big enough payloads, this security check could causea drop in the overall performances,
|
||||
which might be a problem for your application.
|
||||
If you know you can trust the data stored in Elasticsearch, you can safely disable this check.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const client = new Client({
|
||||
disablePrototypePoisoningProtection: true
|
||||
})
|
||||
----
|
||||
|===
|
||||
@ -1,334 +0,0 @@
|
||||
[[breaking-changes]]
|
||||
=== Breaking changes coming from the old client
|
||||
|
||||
If you were already using the previous version of this client – the one you used
|
||||
to install with `npm install elasticsearch` – you will encounter some breaking
|
||||
changes.
|
||||
|
||||
|
||||
[discrete]
|
||||
==== Don’t panic!
|
||||
|
||||
Every breaking change was carefully weighed, and each is justified. Furthermore,
|
||||
the new codebase has been rewritten with modern JavaScript and has been
|
||||
carefully designed to be easy to maintain.
|
||||
|
||||
|
||||
[discrete]
|
||||
==== Breaking changes
|
||||
|
||||
* Minimum supported version of Node.js is `v8`.
|
||||
|
||||
* Everything has been rewritten using ES6 classes to help users extend the
|
||||
defaults more easily.
|
||||
|
||||
* There is no longer an integrated logger. The client now is an event emitter
|
||||
that emits the following events: `request`, `response`, and `error`.
|
||||
|
||||
* The code is no longer shipped with all the versions of the API, but only that
|
||||
of the package’s major version. This means that if you are using {es} `v6`, you
|
||||
are required to install `@elastic/elasticsearch@6`, and so on.
|
||||
|
||||
* The internals are completely different, so if you used to tweak them a lot,
|
||||
you will need to refactor your code. The public API should be almost the same.
|
||||
|
||||
* There is no longer browser support, for that will be distributed via another
|
||||
module: `@elastic/elasticsearch-browser`. This module is intended for Node.js
|
||||
only.
|
||||
|
||||
* The returned value of an API call will no longer be the `body`, `statusCode`,
|
||||
and `headers` for callbacks, and only the `body` for promises. The new returned
|
||||
value will be a unique object containing the `body`, `statusCode`, `headers`,
|
||||
`warnings`, and `meta`, for both callback and promises.
|
||||
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// before
|
||||
const body = await client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
})
|
||||
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
}, (err, body, statusCode, headers) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
|
||||
// after
|
||||
const { body, statusCode, headers, warnings } = await client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
})
|
||||
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
}, (err, { body, statusCode, headers, warnings }) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
----
|
||||
|
||||
|
||||
* Errors: there is no longer a custom error class for every HTTP status code
|
||||
(such as `BadRequest` or `NotFound`). There is instead a single `ResponseError`.
|
||||
Every error class has been renamed, and now each is suffixed with `Error` at the
|
||||
end.
|
||||
|
||||
* Removed errors: `RequestTypeError`, `Generic`, and all the status code
|
||||
specific errors (such as `BadRequest` or `NotFound`).
|
||||
|
||||
* Added errors: `ConfigurationError` (in case of bad configurations) and
|
||||
`ResponseError` that contains all the data you may need to handle the specific
|
||||
error, such as `statusCode`, `headers`, `body`, and `message`.
|
||||
|
||||
|
||||
* Renamed errors:
|
||||
|
||||
** `RequestTimeout` (408 statusCode) => `TimeoutError`
|
||||
** `ConnectionFault` => `ConnectionError`
|
||||
** `NoConnections` => `NoLivingConnectionsError`
|
||||
** `Serialization` => `SerializationError`
|
||||
** `Serialization` => `DeserializationError`
|
||||
|
||||
* You must specify the port number in the configuration. In the previous
|
||||
version, you can specify the host and port in a variety of ways. With the new
|
||||
client, there is only one way to do it, via the `node` parameter.
|
||||
|
||||
* Certificates are verified by default, if you want to disable certificates verification, you should set the `rejectUnauthorized` option to `false` inside the `ssl` configuration:
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
ssl: { rejectUnauthorized: false }
|
||||
})
|
||||
----
|
||||
|
||||
* The `plugins` option has been removed. If you want to extend the client now,
|
||||
you should use the `client.extend` API.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// before
|
||||
const { Client } = require('elasticsearch')
|
||||
const client = new Client({ plugins: [...] })
|
||||
|
||||
// after
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ ... })
|
||||
client.extend(...)
|
||||
----
|
||||
|
||||
* There is a clear distinction between the API related parameters and the client
|
||||
related configurations. The parameters `ignore`, `headers`, `requestTimeout` and
|
||||
`maxRetries` are no longer part of the API object and you need to specify them
|
||||
in a second option object.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// before
|
||||
const body = await client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' },
|
||||
ignore: [404]
|
||||
})
|
||||
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' },
|
||||
ignore: [404]
|
||||
}, (err, body, statusCode, headers) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
|
||||
// after
|
||||
const { body, statusCode, headers, warnings } = await client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
}, {
|
||||
ignore: [404]
|
||||
})
|
||||
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
}, {
|
||||
ignore: [404]
|
||||
}, (err, { body, statusCode, headers, warnings }) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
----
|
||||
|
||||
* The `transport.request` method no longer accepts the `query` key. Use the
|
||||
`querystring` key instead (which can be a string or an object). You also
|
||||
need to send a bulk-like request instead of the `body` key, use the `bulkBody`
|
||||
key. In this method, the client specific parameters should be passed as a second
|
||||
object.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// before
|
||||
const body = await client.transport.request({
|
||||
method: 'GET',
|
||||
path: '/my-index/_search',
|
||||
body: { foo: 'bar' },
|
||||
query: { bar: 'baz' }
|
||||
ignore: [404]
|
||||
})
|
||||
|
||||
client.transport.request({
|
||||
method: 'GET',
|
||||
path: '/my-index/_search',
|
||||
body: { foo: 'bar' },
|
||||
query: { bar: 'baz' }
|
||||
ignore: [404]
|
||||
}, (err, body, statusCode, headers) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
|
||||
// after
|
||||
const { body, statusCode, headers, warnings } = await client.transport.request({
|
||||
method: 'GET',
|
||||
path: '/my-index/_search',
|
||||
body: { foo: 'bar' },
|
||||
querystring: { bar: 'baz' }
|
||||
}, {
|
||||
ignore: [404]
|
||||
})
|
||||
|
||||
client.transport.request({
|
||||
method: 'GET',
|
||||
path: '/my-index/_search',
|
||||
body: { foo: 'bar' },
|
||||
querystring: { bar: 'baz' }
|
||||
}, {
|
||||
ignore: [404]
|
||||
}, (err, { body, statusCode, headers, warnings }) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
----
|
||||
|
||||
[discrete]
|
||||
==== Talk is cheap. Show me the code.
|
||||
|
||||
You can find a code snippet with the old client below followed by the same code
|
||||
logic but with the new client.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client, errors } = require('elasticsearch')
|
||||
const client = new Client({
|
||||
host: 'http://localhost:9200',
|
||||
plugins: [utility]
|
||||
})
|
||||
|
||||
async function run () {
|
||||
try {
|
||||
const body = await client.search({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
query: {
|
||||
match: { quote: 'winter' }
|
||||
}
|
||||
}
|
||||
ignore: [404]
|
||||
})
|
||||
console.log(body)
|
||||
} catch (err) {
|
||||
if (err instanceof errors.BadRequest) {
|
||||
console.log('Bad request')
|
||||
} else {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function utility (Client, config, components) {
|
||||
const ca = components.clientAction.factory
|
||||
Client.prototype.utility = components.clientAction.namespaceFactory()
|
||||
const utility = Client.prototype.utility.prototype
|
||||
|
||||
utility.index = ca({
|
||||
params: {
|
||||
refresh: {
|
||||
type: 'enum',
|
||||
options: [
|
||||
'true',
|
||||
'false',
|
||||
'wait_for',
|
||||
''
|
||||
]
|
||||
},
|
||||
},
|
||||
urls: [
|
||||
{
|
||||
fmt: '/<%=index%>/_doc',
|
||||
req: {
|
||||
index: {
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
needBody: true,
|
||||
method: 'POST'
|
||||
})
|
||||
})
|
||||
----
|
||||
|
||||
And now with the new client.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client, errors } = require('@elastic/elasticsearch')
|
||||
// NOTE: `host` has been renamed to `node`,
|
||||
// and `plugins` is no longer supported
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
|
||||
async function run () {
|
||||
try {
|
||||
// NOTE: we are using the destructuring assignment
|
||||
const { body } = await client.search({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
query: {
|
||||
match: { quote: 'winter' }
|
||||
}
|
||||
}
|
||||
// NOTE: `ignore` now is in a separated object
|
||||
}, {
|
||||
ignore: [404]
|
||||
})
|
||||
console.log(body)
|
||||
} catch (err) {
|
||||
// NOTE: we are checking the `statusCode` property
|
||||
if (err.statusCode === 400) {
|
||||
console.log('Bad request')
|
||||
} else {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: we can still extend the client, but with a different API.
|
||||
// This new API is a little bit more verbose, since you must write
|
||||
// your own validations, but it's way more flexible.
|
||||
client.extend('utility.index', ({ makeRequest, ConfigurationError }) => {
|
||||
return function utilityIndex (params, options) {
|
||||
const { body, index, ...querystring } = params
|
||||
if (body == null) throw new ConfigurationError('Missing body')
|
||||
if (index == null) throw new ConfigurationError('Missing index')
|
||||
const requestParams = {
|
||||
method: 'POST',
|
||||
path: `/${index}/_doc`,
|
||||
body: body,
|
||||
querystring
|
||||
}
|
||||
return makeRequest(requestParams, options)
|
||||
}
|
||||
})
|
||||
----
|
||||
326
docs/changelog.asciidoc
Normal file
326
docs/changelog.asciidoc
Normal file
@ -0,0 +1,326 @@
|
||||
[[changelog-client]]
|
||||
== Release notes
|
||||
|
||||
[discrete]
|
||||
=== 8.0.0
|
||||
|
||||
[discrete]
|
||||
==== Features
|
||||
|
||||
[discrete]
|
||||
[discrete]
|
||||
===== Support for Elasticsearch `v8.0`
|
||||
|
||||
You can find all the API changes
|
||||
https://www.elastic.co/guide/en/elasticsearch/reference/8.0/release-notes-8.0.0.html[here].
|
||||
|
||||
[discrete]
|
||||
===== Drop old typescript definitions
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Medium*
|
||||
|
||||
The current TypeScript definitions will be removed from the client, and the new definitions, which contain request and response definitions as well will be shipped by default.
|
||||
|
||||
[discrete]
|
||||
===== Drop callback-style API
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Large*
|
||||
|
||||
Maintaining both API styles is not a problem per se, but it makes error handling more convoluted due to async stack traces.
|
||||
Moving to a full-promise API will solve this issue.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// callback-style api
|
||||
client.search({ params }, { options }, (err, result) => {
|
||||
console.log(err || result)
|
||||
})
|
||||
|
||||
// promise-style api
|
||||
client.search({ params }, { options })
|
||||
.then(console.log)
|
||||
.catch(console.log)
|
||||
|
||||
// async-style (sugar syntax on top of promises)
|
||||
const response = await client.search({ params }, { options })
|
||||
console.log(response)
|
||||
----
|
||||
|
||||
If you are already using the promise-style API, this won't be a breaking change for you.
|
||||
|
||||
[discrete]
|
||||
===== Remove the current abort API and use the new AbortController standard
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Small*
|
||||
|
||||
The old abort API makes sense for callbacks but it's annoying to use with promises
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// callback-style api
|
||||
const request = client.search({ params }, { options }, (err, result) => {
|
||||
console.log(err) // RequestAbortedError
|
||||
})
|
||||
|
||||
request.abort()
|
||||
|
||||
// promise-style api
|
||||
const promise = client.search({ params }, { options })
|
||||
|
||||
promise
|
||||
.then(console.log)
|
||||
.catch(console.log) // RequestAbortedError
|
||||
|
||||
promise.abort()
|
||||
----
|
||||
|
||||
Node v12 has added the standard https://nodejs.org/api/globals.html#globals_class_abortcontroller[`AbortController`] API which is designed to work well with both callbacks and promises.
|
||||
[source,js]
|
||||
----
|
||||
const ac = new AbortController()
|
||||
client.search({ params }, { signal: ac.signal })
|
||||
.then(console.log)
|
||||
.catch(console.log) // RequestAbortedError
|
||||
|
||||
ac.abort()
|
||||
----
|
||||
|
||||
[discrete]
|
||||
===== Remove the body key from the request
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Small*
|
||||
|
||||
Thanks to the new types we are developing now we know exactly where a parameter should go.
|
||||
The client API leaks HTTP-related notions in many places, and removing them would definitely improve the DX.
|
||||
|
||||
This could be a rather big breaking change, so a double solution could be used during the 8.x lifecycle. (accepting body keys without them being wrapped in the body as well as the current solution).
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// from
|
||||
const response = await client.search({
|
||||
index: 'test',
|
||||
body: {
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// to
|
||||
const response = await client.search({
|
||||
index: 'test',
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
})
|
||||
----
|
||||
|
||||
[discrete]
|
||||
===== Migrate to new separate transport
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Small to none*
|
||||
|
||||
The separated transport has been rewritten in TypeScript and has already dropped the callback style API.
|
||||
Given that now is separated, most of the Elasticsearch specific concepts have been removed, and the client will likely need to extend parts of it for reintroducing them.
|
||||
If you weren't extending the internals of the client, this won't be a breaking change for you.
|
||||
|
||||
[discrete]
|
||||
===== The returned value of API calls is the body and not the HTTP related keys
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Small*
|
||||
|
||||
The client API leaks HTTP-related notions in many places, and removing them would definitely improve the DX.
|
||||
The client will expose a new request-specific option to still get the full response details.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// from
|
||||
const response = await client.search({
|
||||
index: 'test',
|
||||
body: {
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
}
|
||||
})
|
||||
console.log(response) // { body: SearchResponse, statusCode: number, headers: object, warnings: array }
|
||||
|
||||
// to
|
||||
const response = await client.search({
|
||||
index: 'test',
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
})
|
||||
console.log(response) // SearchResponse
|
||||
|
||||
// with a bit of TypeScript and JavaScript magic...
|
||||
const response = await client.search({
|
||||
index: 'test',
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
}, {
|
||||
meta: true
|
||||
})
|
||||
console.log(response) // { body: SearchResponse, statusCode: number, headers: object, warnings: array }
|
||||
----
|
||||
|
||||
[discrete]
|
||||
===== Use a weighted connection pool
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Small to none*
|
||||
|
||||
Move from the current cluster connection pool to a weight-based implementation.
|
||||
This new implementation offers better performances and runs less code in the background, the old connection pool can still be used.
|
||||
If you weren't extending the internals of the client, this won't be a breaking change for you.
|
||||
|
||||
[discrete]
|
||||
===== Migrate to the "undici" http client
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Small to none*
|
||||
|
||||
By default, the HTTP client will no longer be the default Node.js HTTP client, but https://github.com/nodejs/undici[undici] instead.
|
||||
Undici is a brand new HTTP client written from scratch, it offers vastly improved performances and has better support for promises.
|
||||
Furthermore, it offers comprehensive and predictable error handling. The old HTTP client can still be used.
|
||||
If you weren't extending the internals of the client, this won't be a breaking change for you.
|
||||
|
||||
[discrete]
|
||||
===== Drop support for old camelCased keys
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Medium*
|
||||
|
||||
Currently, every path or query parameter could be expressed in both `snake_case` and `camelCase`. Internally the client will convert everything to `snake_case`.
|
||||
This was done in an effort to reduce the friction of migrating from the legacy to the new client, but now it no longer makes sense.
|
||||
If you are already using `snake_case` keys, this won't be a breaking change for you.
|
||||
|
||||
[discrete]
|
||||
===== Rename `ssl` option to `tls`
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Small*
|
||||
|
||||
People usually refers to this as `tls`, furthermore, internally we use the tls API and Node.js refers to it as tls everywhere.
|
||||
[source,js]
|
||||
----
|
||||
// before
|
||||
const client = new Client({
|
||||
node: 'https://localhost:9200',
|
||||
ssl: {
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
})
|
||||
|
||||
// after
|
||||
const client = new Client({
|
||||
node: 'https://localhost:9200',
|
||||
tls: {
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
})
|
||||
----
|
||||
|
||||
[discrete]
|
||||
===== Remove prototype poisoning protection
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Small*
|
||||
|
||||
Prototype poisoning protection is very useful, but it can cause performances issues with big payloads.
|
||||
In v8 it will be removed, and the documentation will show how to add it back with a custom serializer.
|
||||
|
||||
[discrete]
|
||||
===== Remove client extensions API
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Large*
|
||||
|
||||
Nowadays the client support the entire Elasticsearch API, and the `transport.request` method can be used if necessary. The client extensions API have no reason to exist.
|
||||
[source,js]
|
||||
----
|
||||
client.extend('utility.index', ({ makeRequest }) => {
|
||||
return function _index (params, options) {
|
||||
// your code
|
||||
}
|
||||
})
|
||||
|
||||
client.utility.index(...)
|
||||
----
|
||||
|
||||
If you weren't using client extensions, this won't be a breaking change for you.
|
||||
|
||||
[discrete]
|
||||
===== Move to TypeScript
|
||||
|
||||
*Breaking: No* | *Migration effort: None*
|
||||
|
||||
The new separated transport is already written in TypeScript, and it makes sense that the client v8 will be fully written in TypeScript as well.
|
||||
|
||||
[discrete]
|
||||
===== Move from emitter-like interface to a diagnostic method
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Small*
|
||||
|
||||
Currently, the client offers a subset of methods of the `EventEmitter` class, v8 will ship with a `diagnostic` property which will be a proper event emitter.
|
||||
[source,js]
|
||||
----
|
||||
// from
|
||||
client.on('request', console.log)
|
||||
|
||||
// to
|
||||
client.diagnostic.on('request', console.log)
|
||||
----
|
||||
|
||||
[discrete]
|
||||
===== Remove username & password properties from Cloud configuration
|
||||
|
||||
*Breaking: Yes* | *Migration effort: Small*
|
||||
|
||||
The Cloud configuration does not support ApiKey and Bearer auth, while the `auth` options does.
|
||||
There is no need to keep the legacy basic auth support in the cloud configuration.
|
||||
[source,js]
|
||||
----
|
||||
// before
|
||||
const client = new Client({
|
||||
cloud: {
|
||||
id: '<cloud-id>',
|
||||
username: 'elastic',
|
||||
password: 'changeme'
|
||||
}
|
||||
})
|
||||
|
||||
// after
|
||||
const client = new Client({
|
||||
cloud: {
|
||||
id: '<cloud-id>'
|
||||
},
|
||||
auth: {
|
||||
username: 'elastic',
|
||||
password: 'changeme'
|
||||
}
|
||||
})
|
||||
----
|
||||
|
||||
If you are already passing the basic auth options in the `auth` configuration, this won't be a breaking change for you.
|
||||
|
||||
[discrete]
|
||||
===== Calling `client.close` will reject new requests
|
||||
|
||||
Once you call `client.close` every new request after that will be rejected with a `NoLivingConnectionsError`. In-flight requests will be executed normally unless an in-flight request requires a retry, in which case it will be rejected.
|
||||
|
||||
[discrete]
|
||||
===== Parameters rename
|
||||
|
||||
- `ilm.delete_lifecycle`: `policy` parameter has been renamed to `name`
|
||||
- `ilm.get_lifecycle`: `policy` parameter has been renamed to `name`
|
||||
- `ilm.put_lifecycle`: `policy` parameter has been renamed to `name`
|
||||
- `snapshot.cleanup_repository`: `repository` parameter has been renamed to `name`
|
||||
- `snapshot.create_repository`: `repository` parameter has been renamed to `name`
|
||||
- `snapshot.delete_repository`: `repository` parameter has been renamed to `name`
|
||||
- `snapshot.get_repository`: `repository` parameter has been renamed to `name`
|
||||
- `snapshot.verify_repository`: `repository` parameter has been renamed to `name`
|
||||
|
||||
[discrete]
|
||||
===== Removal of snake_cased methods
|
||||
|
||||
The v7 client provided snake_cased methods, such as `client.delete_by_query`. This is no longer supported, now only camelCased method are present.
|
||||
So `client.delete_by_query` can be accessed with `client.deleteByQuery`
|
||||
|
||||
@ -22,12 +22,15 @@ will be closed.
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
const child = client.child({
|
||||
headers: { 'x-foo': 'bar' },
|
||||
requestTimeout: 1000
|
||||
})
|
||||
|
||||
client.info(console.log)
|
||||
child.info(console.log)
|
||||
client.info().then(console.log, console.log)
|
||||
child.info().then(console.log, console.log)
|
||||
----
|
||||
@ -8,5 +8,4 @@ section, you can see the possible options that you can use to configure it.
|
||||
* <<basic-config>>
|
||||
* <<advanced-config>>
|
||||
* <<child>>
|
||||
* <<extend>>
|
||||
* <<client-testing>>
|
||||
|
||||
@ -6,14 +6,14 @@ This page contains the information you need to connect and use the Client with
|
||||
|
||||
**On this page**
|
||||
|
||||
* <<auth-reference, Authentication options>>
|
||||
* <<authentication, Authentication options>>
|
||||
* <<client-usage, Using the client>>
|
||||
* <<client-faas-env, Using the Client in a Function-as-a-Service Environment>>
|
||||
* <<client-connect-proxy, Connecting through a proxy>>
|
||||
* <<client-error-handling, Handling errors>>
|
||||
* <<product-check, Automatic product check>>
|
||||
|
||||
[[auth-reference]]
|
||||
[[authentication]]
|
||||
[discrete]
|
||||
=== Authentication
|
||||
|
||||
@ -32,7 +32,7 @@ the `auth` option.
|
||||
|
||||
NOTE: When connecting to Elastic Cloud, the client will automatically enable
|
||||
both request and response compression by default, since it yields significant
|
||||
throughput improvements. Moreover, the client will also set the ssl option
|
||||
throughput improvements. Moreover, the client will also set the tls option
|
||||
`secureProtocol` to `TLSv1_2_method` unless specified otherwise. You can still
|
||||
override this option by configuring them.
|
||||
|
||||
@ -46,7 +46,7 @@ to know more.
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
cloud: {
|
||||
id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
|
||||
id: '<cloud-id>'
|
||||
},
|
||||
auth: {
|
||||
username: 'elastic',
|
||||
@ -55,6 +55,152 @@ const client = new Client({
|
||||
})
|
||||
----
|
||||
|
||||
[discrete]
|
||||
[[connect-self-managed-new]]
|
||||
=== Connecting to a self-managed cluster
|
||||
|
||||
By default {es} will start with security features like authentication and TLS
|
||||
enabled. To connect to the {es} cluster you'll need to configure the Node.js {es}
|
||||
client to use HTTPS with the generated CA certificate in order to make requests
|
||||
successfully.
|
||||
|
||||
If you're just getting started with {es} we recommend reading the documentation
|
||||
on https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html[configuring]
|
||||
and
|
||||
https://www.elastic.co/guide/en/elasticsearch/reference/current/starting-elasticsearch.html[starting {es}]
|
||||
to ensure your cluster is running as expected.
|
||||
|
||||
When you start {es} for the first time you'll see a distinct block like the one
|
||||
below in the output from {es} (you may have to scroll up if it's been a while):
|
||||
|
||||
[source,sh]
|
||||
----
|
||||
|
||||
-> Elasticsearch security features have been automatically configured!
|
||||
-> Authentication is enabled and cluster connections are encrypted.
|
||||
|
||||
-> Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
|
||||
lhQpLELkjkrawaBoaz0Q
|
||||
|
||||
-> HTTP CA certificate SHA-256 fingerprint:
|
||||
a52dd93511e8c6045e21f16654b77c9ee0f34aea26d9f40320b531c474676228
|
||||
...
|
||||
|
||||
----
|
||||
|
||||
Depending on the circumstances there are two options for verifying the HTTPS
|
||||
connection, either verifying with the CA certificate itself or via the HTTP CA
|
||||
certificate fingerprint.
|
||||
|
||||
[discrete]
|
||||
[[auth-tls]]
|
||||
==== TLS configuration
|
||||
|
||||
The generated root CA certificate can be found in the `certs` directory in your
|
||||
{es} config location (`$ES_CONF_PATH/certs/http_ca.crt`). If you're running {es}
|
||||
in Docker there is
|
||||
https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html[additional documentation for retrieving the CA certificate].
|
||||
|
||||
Without any additional configuration you can specify `https://` node urls, and
|
||||
the certificates used to sign these requests will be verified. To turn off
|
||||
certificate verification, you must specify an `tls` object in the top level
|
||||
config and set `rejectUnauthorized: false`. The default `tls` values are the
|
||||
same that Node.js's https://nodejs.org/api/tls.html#tls_tls_connect_options_callback[`tls.connect()`]
|
||||
uses.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'https://localhost:9200',
|
||||
auth: {
|
||||
username: 'elastic',
|
||||
password: 'changeme'
|
||||
},
|
||||
tls: {
|
||||
ca: fs.readFileSync('./http_ca.crt'),
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
})
|
||||
----
|
||||
|
||||
[discrete]
|
||||
[[auth-ca-fingerprint]]
|
||||
==== CA fingerprint
|
||||
|
||||
You can configure the client to only trust certificates that are signed by a specific CA certificate
|
||||
(CA certificate pinning) by providing a `caFingerprint` option.
|
||||
This will verify that the fingerprint of the CA certificate that has signed
|
||||
the certificate of the server matches the supplied value.
|
||||
You must configure a SHA256 digest.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'https://example.com'
|
||||
auth: { ... },
|
||||
// the fingerprint (SHA256) of the CA certificate that is used to sign
|
||||
// the certificate that the Elasticsearch node presents for TLS.
|
||||
caFingerprint: '20:0D:CA:FA:76:...',
|
||||
tls: {
|
||||
// might be required if it's a self-signed certificate
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
})
|
||||
----
|
||||
|
||||
The certificate fingerprint can be calculated using `openssl x509` with the
|
||||
certificate file:
|
||||
|
||||
[source,sh]
|
||||
----
|
||||
openssl x509 -fingerprint -sha256 -noout -in /path/to/http_ca.crt
|
||||
----
|
||||
|
||||
If you don't have access to the generated CA file from {es} you can use the
|
||||
following script to output the root CA fingerprint of the {es} instance with
|
||||
`openssl s_client`:
|
||||
|
||||
[source,sh]
|
||||
----
|
||||
# Replace the values of 'localhost' and '9200' to the
|
||||
# corresponding host and port values for the cluster.
|
||||
openssl s_client -connect localhost:9200 -servername localhost -showcerts </dev/null 2>/dev/null \
|
||||
| openssl x509 -fingerprint -sha256 -noout -in /dev/stdin
|
||||
----
|
||||
|
||||
The output of `openssl x509` will look something like this:
|
||||
|
||||
[source,sh]
|
||||
----
|
||||
SHA256 Fingerprint=A5:2D:D9:35:11:E8:C6:04:5E:21:F1:66:54:B7:7C:9E:E0:F3:4A:EA:26:D9:F4:03:20:B5:31:C4:74:67:62:28
|
||||
----
|
||||
|
||||
|
||||
[discrete]
|
||||
[[connect-no-security]]
|
||||
=== Connecting without security enabled
|
||||
|
||||
WARNING: Running {es} without security enabled is not recommended.
|
||||
|
||||
If your cluster is configured with
|
||||
https://www.elastic.co/guide/en/elasticsearch/reference/current/security-settings.html[security explicitly disabled]
|
||||
then you can connect via HTTP:
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'http://example.com'
|
||||
})
|
||||
----
|
||||
|
||||
[discrete]
|
||||
[[auth-strategies]]
|
||||
=== Authentication strategies
|
||||
|
||||
Following you can find all the supported authentication strategies.
|
||||
|
||||
[discrete]
|
||||
[[auth-apikey]]
|
||||
@ -150,57 +296,6 @@ const client = new Client({
|
||||
----
|
||||
|
||||
|
||||
[discrete]
|
||||
[[auth-ssl]]
|
||||
==== SSL configuration
|
||||
|
||||
Without any additional configuration you can specify `https://` node urls, and
|
||||
the certificates used to sign these requests will be verified. To turn off
|
||||
certificate verification, you must specify an `ssl` object in the top level
|
||||
config and set `rejectUnauthorized: false`. The default `ssl` values are the
|
||||
same that Node.js's https://nodejs.org/api/tls.html#tls_tls_connect_options_callback[`tls.connect()`]
|
||||
uses.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'https://localhost:9200',
|
||||
auth: {
|
||||
username: 'elastic',
|
||||
password: 'changeme'
|
||||
},
|
||||
ssl: {
|
||||
ca: fs.readFileSync('./cacert.pem'),
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
})
|
||||
----
|
||||
|
||||
[discrete]
|
||||
[[auth-ca-fingerprint]]
|
||||
==== CA fingerprint
|
||||
|
||||
You can configure the client to only trust certificates that are signed by a specific CA certificate ( CA certificate pinning ) by providing a `caFingerprint` option. This will verify that the fingerprint of the CA certificate that has signed the certificate of the server matches the supplied value.
|
||||
a `caFingerprint` option, which will verify the supplied certificate authority fingerprint.
|
||||
You must configure a SHA256 digest.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'https://example.com'
|
||||
auth: { ... },
|
||||
// the fingerprint (SHA256) of the CA certificate that is used to sign the certificate that the Elasticsearch node presents for TLS.
|
||||
caFingerprint: '20:0D:CA:FA:76:...',
|
||||
ssl: {
|
||||
// might be required if it's a self-signed certificate
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
})
|
||||
----
|
||||
|
||||
|
||||
[discrete]
|
||||
[[client-usage]]
|
||||
=== Usage
|
||||
@ -212,33 +307,40 @@ and every method exposes the same signature.
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
|
||||
// promise API
|
||||
const result = await client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
// callback API
|
||||
client.search({
|
||||
const result = await client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
----
|
||||
|
||||
The returned value of every API call is designed as follows:
|
||||
The returned value of every API call is the response body from {es}.
|
||||
If you need to access additonal metadata, such as the status code or headers,
|
||||
you must specify `meta: true` in the request options:
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
const result = await client.search({
|
||||
index: 'my-index',
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}, { meta: true })
|
||||
----
|
||||
|
||||
In this case, the result will be:
|
||||
[source,ts]
|
||||
----
|
||||
{
|
||||
@ -252,44 +354,10 @@ The returned value of every API call is designed as follows:
|
||||
|
||||
NOTE: The body is a boolean value when you use `HEAD` APIs.
|
||||
|
||||
The above value is returned even if there is an error during the execution of
|
||||
the request, this means that you can safely use the
|
||||
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment[destructuring assignment].
|
||||
|
||||
The `meta` key contains all the information about the request, such as attempt,
|
||||
options, and the connection that has been used.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// promise API
|
||||
const { body } = await client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// callback API
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}
|
||||
}, (err, { body }) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
----
|
||||
|
||||
|
||||
[discrete]
|
||||
==== Aborting a request
|
||||
|
||||
If needed, you can abort a running request by calling the `request.abort()`
|
||||
method returned by the API.
|
||||
If needed, you can abort a running request by using the `AbortController` standard.
|
||||
|
||||
CAUTION: If you abort a request, the request will fail with a
|
||||
`RequestAbortedError`.
|
||||
@ -297,51 +365,24 @@ CAUTION: If you abort a request, the request will fail with a
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const request = client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}
|
||||
}, {
|
||||
ignore: [404],
|
||||
maxRetries: 3
|
||||
}, (err, result) => {
|
||||
if (err) {
|
||||
console.log(err) // RequestAbortedError
|
||||
} else {
|
||||
console.log(result)
|
||||
}
|
||||
const AbortController = require('node-abort-controller')
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
request.abort()
|
||||
----
|
||||
const abortController = new AbortController()
|
||||
setImmediate(() => abortController.abort())
|
||||
|
||||
The same behavior is valid for the promise style API as well.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const request = client.search({
|
||||
const result = await client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}, {
|
||||
ignore: [404],
|
||||
maxRetries: 3
|
||||
})
|
||||
|
||||
request
|
||||
.then(result => console.log(result))
|
||||
.catch(err => console.log(err)) // RequestAbortedError
|
||||
|
||||
request.abort()
|
||||
}, { signal: abortController.signal })
|
||||
----
|
||||
|
||||
|
||||
[discrete]
|
||||
==== Request specific options
|
||||
|
||||
@ -349,7 +390,6 @@ If needed you can pass request specific options in a second object:
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// promise API
|
||||
const result = await client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
@ -361,21 +401,6 @@ const result = await client.search({
|
||||
ignore: [404],
|
||||
maxRetries: 3
|
||||
})
|
||||
|
||||
// callback API
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}
|
||||
}, {
|
||||
ignore: [404],
|
||||
maxRetries: 3
|
||||
}, (err, { body }) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
----
|
||||
|
||||
|
||||
@ -427,6 +452,10 @@ _Default:_ `null`
|
||||
|`number` - When configured, it verifies that the compressed response size is lower than the configured number, if it's higher it will abort the request. It cannot be higher than buffer.constants.MAX_LENTGH +
|
||||
_Default:_ `null`
|
||||
|
||||
|`signal`
|
||||
|`AbortSignal` - The AbortSignal instance to allow request abortion. +
|
||||
_Default:_ `null`
|
||||
|
||||
|===
|
||||
|
||||
[discrete]
|
||||
|
||||
@ -9,12 +9,15 @@ data.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
const { body: bulkResponse } = await client.bulk({
|
||||
const bulkResponse = await client.bulk({
|
||||
refresh: true,
|
||||
body: [
|
||||
operations: [
|
||||
// operation to perform
|
||||
{ index: { _index: 'game-of-thrones' } },
|
||||
// the document to index
|
||||
@ -43,13 +46,11 @@ async function run () {
|
||||
}
|
||||
|
||||
// Let's search!
|
||||
const { body } = await client.search({
|
||||
const result = await client.search({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
query: {
|
||||
match: {
|
||||
quote: 'winter'
|
||||
}
|
||||
query: {
|
||||
match: {
|
||||
quote: 'winter'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -59,17 +60,17 @@ async function run () {
|
||||
// stream async iteration, available in Node.js ≥ 10
|
||||
let payload = ''
|
||||
body.setEncoding('utf8')
|
||||
for await (const chunk of body) {
|
||||
for await (const chunk of result) {
|
||||
payload += chunk
|
||||
}
|
||||
console.log(JSON.parse(payload))
|
||||
|
||||
// classic stream callback style
|
||||
let payload = ''
|
||||
body.setEncoding('utf8')
|
||||
body.on('data', chunk => { payload += chunk })
|
||||
body.on('error', console.log)
|
||||
body.on('end', () => {
|
||||
result.setEncoding('utf8')
|
||||
result.on('data', chunk => { payload += chunk })
|
||||
result.on('error', console.log)
|
||||
result.on('end', () => {
|
||||
console.log(JSON.parse(payload))
|
||||
})
|
||||
}
|
||||
@ -85,15 +86,19 @@ send it directly to another source.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
const fastify = require('fastify')()
|
||||
|
||||
fastify.post('/search/:index', async (req, reply) => {
|
||||
const { body, statusCode, headers } = await client.search({
|
||||
index: req.params.index,
|
||||
body: req.body
|
||||
...req.body
|
||||
}, {
|
||||
asStream: true
|
||||
asStream: true,
|
||||
meta: true
|
||||
})
|
||||
|
||||
reply.code(statusCode).headers(headers)
|
||||
|
||||
@ -13,13 +13,14 @@ NOTE: Did you know that we provide an helper for sending bulk request? You can f
|
||||
require('array.prototype.flatmap').shim()
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200'
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
await client.indices.create({
|
||||
index: 'tweets',
|
||||
body: {
|
||||
operations: {
|
||||
mappings: {
|
||||
properties: {
|
||||
id: { type: 'integer' },
|
||||
@ -58,9 +59,9 @@ async function run () {
|
||||
date: new Date()
|
||||
}]
|
||||
|
||||
const body = dataset.flatMap(doc => [{ index: { _index: 'tweets' } }, doc])
|
||||
const operations = dataset.flatMap(doc => [{ index: { _index: 'tweets' } }, doc])
|
||||
|
||||
const { body: bulkResponse } = await client.bulk({ refresh: true, body })
|
||||
const bulkResponse = await client.bulk({ refresh: true, operations })
|
||||
|
||||
if (bulkResponse.errors) {
|
||||
const erroredDocuments = []
|
||||
@ -84,7 +85,7 @@ async function run () {
|
||||
console.log(erroredDocuments)
|
||||
}
|
||||
|
||||
const { body: count } = await client.count({ index: 'tweets' })
|
||||
const count = await client.count({ index: 'tweets' })
|
||||
console.log(count)
|
||||
}
|
||||
|
||||
|
||||
@ -10,24 +10,27 @@ NOTE: Since this API uses the `HEAD` method, the body value will be boolean.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
id: '1',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.'
|
||||
}
|
||||
})
|
||||
|
||||
const { body } = await client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'game-of-thrones',
|
||||
id: 1
|
||||
})
|
||||
|
||||
console.log(body) // true
|
||||
console.log(exists) // true
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
|
||||
@ -10,24 +10,27 @@ The following example gets a JSON document from an index called
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
id: '1',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.'
|
||||
}
|
||||
})
|
||||
|
||||
const { body } = await client.get({
|
||||
const document = await client.get({
|
||||
index: 'game-of-thrones',
|
||||
id: '1'
|
||||
})
|
||||
|
||||
console.log(body)
|
||||
console.log(document)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
|
||||
@ -8,12 +8,15 @@ HTTP status codes which should not be considered errors for this request.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
const { body: bulkResponse } = await client.bulk({
|
||||
const bulkResponse = await client.bulk({
|
||||
refresh: true,
|
||||
body: [
|
||||
operations: [
|
||||
// operation to perform
|
||||
{ index: { _index: 'game-of-thrones' } },
|
||||
// the document to index
|
||||
@ -42,7 +45,7 @@ async function run () {
|
||||
}
|
||||
|
||||
// Let's search!
|
||||
const { body } = await client.search({
|
||||
const result = await client.search({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
query: {
|
||||
@ -55,7 +58,7 @@ async function run () {
|
||||
ignore: [404]
|
||||
})
|
||||
|
||||
console.log(body) // ResponseError
|
||||
console.log(result) // ResponseError
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
|
||||
@ -17,7 +17,6 @@ Following you can find some examples on how to use the client.
|
||||
* Executing a <<search_examples,search>> request;
|
||||
* I need <<suggest_examples,suggestions>>;
|
||||
* How to use the <<transport_request_examples,transport.request>> method;
|
||||
* How to use <<typescript_examples,TypeScript>>;
|
||||
|
||||
include::asStream.asciidoc[]
|
||||
include::bulk.asciidoc[]
|
||||
@ -29,7 +28,6 @@ include::scroll.asciidoc[]
|
||||
include::search.asciidoc[]
|
||||
include::suggest.asciidoc[]
|
||||
include::transport.request.asciidoc[]
|
||||
include::typescript.asciidoc[]
|
||||
include::sql.query.asciidoc[]
|
||||
include::update.asciidoc[]
|
||||
include::update_by_query.asciidoc[]
|
||||
|
||||
@ -9,12 +9,15 @@ API.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
const { body: bulkResponse } = await client.bulk({
|
||||
const bulkResponse = await client.bulk({
|
||||
refresh: true,
|
||||
body: [
|
||||
operations: [
|
||||
{ index: { _index: 'game-of-thrones' } },
|
||||
{
|
||||
character: 'Ned Stark',
|
||||
@ -40,8 +43,8 @@ async function run () {
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const { body } = await client.msearch({
|
||||
body: [
|
||||
const result = await client.msearch({
|
||||
searches: [
|
||||
{ index: 'game-of-thrones' },
|
||||
{ query: { match: { character: 'Daenerys' } } },
|
||||
|
||||
@ -50,7 +53,7 @@ async function run () {
|
||||
]
|
||||
})
|
||||
|
||||
console.log(body.responses)
|
||||
console.log(result.responses)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
|
||||
@ -70,17 +70,15 @@ module.exports = async (req, res) => {
|
||||
// expose you to the risk that a malicious user
|
||||
// could overload your cluster by crafting
|
||||
// expensive queries.
|
||||
body: {
|
||||
_source: ['id', 'url', 'name'], // the fields you want to show in the autocompletion
|
||||
size: 0,
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
|
||||
suggest: {
|
||||
suggestions: {
|
||||
prefix: req.query.q,
|
||||
completion: {
|
||||
field: 'suggest',
|
||||
size: 5
|
||||
}
|
||||
_source: ['id', 'url', 'name'], // the fields you want to show in the autocompletion
|
||||
size: 0,
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
|
||||
suggest: {
|
||||
suggestions: {
|
||||
prefix: req.query.q,
|
||||
completion: {
|
||||
field: 'suggest',
|
||||
size: 5
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -93,7 +91,7 @@ module.exports = async (req, res) => {
|
||||
// It might be useful to configure http control caching headers
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
||||
// res.setHeader('stale-while-revalidate', '30')
|
||||
res.json(response.body)
|
||||
res.json(response)
|
||||
} catch (err) {
|
||||
res.status(err.statusCode || 500)
|
||||
res.json({
|
||||
|
||||
@ -62,7 +62,7 @@ module.exports = async (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
res.json(response.body)
|
||||
res.json(response)
|
||||
} catch (err) {
|
||||
res.status(err.statusCode || 500)
|
||||
res.json({
|
||||
|
||||
@ -56,11 +56,12 @@ module.exports = async (req, res) => {
|
||||
const response = await client.index({
|
||||
index: INDEX,
|
||||
id: req.query.id,
|
||||
body: req.body
|
||||
document: req.body
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: `ApiKey ${token}`
|
||||
}
|
||||
},
|
||||
meta: true
|
||||
})
|
||||
|
||||
res.status(response.statusCode)
|
||||
|
||||
@ -60,10 +60,8 @@ module.exports = async (req, res) => {
|
||||
// expose you to the risk that a malicious user
|
||||
// could overload your cluster by crafting
|
||||
// expensive queries.
|
||||
body: {
|
||||
query: {
|
||||
match: { field: req.body.text }
|
||||
}
|
||||
query: {
|
||||
match: { field: req.body.text }
|
||||
}
|
||||
}, {
|
||||
headers: {
|
||||
@ -74,7 +72,7 @@ module.exports = async (req, res) => {
|
||||
// It might be useful to configure http control caching headers
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
||||
// res.setHeader('stale-while-revalidate', '30')
|
||||
res.json(response.body)
|
||||
res.json(response)
|
||||
} catch (err) {
|
||||
res.status(err.statusCode || 500)
|
||||
res.json({
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
"author": "Tomas Della Vedova",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@elastic/elasticsearch": "^7.10.0"
|
||||
"@elastic/elasticsearch": "^8.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"standard": "^16.0.3"
|
||||
|
||||
@ -43,21 +43,19 @@ async function generateApiKeys (opts) {
|
||||
}
|
||||
})
|
||||
|
||||
const { body } = await client.security.createApiKey({
|
||||
body: {
|
||||
name: 'elasticsearch-proxy',
|
||||
role_descriptors: {
|
||||
'elasticsearch-proxy-users': {
|
||||
index: [{
|
||||
names: indexNames,
|
||||
privileges
|
||||
}]
|
||||
}
|
||||
const result = await client.security.createApiKey({
|
||||
name: 'elasticsearch-proxy',
|
||||
role_descriptors: {
|
||||
'elasticsearch-proxy-users': {
|
||||
index: [{
|
||||
names: indexNames,
|
||||
privileges
|
||||
}]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return Buffer.from(`${body.id}:${body.api_key}`).toString('base64')
|
||||
return Buffer.from(`${result.id}:${result.api_key}`).toString('base64')
|
||||
}
|
||||
|
||||
generateApiKeys()
|
||||
|
||||
@ -15,12 +15,15 @@ the house Stark and remove the `house` field from the document source.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.',
|
||||
house: 'stark'
|
||||
@ -29,7 +32,7 @@ async function run () {
|
||||
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Arya Stark',
|
||||
quote: 'A girl is Arya Stark of Winterfell. And I\'m going home.',
|
||||
house: 'stark'
|
||||
@ -39,7 +42,7 @@ async function run () {
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
refresh: true,
|
||||
body: {
|
||||
document: {
|
||||
character: 'Tyrion Lannister',
|
||||
quote: 'A Lannister always pays his debts.',
|
||||
house: 'lannister'
|
||||
@ -47,33 +50,29 @@ async function run () {
|
||||
})
|
||||
|
||||
await client.reindex({
|
||||
waitForCompletion: true,
|
||||
wait_for_completion: true,
|
||||
refresh: true,
|
||||
body: {
|
||||
source: {
|
||||
index: 'game-of-thrones',
|
||||
query: {
|
||||
match: { character: 'stark' }
|
||||
}
|
||||
},
|
||||
dest: {
|
||||
index: 'stark-index'
|
||||
},
|
||||
script: {
|
||||
lang: 'painless',
|
||||
source: 'ctx._source.remove("house")'
|
||||
source: {
|
||||
index: 'game-of-thrones',
|
||||
query: {
|
||||
match: { character: 'stark' }
|
||||
}
|
||||
},
|
||||
dest: {
|
||||
index: 'stark-index'
|
||||
},
|
||||
script: {
|
||||
lang: 'painless',
|
||||
source: 'ctx._source.remove("house")'
|
||||
}
|
||||
})
|
||||
|
||||
const { body } = await client.search({
|
||||
const result = await client.search({
|
||||
index: 'stark-index',
|
||||
body: {
|
||||
query: { match_all: {} }
|
||||
}
|
||||
query: { match_all: {} }
|
||||
})
|
||||
|
||||
console.log(body.hits.hits)
|
||||
console.log(result.hits.hits)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
|
||||
@ -26,19 +26,22 @@ NOTE: Did you know that we provide an helper for sending scroll requests? You ca
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
const allQuotes = []
|
||||
const responseQueue = []
|
||||
|
||||
// Let's index some data!
|
||||
const { body: bulkResponse } = await client.bulk({
|
||||
const bulkResponse = await client.bulk({
|
||||
// here we are forcing an index refresh,
|
||||
// otherwise we will not get any result
|
||||
// in the consequent search
|
||||
refresh: true,
|
||||
body: [
|
||||
operations: [
|
||||
// operation to perform
|
||||
{ index: { _index: 'game-of-thrones' } },
|
||||
// the document to index
|
||||
@ -76,17 +79,15 @@ async function run () {
|
||||
size: 1,
|
||||
// filter the source to only include the quote field
|
||||
_source: ['quote'],
|
||||
body: {
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
})
|
||||
|
||||
responseQueue.push(response)
|
||||
|
||||
while (responseQueue.length) {
|
||||
const { body } = responseQueue.shift()
|
||||
const body = responseQueue.shift()
|
||||
|
||||
// collect the titles from this response
|
||||
body.hits.hits.forEach(function (hit) {
|
||||
@ -120,14 +121,17 @@ async iteration!
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
// Scroll utility
|
||||
async function * scrollSearch (params) {
|
||||
let response = await client.search(params)
|
||||
|
||||
while (true) {
|
||||
const sourceHits = response.body.hits.hits
|
||||
const sourceHits = response.hits.hits
|
||||
|
||||
if (sourceHits.length === 0) {
|
||||
break
|
||||
@ -137,12 +141,12 @@ async function * scrollSearch (params) {
|
||||
yield hit
|
||||
}
|
||||
|
||||
if (!response.body._scroll_id) {
|
||||
if (!response._scroll_id) {
|
||||
break
|
||||
}
|
||||
|
||||
response = await client.scroll({
|
||||
scrollId: response.body._scroll_id,
|
||||
scrollId: response._scroll_id,
|
||||
scroll: params.scroll
|
||||
})
|
||||
}
|
||||
@ -151,7 +155,7 @@ async function * scrollSearch (params) {
|
||||
async function run () {
|
||||
await client.bulk({
|
||||
refresh: true,
|
||||
body: [
|
||||
operations: [
|
||||
{ index: { _index: 'game-of-thrones' } },
|
||||
{
|
||||
character: 'Ned Stark',
|
||||
@ -177,10 +181,8 @@ async function run () {
|
||||
scroll: '30s',
|
||||
size: 1,
|
||||
_source: ['quote'],
|
||||
body: {
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -12,13 +12,16 @@ https://www.elastic.co/guide/en/elasticsearch/reference/6.6/search-request-body.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
// Let's start by indexing some data
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.'
|
||||
}
|
||||
@ -26,7 +29,7 @@ async function run () {
|
||||
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Daenerys Targaryen',
|
||||
quote: 'I am the blood of the dragon.'
|
||||
}
|
||||
@ -38,25 +41,23 @@ async function run () {
|
||||
// otherwise we will not get any result
|
||||
// in the consequent search
|
||||
refresh: true,
|
||||
body: {
|
||||
document: {
|
||||
character: 'Tyrion Lannister',
|
||||
quote: 'A mind needs books like a sword needs a whetstone.'
|
||||
}
|
||||
})
|
||||
|
||||
// Let's search!
|
||||
const { body } = await client.search({
|
||||
const result = await client.search({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
query: {
|
||||
match: {
|
||||
quote: 'winter'
|
||||
}
|
||||
query: {
|
||||
match: {
|
||||
quote: 'winter'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
console.log(body.hits.hits)
|
||||
console.log(result.hits.hits)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
|
||||
@ -17,12 +17,15 @@ manipulate the result to obtain an object easy to navigate.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.',
|
||||
house: 'stark'
|
||||
@ -31,7 +34,7 @@ async function run () {
|
||||
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Arya Stark',
|
||||
quote: 'A girl is Arya Stark of Winterfell. And I\'m going home.',
|
||||
house: 'stark'
|
||||
@ -41,25 +44,23 @@ async function run () {
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
refresh: true,
|
||||
body: {
|
||||
document: {
|
||||
character: 'Tyrion Lannister',
|
||||
quote: 'A Lannister always pays his debts.',
|
||||
house: 'lannister'
|
||||
}
|
||||
})
|
||||
|
||||
const { body } = await client.sql.query({
|
||||
body: {
|
||||
query: "SELECT * FROM \"game-of-thrones\" WHERE house='stark'"
|
||||
}
|
||||
const result = await client.sql.query({
|
||||
query: "SELECT * FROM \"game-of-thrones\" WHERE house='stark'"
|
||||
})
|
||||
|
||||
console.log(body)
|
||||
console.log(result)
|
||||
|
||||
const data = body.rows.map(row => {
|
||||
const data = result.rows.map(row => {
|
||||
const obj = {}
|
||||
for (let i = 0; i < row.length; i++) {
|
||||
obj[body.columns[i].name] = row[i]
|
||||
obj[result.columns[i].name] = row[i]
|
||||
}
|
||||
return obj
|
||||
})
|
||||
|
||||
@ -12,12 +12,15 @@ request. If the query part is left out, only suggestions are returned.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
const { body: bulkResponse } = await client.bulk({
|
||||
const bulkResponse = await client.bulk({
|
||||
refresh: true,
|
||||
body: [
|
||||
operations: [
|
||||
{ index: { _index: 'game-of-thrones' } },
|
||||
{
|
||||
character: 'Ned Stark',
|
||||
@ -43,22 +46,20 @@ async function run () {
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const { body } = await client.search({
|
||||
const result = await client.search({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
query: {
|
||||
match: { quote: 'witner' }
|
||||
},
|
||||
suggest: {
|
||||
gotsuggest: {
|
||||
text: 'witner',
|
||||
term: { field: 'quote' }
|
||||
}
|
||||
query: {
|
||||
match: { quote: 'winter' }
|
||||
},
|
||||
suggest: {
|
||||
gotsuggest: {
|
||||
text: 'winter',
|
||||
term: { field: 'quote' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
console.log(body)
|
||||
console.log(result)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
|
||||
@ -20,12 +20,15 @@ maintain.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
const { body: bulkResponse } = await client.bulk({
|
||||
const bulkResponse = await client.bulk({
|
||||
refresh: true,
|
||||
body: [
|
||||
operations: [
|
||||
{ index: { _index: 'game-of-thrones' } },
|
||||
{
|
||||
character: 'Ned Stark',
|
||||
@ -51,7 +54,7 @@ async function run () {
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const { body } = await client.transport.request({
|
||||
const response = await client.transport.request({
|
||||
method: 'POST',
|
||||
path: '/game-of-thrones/_search',
|
||||
body: {
|
||||
@ -64,7 +67,7 @@ async function run () {
|
||||
querystring: {}
|
||||
})
|
||||
|
||||
console.log(body)
|
||||
console.log(response)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
|
||||
@ -1,72 +0,0 @@
|
||||
[[typescript_examples]]
|
||||
=== Typescript
|
||||
|
||||
The client offers a first-class support for TypeScript, since it ships the type
|
||||
definitions for every exposed API.
|
||||
|
||||
NOTE: If you are using TypeScript you will be required to use _snake_case_ style
|
||||
to define the API parameters instead of _camelCase_.
|
||||
|
||||
[source,ts]
|
||||
----
|
||||
'use strict'
|
||||
|
||||
import { Client, ApiResponse, RequestParams } from '@elastic/elasticsearch'
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
|
||||
async function run (): void {
|
||||
// Let's start by indexing some data
|
||||
const doc1: RequestParams.Index = {
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.'
|
||||
}
|
||||
}
|
||||
await client.index(doc1)
|
||||
|
||||
const doc2: RequestParams.Index = {
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
character: 'Daenerys Targaryen',
|
||||
quote: 'I am the blood of the dragon.'
|
||||
}
|
||||
}
|
||||
await client.index(doc2)
|
||||
|
||||
const doc3: RequestParams.Index = {
|
||||
index: 'game-of-thrones',
|
||||
// here we are forcing an index refresh,
|
||||
// otherwise we will not get any result
|
||||
// in the consequent search
|
||||
refresh: true,
|
||||
body: {
|
||||
character: 'Tyrion Lannister',
|
||||
quote: 'A mind needs books like a sword needs a whetstone.'
|
||||
}
|
||||
}
|
||||
await client.index(doc3)
|
||||
|
||||
// Let's search!
|
||||
const params: RequestParams.Search = {
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
query: {
|
||||
match: {
|
||||
quote: 'winter'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
client
|
||||
.search(params)
|
||||
.then((result: ApiResponse) => {
|
||||
console.log(result.body.hits.hits)
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
|
||||
run()
|
||||
----
|
||||
@ -10,13 +10,16 @@ a character has said the given quote, and then we will update the `times` field.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
id: '1',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.',
|
||||
times: 0
|
||||
@ -26,23 +29,21 @@ async function run () {
|
||||
await client.update({
|
||||
index: 'game-of-thrones',
|
||||
id: '1',
|
||||
body: {
|
||||
script: {
|
||||
lang: 'painless',
|
||||
source: 'ctx._source.times++'
|
||||
// you can also use parameters
|
||||
// source: 'ctx._source.times += params.count',
|
||||
// params: { count: 1 }
|
||||
}
|
||||
script: {
|
||||
lang: 'painless',
|
||||
source: 'ctx._source.times++'
|
||||
// you can also use parameters
|
||||
// source: 'ctx._source.times += params.count',
|
||||
// params: { count: 1 }
|
||||
}
|
||||
})
|
||||
|
||||
const { body } = await client.get({
|
||||
const document = await client.get({
|
||||
index: 'game-of-thrones',
|
||||
id: '1'
|
||||
})
|
||||
|
||||
console.log(body)
|
||||
console.log(document)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
@ -56,13 +57,16 @@ With the update API, you can also run a partial update of a document.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
id: '1',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.',
|
||||
isAlive: true
|
||||
@ -72,19 +76,17 @@ async function run () {
|
||||
await client.update({
|
||||
index: 'game-of-thrones',
|
||||
id: '1',
|
||||
body: {
|
||||
doc: {
|
||||
isAlive: false
|
||||
}
|
||||
doc: {
|
||||
isAlive: false
|
||||
}
|
||||
})
|
||||
|
||||
const { body } = await client.get({
|
||||
const document = await client.get({
|
||||
index: 'game-of-thrones',
|
||||
id: '1'
|
||||
})
|
||||
|
||||
console.log(body)
|
||||
console.log(document)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
|
||||
@ -10,12 +10,15 @@ property or some other online mapping change.
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.'
|
||||
}
|
||||
@ -24,7 +27,7 @@ async function run () {
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
refresh: true,
|
||||
body: {
|
||||
document: {
|
||||
character: 'Arya Stark',
|
||||
quote: 'A girl is Arya Stark of Winterfell. And I\'m going home.'
|
||||
}
|
||||
@ -33,27 +36,23 @@ async function run () {
|
||||
await client.updateByQuery({
|
||||
index: 'game-of-thrones',
|
||||
refresh: true,
|
||||
body: {
|
||||
script: {
|
||||
lang: 'painless',
|
||||
source: 'ctx._source["house"] = "stark"'
|
||||
},
|
||||
query: {
|
||||
match: {
|
||||
character: 'stark'
|
||||
}
|
||||
script: {
|
||||
lang: 'painless',
|
||||
source: 'ctx._source["house"] = "stark"'
|
||||
},
|
||||
query: {
|
||||
match: {
|
||||
character: 'stark'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const { body } = await client.search({
|
||||
const result = await client.search({
|
||||
index: 'game-of-thrones',
|
||||
body: {
|
||||
query: { match_all: {} }
|
||||
}
|
||||
query: { match_all: {} }
|
||||
})
|
||||
|
||||
console.log(body.hits.hits)
|
||||
console.log(result.hits.hits)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
|
||||
@ -1,72 +0,0 @@
|
||||
[[extend]]
|
||||
=== Extend the client
|
||||
|
||||
Sometimes you need to reuse the same logic, or you want to build a custom API to
|
||||
allow you simplify your code. The easiest way to achieve that is by extending
|
||||
the client.
|
||||
|
||||
NOTE: If you want to override existing methods, you should specify the
|
||||
`{ force: true }` option.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
|
||||
client.extend('supersearch', ({ makeRequest, ConfigurationError }) => {
|
||||
return function supersearch (params, options) {
|
||||
const {
|
||||
body,
|
||||
index,
|
||||
method,
|
||||
...querystring
|
||||
} = params
|
||||
|
||||
// params validation
|
||||
if (body == null) {
|
||||
throw new ConfigurationError('Missing required parameter: body')
|
||||
}
|
||||
|
||||
// build request object
|
||||
const request = {
|
||||
method: method || 'POST',
|
||||
path: `/${encodeURIComponent(index)}/_search_`,
|
||||
body,
|
||||
querystring
|
||||
}
|
||||
|
||||
// build request options object
|
||||
const requestOptions = {
|
||||
ignore: options.ignore || null,
|
||||
requestTimeout: options.requestTimeout || null,
|
||||
maxRetries: options.maxRetries || null,
|
||||
asStream: options.asStream || false,
|
||||
headers: options.headers || null
|
||||
}
|
||||
|
||||
return makeRequest(request, requestOptions)
|
||||
}
|
||||
})
|
||||
|
||||
client.extend('utility.index', ({ makeRequest }) => {
|
||||
return function _index (params, options) {
|
||||
// your code
|
||||
}
|
||||
})
|
||||
|
||||
client.extend('utility.delete', ({ makeRequest }) => {
|
||||
return function _delete (params, options) {
|
||||
// your code
|
||||
}
|
||||
})
|
||||
|
||||
client.extend('indices.delete', { force: true }, ({ makeRequest }) => {
|
||||
return function _delete (params, options) {
|
||||
// your code
|
||||
}
|
||||
})
|
||||
|
||||
client.supersearch(...)
|
||||
client.utility.index(...)
|
||||
client.utility.delete(...)
|
||||
----
|
||||
@ -27,7 +27,10 @@ const { createReadStream } = require('fs')
|
||||
const split = require('split2')
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
const result = await client.helpers.bulk({
|
||||
datasource: createReadStream('./dataset.ndjson').pipe(split()),
|
||||
onDocument (doc) {
|
||||
@ -248,7 +251,10 @@ const { createReadStream } = require('fs')
|
||||
const split = require('split2')
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
const b = client.helpers.bulk({
|
||||
datasource: createReadStream('./dataset.ndjson').pipe(split()),
|
||||
onDocument (doc) {
|
||||
@ -304,7 +310,10 @@ async function * generator () {
|
||||
}
|
||||
}
|
||||
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
const result = await client.helpers.bulk({
|
||||
datasource: generator(),
|
||||
onDocument (doc) {
|
||||
@ -338,26 +347,18 @@ sources.
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
const m = client.helpers.msearch()
|
||||
|
||||
// promise style API
|
||||
m.search(
|
||||
{ index: 'stackoverflow' },
|
||||
{ query: { match: { title: 'javascript' } } }
|
||||
)
|
||||
.then(result => console.log(result.body)) // or result.documents
|
||||
.catch(err => console.error(err))
|
||||
|
||||
// callback style API
|
||||
m.search(
|
||||
{ index: 'stackoverflow' },
|
||||
{ query: { match: { title: 'ruby' } } },
|
||||
(err, result) => {
|
||||
if (err) console.error(err)
|
||||
console.log(result.body)) // or result.documents
|
||||
}
|
||||
)
|
||||
----
|
||||
|
||||
To create a new instance of the multi search (msearch) helper, you should access
|
||||
@ -438,7 +439,10 @@ running will not be stopped.
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
const m = client.helpers.msearch()
|
||||
|
||||
m.search(
|
||||
@ -474,11 +478,9 @@ the query string.
|
||||
----
|
||||
const documents = await client.helpers.search({
|
||||
index: 'stackoverflow',
|
||||
body: {
|
||||
query: {
|
||||
match: {
|
||||
title: 'javascript'
|
||||
}
|
||||
query: {
|
||||
match: {
|
||||
title: 'javascript'
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -505,11 +507,9 @@ the `429` error and uses the `maxRetries` option of the client.
|
||||
----
|
||||
const scrollSearch = client.helpers.scrollSearch({
|
||||
index: 'stackoverflow',
|
||||
body: {
|
||||
query: {
|
||||
match: {
|
||||
title: 'javascript'
|
||||
}
|
||||
query: {
|
||||
match: {
|
||||
title: 'javascript'
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -564,11 +564,9 @@ automatically adds `filter_path=hits.hits._source` to the query string.
|
||||
----
|
||||
const scrollSearch = client.helpers.scrollDocuments({
|
||||
index: 'stackoverflow',
|
||||
body: {
|
||||
query: {
|
||||
match: {
|
||||
title: 'javascript'
|
||||
}
|
||||
query: {
|
||||
match: {
|
||||
title: 'javascript'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
= Elasticsearch JavaScript Client
|
||||
|
||||
:branch: master
|
||||
include::{asciidoc-dir}/../../shared/versions/stack/{source_branch}.asciidoc[]
|
||||
include::{asciidoc-dir}/../../shared/attributes.asciidoc[]
|
||||
|
||||
include::introduction.asciidoc[]
|
||||
include::changelog.asciidoc[]
|
||||
include::installation.asciidoc[]
|
||||
include::connecting.asciidoc[]
|
||||
include::configuration.asciidoc[]
|
||||
include::basic-config.asciidoc[]
|
||||
include::advanced-config.asciidoc[]
|
||||
include::child.asciidoc[]
|
||||
include::extend.asciidoc[]
|
||||
include::testing.asciidoc[]
|
||||
include::integrations.asciidoc[]
|
||||
include::observability.asciidoc[]
|
||||
@ -19,3 +19,4 @@ include::typescript.asciidoc[]
|
||||
include::reference.asciidoc[]
|
||||
include::examples/index.asciidoc[]
|
||||
include::helpers.asciidoc[]
|
||||
include::redirects.asciidoc[]
|
||||
|
||||
@ -56,6 +56,10 @@ of `^7.10.0`).
|
||||
|`10.x`
|
||||
|April 2021
|
||||
|`7.12` (mid 2021)
|
||||
|
||||
|`12.x`
|
||||
|April 2022
|
||||
|`8.2` (early 2022)
|
||||
|===
|
||||
|
||||
[discrete]
|
||||
@ -70,8 +74,8 @@ Elasticsearch language clients are only backwards compatible with default distri
|
||||
|{es} Version
|
||||
|Client Version
|
||||
|
||||
|`master`
|
||||
|`master`
|
||||
|`8.x`
|
||||
|`8.x`
|
||||
|
||||
|`7.x`
|
||||
|`7.x`
|
||||
|
||||
@ -4,9 +4,6 @@
|
||||
This is the official Node.js client for {es}. This page gives a quick overview
|
||||
about the features of the client.
|
||||
|
||||
Refer to <<breaking-changes,this page>> for breaking changes coming from the old
|
||||
client.
|
||||
|
||||
|
||||
[discrete]
|
||||
=== Features
|
||||
@ -23,72 +20,21 @@ client.
|
||||
[discrete]
|
||||
=== Quick start
|
||||
|
||||
First of all, require, then initialize the client:
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
----
|
||||
|
||||
|
||||
You can use both the callback API and the promise API, both behave the same way.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
// promise API
|
||||
const result = await client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// callback API
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: {
|
||||
query: {
|
||||
match: { hello: 'world' }
|
||||
}
|
||||
}
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
----
|
||||
|
||||
|
||||
The returned value of **every** API call is formed as follows:
|
||||
|
||||
[source,ts]
|
||||
----
|
||||
{
|
||||
body: object | boolean
|
||||
statusCode: number
|
||||
headers: object
|
||||
warnings: [string]
|
||||
meta: object
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
Let's see a complete example!
|
||||
|
||||
[source,js]
|
||||
----
|
||||
'use strict'
|
||||
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
async function run () {
|
||||
// Let's start by indexing some data
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
// type: '_doc', // uncomment this line if you are using {es} ≤ 6
|
||||
body: {
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.'
|
||||
}
|
||||
@ -96,8 +42,7 @@ async function run () {
|
||||
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
// type: '_doc', // uncomment this line if you are using {es} ≤ 6
|
||||
body: {
|
||||
document: {
|
||||
character: 'Daenerys Targaryen',
|
||||
quote: 'I am the blood of the dragon.'
|
||||
}
|
||||
@ -105,29 +50,25 @@ async function run () {
|
||||
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
// type: '_doc', // uncomment this line if you are using {es} ≤ 6
|
||||
body: {
|
||||
document: {
|
||||
character: 'Tyrion Lannister',
|
||||
quote: 'A mind needs books like a sword needs a whetstone.'
|
||||
}
|
||||
})
|
||||
|
||||
// We need to force an index refresh at this point, otherwise we will not
|
||||
// here we are forcing an index refresh, otherwise we will not
|
||||
// get any result in the consequent search
|
||||
await client.indices.refresh({ index: 'game-of-thrones' })
|
||||
|
||||
// Let's search!
|
||||
const { body } = await client.search({
|
||||
const result= await client.search({
|
||||
index: 'game-of-thrones',
|
||||
// type: '_doc', // uncomment this line if you are using {es} ≤ 6
|
||||
body: {
|
||||
query: {
|
||||
match: { quote: 'winter' }
|
||||
}
|
||||
query: {
|
||||
match: { quote: 'winter' }
|
||||
}
|
||||
})
|
||||
|
||||
console.log(body.hits.hits)
|
||||
console.log(result.hits.hits)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
@ -178,23 +119,26 @@ Require the packages from your code by using the alias you have defined.
|
||||
const { Client: Client6 } = require('es6')
|
||||
const { Client: Client7 } = require('es7')
|
||||
|
||||
const client6 = new Client6({ node: 'http://localhost:9200' })
|
||||
const client7 = new Client7({ node: 'http://localhost:9201' })
|
||||
const client6 = new Client6({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
const client7 = new Client7({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
client6.info(console.log)
|
||||
client7.info(console.log)
|
||||
client6.info().then(console.log, console.log)
|
||||
client7.info().then(console.log, console.log)
|
||||
----
|
||||
|
||||
|
||||
Finally, if you want to install the client for the next version of {es} (the one
|
||||
that lives in the {es} master branch), use the following command:
|
||||
that lives in the {es} main branch), use the following command:
|
||||
|
||||
[source,sh]
|
||||
----
|
||||
npm install esmaster@github:elastic/elasticsearch-js
|
||||
npm install esmain@github:elastic/elasticsearch-js
|
||||
----
|
||||
WARNING: This command installs the master branch of the client which is not
|
||||
considered stable.
|
||||
|
||||
|
||||
include::breaking-changes.asciidoc[]
|
||||
WARNING: This command installs the main branch of the client which is not
|
||||
considered stable.
|
||||
@ -2,7 +2,7 @@
|
||||
=== Observability
|
||||
|
||||
The client does not provide a default logger, but instead it offers an event
|
||||
emitter interfaces to hook into internal events, such as `request` and
|
||||
emitter interface to hook into internal events, such as `request` and
|
||||
`response`.
|
||||
|
||||
Correlating those events can be hard, especially if your applications have a
|
||||
@ -34,9 +34,12 @@ response and error that is happening during the use of the client.
|
||||
----
|
||||
const logger = require('my-logger')()
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
client.on('response', (err, result) => {
|
||||
client.diagnostic.on('response', (err, result) => {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
} else {
|
||||
@ -53,7 +56,7 @@ The client emits the following events:
|
||||
a|Emitted before starting serialization and compression. If you want to measure this phase duration, you should measure the time elapsed between this event and `request`.
|
||||
[source,js]
|
||||
----
|
||||
client.on('serialization', (err, result) => {
|
||||
client.diagnostic.on('serialization', (err, result) => {
|
||||
console.log(err, result)
|
||||
})
|
||||
----
|
||||
@ -62,7 +65,7 @@ client.on('serialization', (err, result) => {
|
||||
a|Emitted before sending the actual request to {es} _(emitted multiple times in case of retries)_.
|
||||
[source,js]
|
||||
----
|
||||
client.on('request', (err, result) => {
|
||||
client.diagnostic.on('request', (err, result) => {
|
||||
console.log(err, result)
|
||||
})
|
||||
----
|
||||
@ -71,7 +74,7 @@ client.on('request', (err, result) => {
|
||||
a|Emitted before starting deserialization and decompression. If you want to measure this phase duration, you should measure the time elapsed between this event and `response`. _(This event might not be emitted in certain situations)_.
|
||||
[source,js]
|
||||
----
|
||||
client.on('deserialization', (err, result) => {
|
||||
client.diagnostic.on('deserialization', (err, result) => {
|
||||
console.log(err, result)
|
||||
})
|
||||
----
|
||||
@ -80,7 +83,7 @@ client.on('deserialization', (err, result) => {
|
||||
a|Emitted once {es} response has been received and parsed.
|
||||
[source,js]
|
||||
----
|
||||
client.on('response', (err, result) => {
|
||||
client.diagnostic.on('response', (err, result) => {
|
||||
console.log(err, result)
|
||||
})
|
||||
----
|
||||
@ -89,7 +92,7 @@ client.on('response', (err, result) => {
|
||||
a|Emitted when the client ends a sniffing request.
|
||||
[source,js]
|
||||
----
|
||||
client.on('sniff', (err, result) => {
|
||||
client.diagnostic.on('sniff', (err, result) => {
|
||||
console.log(err, result)
|
||||
})
|
||||
----
|
||||
@ -98,7 +101,7 @@ client.on('sniff', (err, result) => {
|
||||
a|Emitted if the client is able to resurrect a dead node.
|
||||
[source,js]
|
||||
----
|
||||
client.on('resurrect', (err, result) => {
|
||||
client.diagnostic.on('resurrect', (err, result) => {
|
||||
console.log(err, result)
|
||||
})
|
||||
----
|
||||
@ -183,16 +186,19 @@ handle this problem.
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
client.on('request', (err, result) => {
|
||||
client.diagnostic.on('request', (err, result) => {
|
||||
const { id } = result.meta.request
|
||||
if (err) {
|
||||
console.log({ error: err, reqId: id })
|
||||
}
|
||||
})
|
||||
|
||||
client.on('response', (err, result) => {
|
||||
client.diagnostic.on('response', (err, result) => {
|
||||
const { id } = result.meta.request
|
||||
if (err) {
|
||||
console.log({ error: err, reqId: id })
|
||||
@ -201,10 +207,8 @@ client.on('response', (err, result) => {
|
||||
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
query: { match_all: {} }
|
||||
}).then(console.log, console.log)
|
||||
----
|
||||
|
||||
|
||||
@ -215,7 +219,8 @@ By default the id is an incremental integer, but you can configure it with the
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' },
|
||||
// it takes two parameters, the request parameters and options
|
||||
generateRequestId: function (params, options) {
|
||||
// your id generation logic
|
||||
@ -232,12 +237,10 @@ You can also specify a custom id per request:
|
||||
----
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
query: { match_all: {} }
|
||||
}, {
|
||||
id: 'custom-id'
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
}).then(console.log, console.log)
|
||||
----
|
||||
|
||||
|
||||
@ -250,9 +253,12 @@ can do that via the `context` option of a request:
|
||||
[source,js]
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
client.on('request', (err, result) => {
|
||||
client.diagnostic.on('request', (err, result) => {
|
||||
const { id } = result.meta.request
|
||||
const { context } = result.meta
|
||||
if (err) {
|
||||
@ -260,7 +266,7 @@ client.on('request', (err, result) => {
|
||||
}
|
||||
})
|
||||
|
||||
client.on('response', (err, result) => {
|
||||
client.diagnostic.on('response', (err, result) => {
|
||||
const { id } = result.meta.request
|
||||
const { winter } = result.meta.context
|
||||
if (err) {
|
||||
@ -270,12 +276,10 @@ client.on('response', (err, result) => {
|
||||
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
query: { match_all: {} }
|
||||
}, {
|
||||
context: { winter: 'is coming' }
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
}).then(console.log, console.log)
|
||||
----
|
||||
|
||||
The context object can also be configured as a global option in the client
|
||||
@ -286,11 +290,12 @@ merged, and the API level object will take precedence.
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' },
|
||||
context: { winter: 'is coming' }
|
||||
})
|
||||
|
||||
client.on('request', (err, result) => {
|
||||
client.diagnostic.on('request', (err, result) => {
|
||||
const { id } = result.meta.request
|
||||
const { context } = result.meta
|
||||
if (err) {
|
||||
@ -298,7 +303,7 @@ client.on('request', (err, result) => {
|
||||
}
|
||||
})
|
||||
|
||||
client.on('response', (err, result) => {
|
||||
client.diagnostic.on('response', (err, result) => {
|
||||
const { id } = result.meta.request
|
||||
const { winter } = result.meta.context
|
||||
if (err) {
|
||||
@ -308,12 +313,10 @@ client.on('response', (err, result) => {
|
||||
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
query: { match_all: {} }
|
||||
}, {
|
||||
context: { winter: 'has come' }
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
}).then(console.log, console.log)
|
||||
----
|
||||
|
||||
|
||||
@ -329,7 +332,8 @@ options help you in this regard.
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' },
|
||||
name: 'parent-client' // default to 'elasticsearch-js'
|
||||
})
|
||||
|
||||
@ -339,7 +343,7 @@ const child = client.child({
|
||||
|
||||
console.log(client.name, child.name)
|
||||
|
||||
client.on('request', (err, result) => {
|
||||
client.diagnostic.on('request', (err, result) => {
|
||||
const { id } = result.meta.request
|
||||
const { name } = result.meta
|
||||
if (err) {
|
||||
@ -347,7 +351,7 @@ client.on('request', (err, result) => {
|
||||
}
|
||||
})
|
||||
|
||||
client.on('response', (err, result) => {
|
||||
client.diagnostic.on('response', (err, result) => {
|
||||
const { id } = result.meta.request
|
||||
const { name } = result.meta
|
||||
if (err) {
|
||||
@ -357,17 +361,13 @@ client.on('response', (err, result) => {
|
||||
|
||||
client.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
query: { match_all: {} }
|
||||
}).then(console.log, console.log)
|
||||
|
||||
child.search({
|
||||
index: 'my-index',
|
||||
body: { foo: 'bar' }
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
query: { match_all: {} }
|
||||
}).then(console.log, console.log)
|
||||
----
|
||||
|
||||
|
||||
@ -377,9 +377,9 @@ child.search({
|
||||
To improve observability, the client offers an easy way to configure the
|
||||
`X-Opaque-Id` header. If you set the `X-Opaque-Id` in a specific request, this
|
||||
allows you to discover this identifier in the
|
||||
https://www.elastic.co/guide/en/elasticsearch/reference/master/logging.html#deprecation-logging[deprecation logs],
|
||||
helps you with https://www.elastic.co/guide/en/elasticsearch/reference/master/index-modules-slowlog.html#_identifying_search_slow_log_origin[identifying search slow log origin]
|
||||
as well as https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html#_identifying_running_tasks[identifying running tasks].
|
||||
https://www.elastic.co/guide/en/elasticsearch/reference/8.0/logging.html#deprecation-logging[deprecation logs],
|
||||
helps you with https://www.elastic.co/guide/en/elasticsearch/reference/8.0/index-modules-slowlog.html#_identifying_search_slow_log_origin[identifying search slow log origin]
|
||||
as well as https://www.elastic.co/guide/en/elasticsearch/reference/8.0/tasks.html#_identifying_running_tasks[identifying running tasks].
|
||||
|
||||
The `X-Opaque-Id` should be configured in each request, for doing that you can
|
||||
use the `opaqueId` option, as you can see in the following example. The
|
||||
@ -389,7 +389,8 @@ resulting header will be `{ 'X-Opaque-Id': 'my-search' }`.
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200'
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
client.search({
|
||||
@ -397,9 +398,7 @@ client.search({
|
||||
body: { foo: 'bar' }
|
||||
}, {
|
||||
opaqueId: 'my-search'
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
}).then(console.log, console.log)
|
||||
----
|
||||
|
||||
Sometimes it may be useful to prefix all the `X-Opaque-Id` headers with a
|
||||
@ -412,7 +411,8 @@ doing this, the client offers a top-level configuration option:
|
||||
----
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' },
|
||||
opaqueIdPrefix: 'proxy-client::'
|
||||
})
|
||||
|
||||
@ -421,8 +421,6 @@ client.search({
|
||||
body: { foo: 'bar' }
|
||||
}, {
|
||||
opaqueId: 'my-search'
|
||||
}, (err, result) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
}).then(console.log, console.log)
|
||||
----
|
||||
|
||||
|
||||
17
docs/redirects.asciidoc
Normal file
17
docs/redirects.asciidoc
Normal file
@ -0,0 +1,17 @@
|
||||
["appendix",role="exclude",id="redirects"]
|
||||
= Deleted pages
|
||||
|
||||
The following pages have moved or been deleted.
|
||||
|
||||
[role="exclude",id="auth-reference"]
|
||||
== Authentication
|
||||
|
||||
This page has moved. See <<client-connecting>>.
|
||||
|
||||
[role="exclude",id="breaking-changes"]
|
||||
== Breaking changes
|
||||
|
||||
For information about migrating from the legacy elasticsearch.js client to the
|
||||
new Elasticsearch JavaScript client, refer to the
|
||||
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/7.17/breaking-changes.html[7.17
|
||||
JavaScript client migration guide].
|
||||
15082
docs/reference.asciidoc
15082
docs/reference.asciidoc
File diff suppressed because it is too large
Load Diff
@ -61,7 +61,8 @@ const Mock = require('@elastic/elasticsearch-mock')
|
||||
|
||||
const mock = new Mock()
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' },
|
||||
Connection: mock.getConnection()
|
||||
})
|
||||
|
||||
@ -72,7 +73,7 @@ mock.add({
|
||||
return { status: 'ok' }
|
||||
})
|
||||
|
||||
client.info(console.log)
|
||||
client.info().then(console.log, console.log)
|
||||
----
|
||||
|
||||
As you can see it works closely with the client itself, once you have created a
|
||||
@ -129,8 +130,8 @@ mock.add({
|
||||
return { count: 42 }
|
||||
})
|
||||
|
||||
client.count({ index: 'foo' }, console.log) // => { count: 42 }
|
||||
client.count({ index: 'bar' }, console.log) // => { count: 42 }
|
||||
client.count({ index: 'foo' }).then(console.log, console.log) // => { count: 42 }
|
||||
client.count({ index: 'bar' }).then(console.log, console.log) // => { count: 42 }
|
||||
----
|
||||
|
||||
And wildcards are supported as well.
|
||||
|
||||
@ -6,7 +6,8 @@ errors, it also handles sniffing.
|
||||
|
||||
[source,js]
|
||||
----
|
||||
const { Client, Transport } = require('@elastic/elasticsearch')
|
||||
const { Client } = require('@elastic/elasticsearch')
|
||||
const { Transport } = require('@elastic/transport')
|
||||
|
||||
class MyTransport extends Transport {
|
||||
request (params, options, callback) {
|
||||
|
||||
@ -4,274 +4,76 @@
|
||||
The client offers a first-class support for TypeScript, shipping a complete set
|
||||
of type definitions of Elasticsearch's API surface.
|
||||
|
||||
|
||||
NOTE: If you are using TypeScript you need to use _snake_case_ style to define
|
||||
the API parameters instead of _camelCase_.
|
||||
|
||||
Currently the client exposes two type definitions, the legacy one, which is the default
|
||||
and the new one, which will be the default in the next major.
|
||||
We strongly recommend to migrate to the new one as soon as possible, as the new types
|
||||
are offering a vastly improved developer experience and guarantee you that your code
|
||||
will always be in sync with the latest Elasticsearch features.
|
||||
|
||||
[discrete]
|
||||
==== New type definitions
|
||||
|
||||
The new type definition is more advanced compared to the legacy one. In the legacy
|
||||
type definitions you were expected to configure via generics both request and response
|
||||
bodies. The new type definitions comes with a complete type definition for every
|
||||
Elasticsearch endpoint.
|
||||
|
||||
For example:
|
||||
|
||||
[source,ts]
|
||||
----
|
||||
// legacy definitions
|
||||
const response = await client.search<SearchResponse<Source>, SearchBody>({
|
||||
index: 'test',
|
||||
body: {
|
||||
query: {
|
||||
match: { foo: 'bar' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// new definitions
|
||||
const response = await client.search<Source>({
|
||||
index: 'test',
|
||||
body: {
|
||||
query: {
|
||||
match: { foo: 'bar' }
|
||||
}
|
||||
}
|
||||
})
|
||||
----
|
||||
|
||||
The types are not 100% complete yet. Some APIs are missing (the newest ones, e.g. EQL),
|
||||
and others may contain some errors, but we are continuously pushing fixes & improvements.
|
||||
|
||||
[discrete]
|
||||
==== Request & Response types
|
||||
|
||||
Once you migrate to the new types, those are automatically integrated into the Elasticsearch client, you will get them out of the box.
|
||||
If everything works, meaning that you won’t get compiler errors, you are good to go!
|
||||
The types are already correct, and there is nothing more to do.
|
||||
|
||||
If a type is incorrect, you should add a comment `// @ts-expect-error @elastic/elasticsearch`
|
||||
telling TypeScript that you are aware of the warning and you would like to temporarily suppress it.
|
||||
In this way, your code will compile until the type is fixed, and when it happens, you’ll only need to remove the
|
||||
`// @ts-expect-error @elastic/elasticsearch` comment (TypeScript will let you know when it is time).
|
||||
Finally, if the type you need is missing, you’ll see that the client method returns (or defines as a parameter)
|
||||
a `TODO` type, which accepts any object.
|
||||
|
||||
Open an issue in the client repository letting us know if you encounter any problem!
|
||||
|
||||
If needed you can import the request and response types.
|
||||
|
||||
[source,ts]
|
||||
----
|
||||
import { Client, estypes } from '@elastic/elasticsearch'
|
||||
import type { Client as NewTypes } from '@elastic/elasticsearch/api/new'
|
||||
|
||||
// @ts-expect-error @elastic/elasticsearch
|
||||
const client: NewTypes = new Client({
|
||||
node: 'http://localhost:9200'
|
||||
})
|
||||
|
||||
interface Source {
|
||||
foo: string
|
||||
}
|
||||
|
||||
const request: estypes.IndexRequest<Source> = {
|
||||
index: 'test',
|
||||
body: { foo: 'bar' }
|
||||
}
|
||||
|
||||
await client.index(request)
|
||||
----
|
||||
|
||||
[discrete]
|
||||
===== How to migrate to the new type definitions
|
||||
|
||||
Since the new type definitions can be considered a breaking change we couldn't add the directly to the client.
|
||||
Following you will find a snippet that shows you how to override the default types with the new ones.
|
||||
==== Example
|
||||
|
||||
[source,ts]
|
||||
----
|
||||
import { Client } from '@elastic/elasticsearch'
|
||||
import type { Client as NewTypes } from '@elastic/elasticsearch/api/new'
|
||||
|
||||
// @ts-expect-error @elastic/elasticsearch
|
||||
const client: NewTypes = new Client({
|
||||
node: 'http://localhost:9200'
|
||||
const client = new Client({
|
||||
cloud: { id: '<cloud-id>' },
|
||||
auth: { apiKey: 'base64EncodedKey' }
|
||||
})
|
||||
|
||||
interface Source {
|
||||
foo: string
|
||||
}
|
||||
|
||||
// try the new code completion when building a query!
|
||||
const response = await client.search<Source>({
|
||||
index: 'test',
|
||||
body: {
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// try the new code completion when traversing a response!
|
||||
const results = response.body.hits.hits.map(hit => hit._source)
|
||||
// results type will be `Source[]`
|
||||
console.log(results)
|
||||
----
|
||||
|
||||
[discrete]
|
||||
==== Legacy type definitions
|
||||
|
||||
By default event API uses
|
||||
https://www.typescriptlang.org/docs/handbook/generics.html[generics] to specify
|
||||
the requests and response bodies and the `meta.context`. Currently, we can't
|
||||
provide those definitions, but we are working to improve this situation.
|
||||
|
||||
You can find a partial definition of the request types by importing
|
||||
`RequestParams`, which is used by default in the client and accepts a body (when
|
||||
needed) as a generic to provide a better specification.
|
||||
|
||||
The body defaults to `RequestBody` and `RequestNDBody`, which are defined as
|
||||
follows:
|
||||
|
||||
[source,ts]
|
||||
----
|
||||
type RequestBody<T = Record<string, any>> = T | string | Buffer | ReadableStream
|
||||
type RequestNDBody<T = Record<string, any>[]> = T | string | string[] | Buffer | ReadableStream
|
||||
----
|
||||
|
||||
You can specify the response and request body in each API as follows:
|
||||
|
||||
[source,ts]
|
||||
----
|
||||
const response = await client.search<ResponseBody, RequestBody, Context>({
|
||||
index: 'test',
|
||||
body: {
|
||||
query: {
|
||||
match: { foo: 'bar' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
console.log(response.body)
|
||||
----
|
||||
|
||||
You don't have to specify all the generics, but the order must be respected.
|
||||
|
||||
|
||||
[discrete]
|
||||
===== A complete example
|
||||
|
||||
[source,ts]
|
||||
----
|
||||
import {
|
||||
Client,
|
||||
// Object that contains the type definitions of every API method
|
||||
RequestParams,
|
||||
// Interface of the generic API response
|
||||
ApiResponse,
|
||||
} from '@elastic/elasticsearch'
|
||||
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
|
||||
// Define the type of the body for the Search request
|
||||
interface SearchBody {
|
||||
query: {
|
||||
match: { foo: string }
|
||||
}
|
||||
}
|
||||
|
||||
// Complete definition of the Search response
|
||||
interface ShardsResponse {
|
||||
total: number;
|
||||
successful: number;
|
||||
failed: number;
|
||||
skipped: number;
|
||||
}
|
||||
|
||||
interface Explanation {
|
||||
value: number;
|
||||
description: string;
|
||||
details: Explanation[];
|
||||
}
|
||||
|
||||
interface SearchResponse<T> {
|
||||
took: number;
|
||||
timed_out: boolean;
|
||||
_scroll_id?: string;
|
||||
_shards: ShardsResponse;
|
||||
hits: {
|
||||
total: number;
|
||||
max_score: number;
|
||||
hits: Array<{
|
||||
_index: string;
|
||||
_type: string;
|
||||
_id: string;
|
||||
_score: number;
|
||||
_source: T;
|
||||
_version?: number;
|
||||
_explanation?: Explanation;
|
||||
fields?: any;
|
||||
highlight?: any;
|
||||
inner_hits?: any;
|
||||
matched_queries?: string[];
|
||||
sort?: string[];
|
||||
}>;
|
||||
};
|
||||
aggregations?: any;
|
||||
}
|
||||
|
||||
// Define the interface of the source object
|
||||
interface Source {
|
||||
foo: string
|
||||
interface Document {
|
||||
character: string
|
||||
quote: string
|
||||
}
|
||||
|
||||
async function run () {
|
||||
// All of the examples below are valid code, by default,
|
||||
// the request body will be `RequestBody` and response will be `Record<string, any>`.
|
||||
let response = await client.search({
|
||||
index: 'test',
|
||||
body: {
|
||||
query: {
|
||||
match: { foo: 'bar' }
|
||||
}
|
||||
// Let's start by indexing some data
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
document: {
|
||||
character: 'Ned Stark',
|
||||
quote: 'Winter is coming.'
|
||||
}
|
||||
})
|
||||
// body here is `ResponseBody`
|
||||
console.log(response.body)
|
||||
|
||||
// The first generic is the response body
|
||||
response = await client.search<SearchResponse<Source>>({
|
||||
index: 'test',
|
||||
// Here the body must follow the `RequestBody` interface
|
||||
body: {
|
||||
query: {
|
||||
match: { foo: 'bar' }
|
||||
}
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
document: {
|
||||
character: 'Daenerys Targaryen',
|
||||
quote: 'I am the blood of the dragon.'
|
||||
}
|
||||
})
|
||||
// body here is `SearchResponse<Source>`
|
||||
console.log(response.body)
|
||||
|
||||
response = await client.search<SearchResponse<Source>, SearchBody>({
|
||||
index: 'test',
|
||||
// Here the body must follow the `SearchBody` interface
|
||||
body: {
|
||||
query: {
|
||||
match: { foo: 'bar' }
|
||||
}
|
||||
await client.index({
|
||||
index: 'game-of-thrones',
|
||||
document: {
|
||||
character: 'Tyrion Lannister',
|
||||
quote: 'A mind needs books like a sword needs a whetstone.'
|
||||
}
|
||||
})
|
||||
// body here is `SearchResponse<Source>`
|
||||
console.log(response.body)
|
||||
|
||||
// here we are forcing an index refresh, otherwise we will not
|
||||
// get any result in the consequent search
|
||||
await client.indices.refresh({ index: 'game-of-thrones' })
|
||||
|
||||
// Let's search!
|
||||
const result= await client.search<Document>({
|
||||
index: 'game-of-thrones',
|
||||
query: {
|
||||
match: { quote: 'winter' }
|
||||
}
|
||||
})
|
||||
|
||||
console.log(result.hits.hits)
|
||||
}
|
||||
|
||||
run().catch(console.log)
|
||||
----
|
||||
|
||||
[discrete]
|
||||
==== Request & Response types
|
||||
|
||||
You can import the full TypeScript requests & responses defintions as it follows:
|
||||
|
||||
[source,ts]
|
||||
----
|
||||
import { estypes } from '@elastic/elasticsearch'
|
||||
----
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@elastic/elasticsearch",
|
||||
"version": "8.0.0-beta.1",
|
||||
"version": "8.0.0",
|
||||
"versionCanary": "8.0.0-canary.37",
|
||||
"description": "The official Elasticsearch client for Node.js",
|
||||
"main": "index.js",
|
||||
@ -80,7 +80,7 @@
|
||||
"xmlbuilder2": "^3.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elastic/transport": "^8.0.0-beta.2",
|
||||
"@elastic/transport": "^8.0.2",
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"tap": {
|
||||
|
||||
@ -37,11 +37,11 @@ import * as T from '../types'
|
||||
import * as TB from '../typesWithBodyKey'
|
||||
interface That { transport: Transport }
|
||||
|
||||
export default async function BulkApi<TSource = unknown> (this: That, params: T.BulkRequest<TSource> | TB.BulkRequest<TSource>, options?: TransportRequestOptionsWithOutMeta): Promise<T.BulkResponse>
|
||||
export default async function BulkApi<TSource = unknown> (this: That, params: T.BulkRequest<TSource> | TB.BulkRequest<TSource>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.BulkResponse, unknown>>
|
||||
export default async function BulkApi<TSource = unknown> (this: That, params: T.BulkRequest<TSource> | TB.BulkRequest<TSource>, options?: TransportRequestOptions): Promise<T.BulkResponse>
|
||||
export default async function BulkApi<TSource = unknown> (this: That, params: T.BulkRequest<TSource> | TB.BulkRequest<TSource>, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index', 'type']
|
||||
export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument> | TB.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptionsWithOutMeta): Promise<T.BulkResponse>
|
||||
export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument> | TB.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.BulkResponse, unknown>>
|
||||
export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument> | TB.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<T.BulkResponse>
|
||||
export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument> | TB.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index']
|
||||
const acceptedBody: string[] = ['operations']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
@ -61,10 +61,7 @@ export default async function BulkApi<TSource = unknown> (this: That, params: T.
|
||||
|
||||
let method = ''
|
||||
let path = ''
|
||||
if (params.index != null && params.type != null) {
|
||||
method = 'POST'
|
||||
path = `/${encodeURIComponent(params.index.toString())}/${encodeURIComponent(params.type.toString())}/_bulk`
|
||||
} else if (params.index != null) {
|
||||
if (params.index != null) {
|
||||
method = 'POST'
|
||||
path = `/${encodeURIComponent(params.index.toString())}/_bulk`
|
||||
} else {
|
||||
|
||||
@ -41,7 +41,7 @@ export default async function CreateApi<TDocument = unknown> (this: That, params
|
||||
export default async function CreateApi<TDocument = unknown> (this: That, params: T.CreateRequest<TDocument> | TB.CreateRequest<TDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CreateResponse, unknown>>
|
||||
export default async function CreateApi<TDocument = unknown> (this: That, params: T.CreateRequest<TDocument> | TB.CreateRequest<TDocument>, options?: TransportRequestOptions): Promise<T.CreateResponse>
|
||||
export default async function CreateApi<TDocument = unknown> (this: That, params: T.CreateRequest<TDocument> | TB.CreateRequest<TDocument>, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['id', 'index', 'type']
|
||||
const acceptedPath: string[] = ['id', 'index']
|
||||
const acceptedBody: string[] = ['document']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
|
||||
@ -41,7 +41,7 @@ export default async function DeleteApi (this: That, params: T.DeleteRequest | T
|
||||
export default async function DeleteApi (this: That, params: T.DeleteRequest | TB.DeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.DeleteResponse, unknown>>
|
||||
export default async function DeleteApi (this: That, params: T.DeleteRequest | TB.DeleteRequest, options?: TransportRequestOptions): Promise<T.DeleteResponse>
|
||||
export default async function DeleteApi (this: That, params: T.DeleteRequest | TB.DeleteRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['id', 'index', 'type']
|
||||
const acceptedPath: string[] = ['id', 'index']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
|
||||
@ -114,7 +114,7 @@ export default class Eql {
|
||||
async search<TEvent = unknown> (this: That, params: T.EqlSearchRequest | TB.EqlSearchRequest, options?: TransportRequestOptions): Promise<T.EqlSearchResponse<TEvent>>
|
||||
async search<TEvent = unknown> (this: That, params: T.EqlSearchRequest | TB.EqlSearchRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index']
|
||||
const acceptedBody: string[] = ['query', 'case_sensitive', 'event_category_field', 'tiebreaker_field', 'timestamp_field', 'fetch_size', 'filter', 'keep_alive', 'keep_on_completion', 'wait_for_completion_timeout', 'size', 'fields', 'result_position']
|
||||
const acceptedBody: string[] = ['query', 'case_sensitive', 'event_category_field', 'tiebreaker_field', 'timestamp_field', 'fetch_size', 'filter', 'keep_alive', 'keep_on_completion', 'wait_for_completion_timeout', 'size', 'fields', 'result_position', 'runtime_mappings']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
|
||||
@ -41,7 +41,7 @@ export default async function ExistsSourceApi (this: That, params: T.ExistsSourc
|
||||
export default async function ExistsSourceApi (this: That, params: T.ExistsSourceRequest | TB.ExistsSourceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ExistsSourceResponse, unknown>>
|
||||
export default async function ExistsSourceApi (this: That, params: T.ExistsSourceRequest | TB.ExistsSourceRequest, options?: TransportRequestOptions): Promise<T.ExistsSourceResponse>
|
||||
export default async function ExistsSourceApi (this: That, params: T.ExistsSourceRequest | TB.ExistsSourceRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['id', 'index', 'type']
|
||||
const acceptedPath: string[] = ['id', 'index']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
|
||||
@ -65,19 +65,24 @@ export default class Fleet {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async msearch (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async msearch (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async msearch (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async msearch (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest | TB.FleetMsearchRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.FleetMsearchResponse<TDocument>>
|
||||
async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest | TB.FleetMsearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.FleetMsearchResponse<TDocument>, unknown>>
|
||||
async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest | TB.FleetMsearchRequest, options?: TransportRequestOptions): Promise<T.FleetMsearchResponse<TDocument>>
|
||||
async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest | TB.FleetMsearchRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index']
|
||||
const acceptedBody: string[] = ['searches']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
let body: any = params.body ?? undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
// @ts-expect-error
|
||||
body = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -94,19 +99,31 @@ export default class Fleet {
|
||||
return await this.transport.request({ path, method, querystring, bulkBody: body }, options)
|
||||
}
|
||||
|
||||
async search (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async search (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async search (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async search (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest | TB.FleetSearchRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.FleetSearchResponse<TDocument>>
|
||||
async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest | TB.FleetSearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.FleetSearchResponse<TDocument>, unknown>>
|
||||
async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest | TB.FleetSearchRequest, options?: TransportRequestOptions): Promise<T.FleetSearchResponse<TDocument>>
|
||||
async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest | TB.FleetSearchRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index']
|
||||
const acceptedBody: string[] = ['aggregations', 'aggs', 'collapse', 'explain', 'from', 'highlight', 'track_total_hits', 'indices_boost', 'docvalue_fields', 'min_score', 'post_filter', 'profile', 'query', 'rescore', 'script_fields', 'search_after', 'size', 'slice', 'sort', '_source', 'fields', 'suggest', 'terminate_after', 'timeout', 'track_scores', 'version', 'seq_no_primary_term', 'stored_fields', 'pit', 'runtime_mappings', 'stats']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,19 +140,32 @@ export default class Ilm {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async migrateToDataTiers (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async migrateToDataTiers (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async migrateToDataTiers (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async migrateToDataTiers (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest | TB.IlmMigrateToDataTiersRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.IlmMigrateToDataTiersResponse>
|
||||
async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest | TB.IlmMigrateToDataTiersRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmMigrateToDataTiersResponse, unknown>>
|
||||
async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest | TB.IlmMigrateToDataTiersRequest, options?: TransportRequestOptions): Promise<T.IlmMigrateToDataTiersResponse>
|
||||
async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest | TB.IlmMigrateToDataTiersRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['legacy_template_to_delete', 'node_attribute']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
|
||||
@ -513,11 +513,11 @@ export default class Indices {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async existsType (this: That, params: T.IndicesExistsTypeRequest | TB.IndicesExistsTypeRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.IndicesExistsTypeResponse>
|
||||
async existsType (this: That, params: T.IndicesExistsTypeRequest | TB.IndicesExistsTypeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesExistsTypeResponse, unknown>>
|
||||
async existsType (this: That, params: T.IndicesExistsTypeRequest | TB.IndicesExistsTypeRequest, options?: TransportRequestOptions): Promise<T.IndicesExistsTypeResponse>
|
||||
async existsType (this: That, params: T.IndicesExistsTypeRequest | TB.IndicesExistsTypeRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index', 'type']
|
||||
async fieldUsageStats (this: That, params: T.IndicesFieldUsageStatsRequest | TB.IndicesFieldUsageStatsRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.IndicesFieldUsageStatsResponse>
|
||||
async fieldUsageStats (this: That, params: T.IndicesFieldUsageStatsRequest | TB.IndicesFieldUsageStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesFieldUsageStatsResponse, unknown>>
|
||||
async fieldUsageStats (this: That, params: T.IndicesFieldUsageStatsRequest | TB.IndicesFieldUsageStatsRequest, options?: TransportRequestOptions): Promise<T.IndicesFieldUsageStatsResponse>
|
||||
async fieldUsageStats (this: That, params: T.IndicesFieldUsageStatsRequest | TB.IndicesFieldUsageStatsRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
@ -530,28 +530,6 @@ export default class Indices {
|
||||
}
|
||||
}
|
||||
|
||||
const method = 'HEAD'
|
||||
const path = `/${encodeURIComponent(params.index.toString())}/_mapping/${encodeURIComponent(params.type.toString())}`
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async fieldUsageStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async fieldUsageStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async fieldUsageStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async fieldUsageStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
|
||||
const method = 'GET'
|
||||
const path = `/${encodeURIComponent(params.index.toString())}/_field_usage_stats`
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
@ -1563,7 +1541,7 @@ export default class Indices {
|
||||
async validateQuery (this: That, params?: T.IndicesValidateQueryRequest | TB.IndicesValidateQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesValidateQueryResponse, unknown>>
|
||||
async validateQuery (this: That, params?: T.IndicesValidateQueryRequest | TB.IndicesValidateQueryRequest, options?: TransportRequestOptions): Promise<T.IndicesValidateQueryResponse>
|
||||
async validateQuery (this: That, params?: T.IndicesValidateQueryRequest | TB.IndicesValidateQueryRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index', 'type']
|
||||
const acceptedPath: string[] = ['index']
|
||||
const acceptedBody: string[] = ['query']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
|
||||
@ -135,10 +135,10 @@ export default class License {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async post (this: That, params?: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.LicensePostResponse>
|
||||
async post (this: That, params?: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicensePostResponse, unknown>>
|
||||
async post (this: That, params?: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptions): Promise<T.LicensePostResponse>
|
||||
async post (this: That, params?: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
async post (this: That, params: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.LicensePostResponse>
|
||||
async post (this: That, params: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicensePostResponse, unknown>>
|
||||
async post (this: That, params: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptions): Promise<T.LicensePostResponse>
|
||||
async post (this: That, params: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['license', 'licenses']
|
||||
const querystring: Record<string, any> = {}
|
||||
@ -151,7 +151,6 @@ export default class License {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
|
||||
@ -73,10 +73,10 @@ export default class Migration {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async getFeatureUpgradeStatus (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async getFeatureUpgradeStatus (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async getFeatureUpgradeStatus (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async getFeatureUpgradeStatus (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async getFeatureUpgradeStatus (this: That, params?: T.MigrationGetFeatureUpgradeStatusRequest | TB.MigrationGetFeatureUpgradeStatusRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MigrationGetFeatureUpgradeStatusResponse>
|
||||
async getFeatureUpgradeStatus (this: That, params?: T.MigrationGetFeatureUpgradeStatusRequest | TB.MigrationGetFeatureUpgradeStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MigrationGetFeatureUpgradeStatusResponse, unknown>>
|
||||
async getFeatureUpgradeStatus (this: That, params?: T.MigrationGetFeatureUpgradeStatusRequest | TB.MigrationGetFeatureUpgradeStatusRequest, options?: TransportRequestOptions): Promise<T.MigrationGetFeatureUpgradeStatusResponse>
|
||||
async getFeatureUpgradeStatus (this: That, params?: T.MigrationGetFeatureUpgradeStatusRequest | TB.MigrationGetFeatureUpgradeStatusRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
@ -86,6 +86,7 @@ export default class Migration {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -95,10 +96,10 @@ export default class Migration {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async postFeatureUpgrade (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async postFeatureUpgrade (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async postFeatureUpgrade (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async postFeatureUpgrade (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async postFeatureUpgrade (this: That, params?: T.MigrationPostFeatureUpgradeRequest | TB.MigrationPostFeatureUpgradeRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MigrationPostFeatureUpgradeResponse>
|
||||
async postFeatureUpgrade (this: That, params?: T.MigrationPostFeatureUpgradeRequest | TB.MigrationPostFeatureUpgradeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MigrationPostFeatureUpgradeResponse, unknown>>
|
||||
async postFeatureUpgrade (this: That, params?: T.MigrationPostFeatureUpgradeRequest | TB.MigrationPostFeatureUpgradeRequest, options?: TransportRequestOptions): Promise<T.MigrationPostFeatureUpgradeResponse>
|
||||
async postFeatureUpgrade (this: That, params?: T.MigrationPostFeatureUpgradeRequest | TB.MigrationPostFeatureUpgradeRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
@ -108,6 +109,7 @@ export default class Migration {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
|
||||
@ -937,6 +937,28 @@ export default class Ml {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async getModelSnapshotUpgradeStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async getModelSnapshotUpgradeStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async getModelSnapshotUpgradeStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async getModelSnapshotUpgradeStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['job_id', 'snapshot_id']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
|
||||
const method = 'GET'
|
||||
const path = `/_ml/anomaly_detectors/${encodeURIComponent(params.job_id.toString())}/model_snapshots/${encodeURIComponent(params.snapshot_id.toString())}/_upgrade/_stats`
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async getModelSnapshots (this: That, params: T.MlGetModelSnapshotsRequest | TB.MlGetModelSnapshotsRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MlGetModelSnapshotsResponse>
|
||||
async getModelSnapshots (this: That, params: T.MlGetModelSnapshotsRequest | TB.MlGetModelSnapshotsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetModelSnapshotsResponse, unknown>>
|
||||
async getModelSnapshots (this: That, params: T.MlGetModelSnapshotsRequest | TB.MlGetModelSnapshotsRequest, options?: TransportRequestOptions): Promise<T.MlGetModelSnapshotsResponse>
|
||||
@ -1106,19 +1128,31 @@ export default class Ml {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async inferTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async inferTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async inferTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async inferTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async inferTrainedModelDeployment (this: That, params: T.MlInferTrainedModelDeploymentRequest | TB.MlInferTrainedModelDeploymentRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MlInferTrainedModelDeploymentResponse>
|
||||
async inferTrainedModelDeployment (this: That, params: T.MlInferTrainedModelDeploymentRequest | TB.MlInferTrainedModelDeploymentRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlInferTrainedModelDeploymentResponse, unknown>>
|
||||
async inferTrainedModelDeployment (this: That, params: T.MlInferTrainedModelDeploymentRequest | TB.MlInferTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<T.MlInferTrainedModelDeploymentResponse>
|
||||
async inferTrainedModelDeployment (this: That, params: T.MlInferTrainedModelDeploymentRequest | TB.MlInferTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['model_id']
|
||||
const acceptedBody: string[] = ['docs']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1391,7 +1425,7 @@ export default class Ml {
|
||||
async putDataFrameAnalytics (this: That, params: T.MlPutDataFrameAnalyticsRequest | TB.MlPutDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<T.MlPutDataFrameAnalyticsResponse>
|
||||
async putDataFrameAnalytics (this: That, params: T.MlPutDataFrameAnalyticsRequest | TB.MlPutDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['id']
|
||||
const acceptedBody: string[] = ['allow_lazy_start', 'analysis', 'analyzed_fields', 'description', 'dest', 'max_num_threads', 'model_memory_limit', 'source']
|
||||
const acceptedBody: string[] = ['allow_lazy_start', 'analysis', 'analyzed_fields', 'description', 'dest', 'max_num_threads', 'model_memory_limit', 'source', 'headers', 'version']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
@ -1425,7 +1459,7 @@ export default class Ml {
|
||||
async putDatafeed (this: That, params: T.MlPutDatafeedRequest | TB.MlPutDatafeedRequest, options?: TransportRequestOptions): Promise<T.MlPutDatafeedResponse>
|
||||
async putDatafeed (this: That, params: T.MlPutDatafeedRequest | TB.MlPutDatafeedRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['datafeed_id']
|
||||
const acceptedBody: string[] = ['aggregations', 'chunking_config', 'delayed_data_check_config', 'frequency', 'indices', 'indexes', 'indices_options', 'job_id', 'max_empty_searches', 'query', 'query_delay', 'runtime_mappings', 'script_fields', 'scroll_size']
|
||||
const acceptedBody: string[] = ['aggregations', 'chunking_config', 'delayed_data_check_config', 'frequency', 'indices', 'indexes', 'indices_options', 'job_id', 'max_empty_searches', 'query', 'query_delay', 'runtime_mappings', 'script_fields', 'scroll_size', 'headers']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
@ -1527,7 +1561,7 @@ export default class Ml {
|
||||
async putTrainedModel (this: That, params: T.MlPutTrainedModelRequest | TB.MlPutTrainedModelRequest, options?: TransportRequestOptions): Promise<T.MlPutTrainedModelResponse>
|
||||
async putTrainedModel (this: That, params: T.MlPutTrainedModelRequest | TB.MlPutTrainedModelRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['model_id']
|
||||
const acceptedBody: string[] = ['compressed_definition', 'definition', 'description', 'inference_config', 'input', 'metadata', 'model_type', 'tags']
|
||||
const acceptedBody: string[] = ['compressed_definition', 'definition', 'description', 'inference_config', 'input', 'metadata', 'model_type', 'model_size_bytes', 'tags']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
@ -1578,19 +1612,31 @@ export default class Ml {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async putTrainedModelDefinitionPart (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async putTrainedModelDefinitionPart (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async putTrainedModelDefinitionPart (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async putTrainedModelDefinitionPart (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async putTrainedModelDefinitionPart (this: That, params: T.MlPutTrainedModelDefinitionPartRequest | TB.MlPutTrainedModelDefinitionPartRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MlPutTrainedModelDefinitionPartResponse>
|
||||
async putTrainedModelDefinitionPart (this: That, params: T.MlPutTrainedModelDefinitionPartRequest | TB.MlPutTrainedModelDefinitionPartRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutTrainedModelDefinitionPartResponse, unknown>>
|
||||
async putTrainedModelDefinitionPart (this: That, params: T.MlPutTrainedModelDefinitionPartRequest | TB.MlPutTrainedModelDefinitionPartRequest, options?: TransportRequestOptions): Promise<T.MlPutTrainedModelDefinitionPartResponse>
|
||||
async putTrainedModelDefinitionPart (this: That, params: T.MlPutTrainedModelDefinitionPartRequest | TB.MlPutTrainedModelDefinitionPartRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['model_id', 'part']
|
||||
const acceptedBody: string[] = ['definition', 'total_definition_length', 'total_parts']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1600,19 +1646,31 @@ export default class Ml {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async putTrainedModelVocabulary (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async putTrainedModelVocabulary (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async putTrainedModelVocabulary (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async putTrainedModelVocabulary (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async putTrainedModelVocabulary (this: That, params: T.MlPutTrainedModelVocabularyRequest | TB.MlPutTrainedModelVocabularyRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MlPutTrainedModelVocabularyResponse>
|
||||
async putTrainedModelVocabulary (this: That, params: T.MlPutTrainedModelVocabularyRequest | TB.MlPutTrainedModelVocabularyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutTrainedModelVocabularyResponse, unknown>>
|
||||
async putTrainedModelVocabulary (this: That, params: T.MlPutTrainedModelVocabularyRequest | TB.MlPutTrainedModelVocabularyRequest, options?: TransportRequestOptions): Promise<T.MlPutTrainedModelVocabularyResponse>
|
||||
async putTrainedModelVocabulary (this: That, params: T.MlPutTrainedModelVocabularyRequest | TB.MlPutTrainedModelVocabularyRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['model_id']
|
||||
const acceptedBody: string[] = ['vocabulary']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1757,19 +1815,19 @@ export default class Ml {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async startTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async startTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async startTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async startTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async startTrainedModelDeployment (this: That, params: T.MlStartTrainedModelDeploymentRequest | TB.MlStartTrainedModelDeploymentRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MlStartTrainedModelDeploymentResponse>
|
||||
async startTrainedModelDeployment (this: That, params: T.MlStartTrainedModelDeploymentRequest | TB.MlStartTrainedModelDeploymentRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlStartTrainedModelDeploymentResponse, unknown>>
|
||||
async startTrainedModelDeployment (this: That, params: T.MlStartTrainedModelDeploymentRequest | TB.MlStartTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<T.MlStartTrainedModelDeploymentResponse>
|
||||
async startTrainedModelDeployment (this: That, params: T.MlStartTrainedModelDeploymentRequest | TB.MlStartTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['model_id']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1835,19 +1893,19 @@ export default class Ml {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async stopTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async stopTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async stopTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async stopTrainedModelDeployment (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async stopTrainedModelDeployment (this: That, params: T.MlStopTrainedModelDeploymentRequest | TB.MlStopTrainedModelDeploymentRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MlStopTrainedModelDeploymentResponse>
|
||||
async stopTrainedModelDeployment (this: That, params: T.MlStopTrainedModelDeploymentRequest | TB.MlStopTrainedModelDeploymentRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlStopTrainedModelDeploymentResponse, unknown>>
|
||||
async stopTrainedModelDeployment (this: That, params: T.MlStopTrainedModelDeploymentRequest | TB.MlStopTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<T.MlStopTrainedModelDeploymentResponse>
|
||||
async stopTrainedModelDeployment (this: That, params: T.MlStopTrainedModelDeploymentRequest | TB.MlStopTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['model_id']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -2054,7 +2112,7 @@ export default class Ml {
|
||||
async validate (this: That, params?: T.MlValidateRequest | TB.MlValidateRequest, options?: TransportRequestOptions): Promise<T.MlValidateResponse>
|
||||
async validate (this: That, params?: T.MlValidateRequest | TB.MlValidateRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['job_id', 'analysis_config', 'analysis_limits', 'data_description', 'description', 'model_plot', 'model_snapshot_retention_days', 'results_index_name']
|
||||
const acceptedBody: string[] = ['job_id', 'analysis_config', 'analysis_limits', 'data_description', 'description', 'model_plot', 'model_snapshot_id', 'model_snapshot_retention_days', 'results_index_name']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
|
||||
@ -43,10 +43,10 @@ export default class Monitoring {
|
||||
this.transport = transport
|
||||
}
|
||||
|
||||
async bulk<TSource = unknown> (this: That, params: T.MonitoringBulkRequest<TSource> | TB.MonitoringBulkRequest<TSource>, options?: TransportRequestOptionsWithOutMeta): Promise<T.MonitoringBulkResponse>
|
||||
async bulk<TSource = unknown> (this: That, params: T.MonitoringBulkRequest<TSource> | TB.MonitoringBulkRequest<TSource>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MonitoringBulkResponse, unknown>>
|
||||
async bulk<TSource = unknown> (this: That, params: T.MonitoringBulkRequest<TSource> | TB.MonitoringBulkRequest<TSource>, options?: TransportRequestOptions): Promise<T.MonitoringBulkResponse>
|
||||
async bulk<TSource = unknown> (this: That, params: T.MonitoringBulkRequest<TSource> | TB.MonitoringBulkRequest<TSource>, options?: TransportRequestOptions): Promise<any> {
|
||||
async bulk<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.MonitoringBulkRequest<TDocument, TPartialDocument> | TB.MonitoringBulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptionsWithOutMeta): Promise<T.MonitoringBulkResponse>
|
||||
async bulk<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.MonitoringBulkRequest<TDocument, TPartialDocument> | TB.MonitoringBulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MonitoringBulkResponse, unknown>>
|
||||
async bulk<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.MonitoringBulkRequest<TDocument, TPartialDocument> | TB.MonitoringBulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<T.MonitoringBulkResponse>
|
||||
async bulk<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.MonitoringBulkRequest<TDocument, TPartialDocument> | TB.MonitoringBulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['type']
|
||||
const acceptedBody: string[] = ['operations']
|
||||
const querystring: Record<string, any> = {}
|
||||
|
||||
@ -37,10 +37,10 @@ import * as T from '../types'
|
||||
import * as TB from '../typesWithBodyKey'
|
||||
interface That { transport: Transport }
|
||||
|
||||
export default async function MsearchApi<TDocument = unknown> (this: That, params: T.MsearchRequest | TB.MsearchRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MsearchResponse<TDocument>>
|
||||
export default async function MsearchApi<TDocument = unknown> (this: That, params: T.MsearchRequest | TB.MsearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MsearchResponse<TDocument>, unknown>>
|
||||
export default async function MsearchApi<TDocument = unknown> (this: That, params: T.MsearchRequest | TB.MsearchRequest, options?: TransportRequestOptions): Promise<T.MsearchResponse<TDocument>>
|
||||
export default async function MsearchApi<TDocument = unknown> (this: That, params: T.MsearchRequest | TB.MsearchRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
export default async function MsearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchRequest | TB.MsearchRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MsearchResponse<TDocument, TAggregations>>
|
||||
export default async function MsearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchRequest | TB.MsearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MsearchResponse<TDocument, TAggregations>, unknown>>
|
||||
export default async function MsearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchRequest | TB.MsearchRequest, options?: TransportRequestOptions): Promise<T.MsearchResponse<TDocument, TAggregations>>
|
||||
export default async function MsearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchRequest | TB.MsearchRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index']
|
||||
const acceptedBody: string[] = ['searches']
|
||||
const querystring: Record<string, any> = {}
|
||||
|
||||
@ -37,10 +37,10 @@ import * as T from '../types'
|
||||
import * as TB from '../typesWithBodyKey'
|
||||
interface That { transport: Transport }
|
||||
|
||||
export default async function MsearchTemplateApi<TDocument = unknown> (this: That, params: T.MsearchTemplateRequest | TB.MsearchTemplateRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MsearchTemplateResponse<TDocument>>
|
||||
export default async function MsearchTemplateApi<TDocument = unknown> (this: That, params: T.MsearchTemplateRequest | TB.MsearchTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MsearchTemplateResponse<TDocument>, unknown>>
|
||||
export default async function MsearchTemplateApi<TDocument = unknown> (this: That, params: T.MsearchTemplateRequest | TB.MsearchTemplateRequest, options?: TransportRequestOptions): Promise<T.MsearchTemplateResponse<TDocument>>
|
||||
export default async function MsearchTemplateApi<TDocument = unknown> (this: That, params: T.MsearchTemplateRequest | TB.MsearchTemplateRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
export default async function MsearchTemplateApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchTemplateRequest | TB.MsearchTemplateRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.MsearchTemplateResponse<TDocument, TAggregations>>
|
||||
export default async function MsearchTemplateApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchTemplateRequest | TB.MsearchTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MsearchTemplateResponse<TDocument, TAggregations>, unknown>>
|
||||
export default async function MsearchTemplateApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchTemplateRequest | TB.MsearchTemplateRequest, options?: TransportRequestOptions): Promise<T.MsearchTemplateResponse<TDocument, TAggregations>>
|
||||
export default async function MsearchTemplateApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchTemplateRequest | TB.MsearchTemplateRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index']
|
||||
const acceptedBody: string[] = ['search_templates']
|
||||
const querystring: Record<string, any> = {}
|
||||
|
||||
@ -43,19 +43,19 @@ export default class Nodes {
|
||||
this.transport = transport
|
||||
}
|
||||
|
||||
async clearRepositoriesMeteringArchive (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async clearRepositoriesMeteringArchive (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async clearRepositoriesMeteringArchive (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async clearRepositoriesMeteringArchive (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async clearRepositoriesMeteringArchive (this: That, params: T.NodesClearRepositoriesMeteringArchiveRequest | TB.NodesClearRepositoriesMeteringArchiveRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.NodesClearRepositoriesMeteringArchiveResponse>
|
||||
async clearRepositoriesMeteringArchive (this: That, params: T.NodesClearRepositoriesMeteringArchiveRequest | TB.NodesClearRepositoriesMeteringArchiveRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.NodesClearRepositoriesMeteringArchiveResponse, unknown>>
|
||||
async clearRepositoriesMeteringArchive (this: That, params: T.NodesClearRepositoriesMeteringArchiveRequest | TB.NodesClearRepositoriesMeteringArchiveRequest, options?: TransportRequestOptions): Promise<T.NodesClearRepositoriesMeteringArchiveResponse>
|
||||
async clearRepositoriesMeteringArchive (this: That, params: T.NodesClearRepositoriesMeteringArchiveRequest | TB.NodesClearRepositoriesMeteringArchiveRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['node_id', 'max_archive_version']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -65,19 +65,19 @@ export default class Nodes {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async getRepositoriesMeteringInfo (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async getRepositoriesMeteringInfo (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async getRepositoriesMeteringInfo (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async getRepositoriesMeteringInfo (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async getRepositoriesMeteringInfo (this: That, params: T.NodesGetRepositoriesMeteringInfoRequest | TB.NodesGetRepositoriesMeteringInfoRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.NodesGetRepositoriesMeteringInfoResponse>
|
||||
async getRepositoriesMeteringInfo (this: That, params: T.NodesGetRepositoriesMeteringInfoRequest | TB.NodesGetRepositoriesMeteringInfoRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.NodesGetRepositoriesMeteringInfoResponse, unknown>>
|
||||
async getRepositoriesMeteringInfo (this: That, params: T.NodesGetRepositoriesMeteringInfoRequest | TB.NodesGetRepositoriesMeteringInfoRequest, options?: TransportRequestOptions): Promise<T.NodesGetRepositoriesMeteringInfoResponse>
|
||||
async getRepositoriesMeteringInfo (this: That, params: T.NodesGetRepositoriesMeteringInfoRequest | TB.NodesGetRepositoriesMeteringInfoRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['node_id']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ export default class Rollup {
|
||||
async putJob (this: That, params: T.RollupPutJobRequest | TB.RollupPutJobRequest, options?: TransportRequestOptions): Promise<T.RollupPutJobResponse>
|
||||
async putJob (this: That, params: T.RollupPutJobRequest | TB.RollupPutJobRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['id']
|
||||
const acceptedBody: string[] = ['cron', 'groups', 'index_pattern', 'metrics', 'page_size', 'rollup_index']
|
||||
const acceptedBody: string[] = ['cron', 'groups', 'index_pattern', 'metrics', 'page_size', 'rollup_index', 'timeout', 'headers']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
@ -208,11 +208,11 @@ export default class Rollup {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async rollupSearch<TDocument = unknown> (this: That, params: T.RollupRollupSearchRequest | TB.RollupRollupSearchRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.RollupRollupSearchResponse<TDocument>>
|
||||
async rollupSearch<TDocument = unknown> (this: That, params: T.RollupRollupSearchRequest | TB.RollupRollupSearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RollupRollupSearchResponse<TDocument>, unknown>>
|
||||
async rollupSearch<TDocument = unknown> (this: That, params: T.RollupRollupSearchRequest | TB.RollupRollupSearchRequest, options?: TransportRequestOptions): Promise<T.RollupRollupSearchResponse<TDocument>>
|
||||
async rollupSearch<TDocument = unknown> (this: That, params: T.RollupRollupSearchRequest | TB.RollupRollupSearchRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index', 'type']
|
||||
async rollupSearch<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.RollupRollupSearchRequest | TB.RollupRollupSearchRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.RollupRollupSearchResponse<TDocument, TAggregations>>
|
||||
async rollupSearch<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.RollupRollupSearchRequest | TB.RollupRollupSearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RollupRollupSearchResponse<TDocument, TAggregations>, unknown>>
|
||||
async rollupSearch<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.RollupRollupSearchRequest | TB.RollupRollupSearchRequest, options?: TransportRequestOptions): Promise<T.RollupRollupSearchResponse<TDocument, TAggregations>>
|
||||
async rollupSearch<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.RollupRollupSearchRequest | TB.RollupRollupSearchRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index']
|
||||
const acceptedBody: string[] = ['aggregations', 'aggs', 'query', 'size']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
|
||||
@ -37,10 +37,10 @@ import * as T from '../types'
|
||||
import * as TB from '../typesWithBodyKey'
|
||||
interface That { transport: Transport }
|
||||
|
||||
export default async function ScrollApi<TDocument = unknown> (this: That, params: T.ScrollRequest | TB.ScrollRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.ScrollResponse<TDocument>>
|
||||
export default async function ScrollApi<TDocument = unknown> (this: That, params: T.ScrollRequest | TB.ScrollRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ScrollResponse<TDocument>, unknown>>
|
||||
export default async function ScrollApi<TDocument = unknown> (this: That, params: T.ScrollRequest | TB.ScrollRequest, options?: TransportRequestOptions): Promise<T.ScrollResponse<TDocument>>
|
||||
export default async function ScrollApi<TDocument = unknown> (this: That, params: T.ScrollRequest | TB.ScrollRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
export default async function ScrollApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.ScrollRequest | TB.ScrollRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.ScrollResponse<TDocument, TAggregations>>
|
||||
export default async function ScrollApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.ScrollRequest | TB.ScrollRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ScrollResponse<TDocument, TAggregations>, unknown>>
|
||||
export default async function ScrollApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.ScrollRequest | TB.ScrollRequest, options?: TransportRequestOptions): Promise<T.ScrollResponse<TDocument, TAggregations>>
|
||||
export default async function ScrollApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.ScrollRequest | TB.ScrollRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['scroll', 'scroll_id']
|
||||
const querystring: Record<string, any> = {}
|
||||
|
||||
@ -37,10 +37,10 @@ import * as T from '../types'
|
||||
import * as TB from '../typesWithBodyKey'
|
||||
interface That { transport: Transport }
|
||||
|
||||
export default async function SearchApi<TDocument = unknown> (this: That, params?: T.SearchRequest | TB.SearchRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SearchResponse<TDocument>>
|
||||
export default async function SearchApi<TDocument = unknown> (this: That, params?: T.SearchRequest | TB.SearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchResponse<TDocument>, unknown>>
|
||||
export default async function SearchApi<TDocument = unknown> (this: That, params?: T.SearchRequest | TB.SearchRequest, options?: TransportRequestOptions): Promise<T.SearchResponse<TDocument>>
|
||||
export default async function SearchApi<TDocument = unknown> (this: That, params?: T.SearchRequest | TB.SearchRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
export default async function SearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params?: T.SearchRequest | TB.SearchRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SearchResponse<TDocument, TAggregations>>
|
||||
export default async function SearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params?: T.SearchRequest | TB.SearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchResponse<TDocument, TAggregations>, unknown>>
|
||||
export default async function SearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params?: T.SearchRequest | TB.SearchRequest, options?: TransportRequestOptions): Promise<T.SearchResponse<TDocument, TAggregations>>
|
||||
export default async function SearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params?: T.SearchRequest | TB.SearchRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index']
|
||||
const acceptedBody: string[] = ['aggregations', 'aggs', 'collapse', 'explain', 'from', 'highlight', 'track_total_hits', 'indices_boost', 'docvalue_fields', 'min_score', 'post_filter', 'profile', 'query', 'rescore', 'script_fields', 'search_after', 'size', 'slice', 'sort', '_source', 'fields', 'suggest', 'terminate_after', 'timeout', 'track_scores', 'version', 'seq_no_primary_term', 'stored_fields', 'pit', 'runtime_mappings', 'stats']
|
||||
const querystring: Record<string, any> = {}
|
||||
|
||||
@ -42,7 +42,7 @@ export default async function SearchMvtApi (this: That, params: T.SearchMvtReque
|
||||
export default async function SearchMvtApi (this: That, params: T.SearchMvtRequest | TB.SearchMvtRequest, options?: TransportRequestOptions): Promise<T.SearchMvtResponse>
|
||||
export default async function SearchMvtApi (this: That, params: T.SearchMvtRequest | TB.SearchMvtRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['index', 'field', 'zoom', 'x', 'y']
|
||||
const acceptedBody: string[] = ['aggs', 'exact_bounds', 'extent', 'fields', 'grid_precision', 'grid_type', 'query', 'runtime_mappings', 'size', 'sort']
|
||||
const acceptedBody: string[] = ['aggs', 'exact_bounds', 'extent', 'fields', 'grid_precision', 'grid_type', 'query', 'runtime_mappings', 'size', 'sort', 'track_total_hits']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
|
||||
@ -43,10 +43,10 @@ export default class SearchableSnapshots {
|
||||
this.transport = transport
|
||||
}
|
||||
|
||||
async cacheStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async cacheStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async cacheStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async cacheStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async cacheStats (this: That, params?: T.SearchableSnapshotsCacheStatsRequest | TB.SearchableSnapshotsCacheStatsRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SearchableSnapshotsCacheStatsResponse>
|
||||
async cacheStats (this: That, params?: T.SearchableSnapshotsCacheStatsRequest | TB.SearchableSnapshotsCacheStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchableSnapshotsCacheStatsResponse, unknown>>
|
||||
async cacheStats (this: That, params?: T.SearchableSnapshotsCacheStatsRequest | TB.SearchableSnapshotsCacheStatsRequest, options?: TransportRequestOptions): Promise<T.SearchableSnapshotsCacheStatsResponse>
|
||||
async cacheStats (this: That, params?: T.SearchableSnapshotsCacheStatsRequest | TB.SearchableSnapshotsCacheStatsRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['node_id']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
@ -56,6 +56,7 @@ export default class SearchableSnapshots {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
|
||||
@ -436,10 +436,10 @@ export default class Security {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async enrollKibana (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async enrollKibana (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async enrollKibana (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async enrollKibana (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async enrollKibana (this: That, params?: T.SecurityEnrollKibanaRequest | TB.SecurityEnrollKibanaRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SecurityEnrollKibanaResponse>
|
||||
async enrollKibana (this: That, params?: T.SecurityEnrollKibanaRequest | TB.SecurityEnrollKibanaRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityEnrollKibanaResponse, unknown>>
|
||||
async enrollKibana (this: That, params?: T.SecurityEnrollKibanaRequest | TB.SecurityEnrollKibanaRequest, options?: TransportRequestOptions): Promise<T.SecurityEnrollKibanaResponse>
|
||||
async enrollKibana (this: That, params?: T.SecurityEnrollKibanaRequest | TB.SecurityEnrollKibanaRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
@ -449,6 +449,7 @@ export default class Security {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -458,10 +459,10 @@ export default class Security {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async enrollNode (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async enrollNode (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async enrollNode (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async enrollNode (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async enrollNode (this: That, params?: T.SecurityEnrollNodeRequest | TB.SecurityEnrollNodeRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SecurityEnrollNodeResponse>
|
||||
async enrollNode (this: That, params?: T.SecurityEnrollNodeRequest | TB.SecurityEnrollNodeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityEnrollNodeResponse, unknown>>
|
||||
async enrollNode (this: That, params?: T.SecurityEnrollNodeRequest | TB.SecurityEnrollNodeRequest, options?: TransportRequestOptions): Promise<T.SecurityEnrollNodeResponse>
|
||||
async enrollNode (this: That, params?: T.SecurityEnrollNodeRequest | TB.SecurityEnrollNodeRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
@ -471,6 +472,7 @@ export default class Security {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1037,19 +1039,32 @@ export default class Security {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async queryApiKeys (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async queryApiKeys (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async queryApiKeys (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async queryApiKeys (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async queryApiKeys (this: That, params?: T.SecurityQueryApiKeysRequest | TB.SecurityQueryApiKeysRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SecurityQueryApiKeysResponse>
|
||||
async queryApiKeys (this: That, params?: T.SecurityQueryApiKeysRequest | TB.SecurityQueryApiKeysRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityQueryApiKeysResponse, unknown>>
|
||||
async queryApiKeys (this: That, params?: T.SecurityQueryApiKeysRequest | TB.SecurityQueryApiKeysRequest, options?: TransportRequestOptions): Promise<T.SecurityQueryApiKeysResponse>
|
||||
async queryApiKeys (this: That, params?: T.SecurityQueryApiKeysRequest | TB.SecurityQueryApiKeysRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['query', 'from', 'sort', 'size', 'search_after']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1059,19 +1074,31 @@ export default class Security {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async samlAuthenticate (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async samlAuthenticate (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async samlAuthenticate (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async samlAuthenticate (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async samlAuthenticate (this: That, params: T.SecuritySamlAuthenticateRequest | TB.SecuritySamlAuthenticateRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SecuritySamlAuthenticateResponse>
|
||||
async samlAuthenticate (this: That, params: T.SecuritySamlAuthenticateRequest | TB.SecuritySamlAuthenticateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlAuthenticateResponse, unknown>>
|
||||
async samlAuthenticate (this: That, params: T.SecuritySamlAuthenticateRequest | TB.SecuritySamlAuthenticateRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlAuthenticateResponse>
|
||||
async samlAuthenticate (this: That, params: T.SecuritySamlAuthenticateRequest | TB.SecuritySamlAuthenticateRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['content', 'ids', 'realm']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1081,19 +1108,31 @@ export default class Security {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async samlCompleteLogout (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async samlCompleteLogout (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async samlCompleteLogout (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async samlCompleteLogout (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async samlCompleteLogout (this: That, params: T.SecuritySamlCompleteLogoutRequest | TB.SecuritySamlCompleteLogoutRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SecuritySamlCompleteLogoutResponse>
|
||||
async samlCompleteLogout (this: That, params: T.SecuritySamlCompleteLogoutRequest | TB.SecuritySamlCompleteLogoutRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlCompleteLogoutResponse, unknown>>
|
||||
async samlCompleteLogout (this: That, params: T.SecuritySamlCompleteLogoutRequest | TB.SecuritySamlCompleteLogoutRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlCompleteLogoutResponse>
|
||||
async samlCompleteLogout (this: That, params: T.SecuritySamlCompleteLogoutRequest | TB.SecuritySamlCompleteLogoutRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['realm', 'ids', 'query_string', 'content']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1103,19 +1142,31 @@ export default class Security {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async samlInvalidate (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async samlInvalidate (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async samlInvalidate (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async samlInvalidate (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async samlInvalidate (this: That, params: T.SecuritySamlInvalidateRequest | TB.SecuritySamlInvalidateRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SecuritySamlInvalidateResponse>
|
||||
async samlInvalidate (this: That, params: T.SecuritySamlInvalidateRequest | TB.SecuritySamlInvalidateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlInvalidateResponse, unknown>>
|
||||
async samlInvalidate (this: That, params: T.SecuritySamlInvalidateRequest | TB.SecuritySamlInvalidateRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlInvalidateResponse>
|
||||
async samlInvalidate (this: That, params: T.SecuritySamlInvalidateRequest | TB.SecuritySamlInvalidateRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['acs', 'query_string', 'realm']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1125,19 +1176,31 @@ export default class Security {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async samlLogout (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async samlLogout (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async samlLogout (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async samlLogout (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async samlLogout (this: That, params: T.SecuritySamlLogoutRequest | TB.SecuritySamlLogoutRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SecuritySamlLogoutResponse>
|
||||
async samlLogout (this: That, params: T.SecuritySamlLogoutRequest | TB.SecuritySamlLogoutRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlLogoutResponse, unknown>>
|
||||
async samlLogout (this: That, params: T.SecuritySamlLogoutRequest | TB.SecuritySamlLogoutRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlLogoutResponse>
|
||||
async samlLogout (this: That, params: T.SecuritySamlLogoutRequest | TB.SecuritySamlLogoutRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['token', 'refresh_token']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1147,19 +1210,32 @@ export default class Security {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async samlPrepareAuthentication (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async samlPrepareAuthentication (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async samlPrepareAuthentication (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async samlPrepareAuthentication (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async samlPrepareAuthentication (this: That, params?: T.SecuritySamlPrepareAuthenticationRequest | TB.SecuritySamlPrepareAuthenticationRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SecuritySamlPrepareAuthenticationResponse>
|
||||
async samlPrepareAuthentication (this: That, params?: T.SecuritySamlPrepareAuthenticationRequest | TB.SecuritySamlPrepareAuthenticationRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlPrepareAuthenticationResponse, unknown>>
|
||||
async samlPrepareAuthentication (this: That, params?: T.SecuritySamlPrepareAuthenticationRequest | TB.SecuritySamlPrepareAuthenticationRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlPrepareAuthenticationResponse>
|
||||
async samlPrepareAuthentication (this: That, params?: T.SecuritySamlPrepareAuthenticationRequest | TB.SecuritySamlPrepareAuthenticationRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['acs', 'realm', 'relay_state']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
let body: Record<string, any> | string
|
||||
if (typeof userBody === 'string') {
|
||||
body = userBody
|
||||
} else {
|
||||
body = userBody != null ? { ...userBody } : undefined
|
||||
}
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
if (acceptedBody.includes(key)) {
|
||||
body = body ?? {}
|
||||
// @ts-expect-error
|
||||
body[key] = params[key]
|
||||
} else if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -1169,19 +1245,19 @@ export default class Security {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async samlServiceProviderMetadata (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async samlServiceProviderMetadata (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async samlServiceProviderMetadata (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async samlServiceProviderMetadata (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async samlServiceProviderMetadata (this: That, params: T.SecuritySamlServiceProviderMetadataRequest | TB.SecuritySamlServiceProviderMetadataRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SecuritySamlServiceProviderMetadataResponse>
|
||||
async samlServiceProviderMetadata (this: That, params: T.SecuritySamlServiceProviderMetadataRequest | TB.SecuritySamlServiceProviderMetadataRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlServiceProviderMetadataResponse, unknown>>
|
||||
async samlServiceProviderMetadata (this: That, params: T.SecuritySamlServiceProviderMetadataRequest | TB.SecuritySamlServiceProviderMetadataRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlServiceProviderMetadataResponse>
|
||||
async samlServiceProviderMetadata (this: That, params: T.SecuritySamlServiceProviderMetadataRequest | TB.SecuritySamlServiceProviderMetadataRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['realm_name']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,19 +77,19 @@ export default class Sql {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async deleteAsync (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async deleteAsync (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async deleteAsync (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async deleteAsync (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async deleteAsync (this: That, params: T.SqlDeleteAsyncRequest | TB.SqlDeleteAsyncRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SqlDeleteAsyncResponse>
|
||||
async deleteAsync (this: That, params: T.SqlDeleteAsyncRequest | TB.SqlDeleteAsyncRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SqlDeleteAsyncResponse, unknown>>
|
||||
async deleteAsync (this: That, params: T.SqlDeleteAsyncRequest | TB.SqlDeleteAsyncRequest, options?: TransportRequestOptions): Promise<T.SqlDeleteAsyncResponse>
|
||||
async deleteAsync (this: That, params: T.SqlDeleteAsyncRequest | TB.SqlDeleteAsyncRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['id']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -99,19 +99,19 @@ export default class Sql {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async getAsync (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async getAsync (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async getAsync (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async getAsync (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async getAsync (this: That, params: T.SqlGetAsyncRequest | TB.SqlGetAsyncRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SqlGetAsyncResponse>
|
||||
async getAsync (this: That, params: T.SqlGetAsyncRequest | TB.SqlGetAsyncRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SqlGetAsyncResponse, unknown>>
|
||||
async getAsync (this: That, params: T.SqlGetAsyncRequest | TB.SqlGetAsyncRequest, options?: TransportRequestOptions): Promise<T.SqlGetAsyncResponse>
|
||||
async getAsync (this: That, params: T.SqlGetAsyncRequest | TB.SqlGetAsyncRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['id']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -121,19 +121,19 @@ export default class Sql {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async getAsyncStatus (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async getAsyncStatus (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async getAsyncStatus (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async getAsyncStatus (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async getAsyncStatus (this: That, params: T.SqlGetAsyncStatusRequest | TB.SqlGetAsyncStatusRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.SqlGetAsyncStatusResponse>
|
||||
async getAsyncStatus (this: That, params: T.SqlGetAsyncStatusRequest | TB.SqlGetAsyncStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SqlGetAsyncStatusResponse, unknown>>
|
||||
async getAsyncStatus (this: That, params: T.SqlGetAsyncStatusRequest | TB.SqlGetAsyncStatusRequest, options?: TransportRequestOptions): Promise<T.SqlGetAsyncStatusResponse>
|
||||
async getAsyncStatus (this: That, params: T.SqlGetAsyncStatusRequest | TB.SqlGetAsyncStatusRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['id']
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
|
||||
params = params ?? {}
|
||||
for (const key in params) {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
@ -148,7 +148,7 @@ export default class Sql {
|
||||
async query (this: That, params?: T.SqlQueryRequest | TB.SqlQueryRequest, options?: TransportRequestOptions): Promise<T.SqlQueryResponse>
|
||||
async query (this: That, params?: T.SqlQueryRequest | TB.SqlQueryRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const acceptedBody: string[] = ['columnar', 'cursor', 'fetch_size', 'filter', 'query', 'request_timeout', 'page_timeout', 'time_zone', 'field_multi_value_leniency']
|
||||
const acceptedBody: string[] = ['catalog', 'columnar', 'cursor', 'fetch_size', 'filter', 'query', 'request_timeout', 'page_timeout', 'time_zone', 'field_multi_value_leniency', 'runtime_mappings', 'wait_for_completion_timeout', 'params', 'keep_alive', 'keep_on_completion', 'index_using_frozen']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
|
||||
@ -164,7 +164,7 @@ export default class Transform {
|
||||
async putTransform (this: That, params: T.TransformPutTransformRequest | TB.TransformPutTransformRequest, options?: TransportRequestOptions): Promise<T.TransformPutTransformResponse>
|
||||
async putTransform (this: That, params: T.TransformPutTransformRequest | TB.TransformPutTransformRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['transform_id']
|
||||
const acceptedBody: string[] = ['dest', 'description', 'frequency', 'pivot', 'source', 'settings', 'sync', 'retention_policy', 'latest']
|
||||
const acceptedBody: string[] = ['dest', 'description', 'frequency', 'latest', '_meta', 'pivot', 'retention_policy', 'settings', 'source', 'sync']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
@ -242,7 +242,7 @@ export default class Transform {
|
||||
async updateTransform (this: That, params: T.TransformUpdateTransformRequest | TB.TransformUpdateTransformRequest, options?: TransportRequestOptions): Promise<T.TransformUpdateTransformResponse>
|
||||
async updateTransform (this: That, params: T.TransformUpdateTransformRequest | TB.TransformUpdateTransformRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['transform_id']
|
||||
const acceptedBody: string[] = ['dest', 'description', 'frequency', 'source', 'settings', 'sync', 'retention_policy']
|
||||
const acceptedBody: string[] = ['dest', 'description', 'frequency', '_meta', 'source', 'settings', 'sync', 'retention_policy']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
const userBody: any = params?.body
|
||||
@ -271,10 +271,10 @@ export default class Transform {
|
||||
return await this.transport.request({ path, method, querystring, body }, options)
|
||||
}
|
||||
|
||||
async upgradeTransforms (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
|
||||
async upgradeTransforms (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
|
||||
async upgradeTransforms (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
|
||||
async upgradeTransforms (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
|
||||
async upgradeTransforms (this: That, params?: T.TransformUpgradeTransformsRequest | TB.TransformUpgradeTransformsRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.TransformUpgradeTransformsResponse>
|
||||
async upgradeTransforms (this: That, params?: T.TransformUpgradeTransformsRequest | TB.TransformUpgradeTransformsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformUpgradeTransformsResponse, unknown>>
|
||||
async upgradeTransforms (this: That, params?: T.TransformUpgradeTransformsRequest | TB.TransformUpgradeTransformsRequest, options?: TransportRequestOptions): Promise<T.TransformUpgradeTransformsResponse>
|
||||
async upgradeTransforms (this: That, params?: T.TransformUpgradeTransformsRequest | TB.TransformUpgradeTransformsRequest, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = []
|
||||
const querystring: Record<string, any> = {}
|
||||
const body = undefined
|
||||
@ -284,6 +284,7 @@ export default class Transform {
|
||||
if (acceptedPath.includes(key)) {
|
||||
continue
|
||||
} else if (key !== 'body') {
|
||||
// @ts-expect-error
|
||||
querystring[key] = params[key]
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ export default async function UpdateApi<TDocument = unknown, TPartialDocument =
|
||||
export default async function UpdateApi<TDocument = unknown, TPartialDocument = unknown, TDocumentR = unknown> (this: That, params: T.UpdateRequest<TDocument, TPartialDocument> | TB.UpdateRequest<TDocument, TPartialDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.UpdateResponse<TDocumentR>, unknown>>
|
||||
export default async function UpdateApi<TDocument = unknown, TPartialDocument = unknown, TDocumentR = unknown> (this: That, params: T.UpdateRequest<TDocument, TPartialDocument> | TB.UpdateRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<T.UpdateResponse<TDocumentR>>
|
||||
export default async function UpdateApi<TDocument = unknown, TPartialDocument = unknown, TDocumentR = unknown> (this: That, params: T.UpdateRequest<TDocument, TPartialDocument> | TB.UpdateRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<any> {
|
||||
const acceptedPath: string[] = ['id', 'index', 'type']
|
||||
const acceptedPath: string[] = ['id', 'index']
|
||||
const acceptedBody: string[] = ['detect_noop', 'doc', 'doc_as_upsert', 'script', 'scripted_upsert', '_source', 'upsert']
|
||||
const querystring: Record<string, any> = {}
|
||||
// @ts-expect-error
|
||||
|
||||
@ -63,7 +63,7 @@ interface KibanaClient {
|
||||
getAutoscalingPolicy: <TContext = unknown>(params: T.AutoscalingGetAutoscalingPolicyRequest| TB.AutoscalingGetAutoscalingPolicyRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.AutoscalingGetAutoscalingPolicyResponse, TContext>>
|
||||
putAutoscalingPolicy: <TContext = unknown>(params: T.AutoscalingPutAutoscalingPolicyRequest| TB.AutoscalingPutAutoscalingPolicyRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.AutoscalingPutAutoscalingPolicyResponse, TContext>>
|
||||
}
|
||||
bulk: <TSource = unknown, TContext = unknown>(params: T.BulkRequest<TSource>| TB.BulkRequest<TSource>, options?: TransportRequestOptions) => Promise<TransportResult<T.BulkResponse, TContext>>
|
||||
bulk: <TDocument = unknown, TPartialDocument = unknown, TContext = unknown>(params: T.BulkRequest<TDocument, TPartialDocument>| TB.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions) => Promise<TransportResult<T.BulkResponse, TContext>>
|
||||
cat: {
|
||||
aliases: <TContext = unknown>(params?: T.CatAliasesRequest| TB.CatAliasesRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.CatAliasesResponse, TContext>>
|
||||
allocation: <TContext = unknown>(params?: T.CatAllocationRequest| TB.CatAllocationRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.CatAllocationResponse, TContext>>
|
||||
@ -159,8 +159,8 @@ interface KibanaClient {
|
||||
fieldCaps: <TContext = unknown>(params?: T.FieldCapsRequest| TB.FieldCapsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.FieldCapsResponse, TContext>>
|
||||
fleet: {
|
||||
globalCheckpoints: <TContext = unknown>(params: T.FleetGlobalCheckpointsRequest| TB.FleetGlobalCheckpointsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.FleetGlobalCheckpointsResponse, TContext>>
|
||||
msearch: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
search: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
msearch: <TDocument = unknown, TContext = unknown>(params: T.FleetMsearchRequest| TB.FleetMsearchRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.FleetMsearchResponse<TDocument>, TContext>>
|
||||
search: <TDocument = unknown, TContext = unknown>(params: T.FleetSearchRequest| TB.FleetSearchRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.FleetSearchResponse<TDocument>, TContext>>
|
||||
}
|
||||
get: <TDocument = unknown, TContext = unknown>(params: T.GetRequest| TB.GetRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.GetResponse<TDocument>, TContext>>
|
||||
getScript: <TContext = unknown>(params: T.GetScriptRequest| TB.GetScriptRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.GetScriptResponse, TContext>>
|
||||
@ -175,7 +175,7 @@ interface KibanaClient {
|
||||
explainLifecycle: <TContext = unknown>(params: T.IlmExplainLifecycleRequest| TB.IlmExplainLifecycleRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IlmExplainLifecycleResponse, TContext>>
|
||||
getLifecycle: <TContext = unknown>(params?: T.IlmGetLifecycleRequest| TB.IlmGetLifecycleRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IlmGetLifecycleResponse, TContext>>
|
||||
getStatus: <TContext = unknown>(params?: T.IlmGetStatusRequest| TB.IlmGetStatusRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IlmGetStatusResponse, TContext>>
|
||||
migrateToDataTiers: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
migrateToDataTiers: <TContext = unknown>(params?: T.IlmMigrateToDataTiersRequest| TB.IlmMigrateToDataTiersRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IlmMigrateToDataTiersResponse, TContext>>
|
||||
moveToStep: <TContext = unknown>(params: T.IlmMoveToStepRequest| TB.IlmMoveToStepRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IlmMoveToStepResponse, TContext>>
|
||||
putLifecycle: <TContext = unknown>(params: T.IlmPutLifecycleRequest| TB.IlmPutLifecycleRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IlmPutLifecycleResponse, TContext>>
|
||||
removePolicy: <TContext = unknown>(params: T.IlmRemovePolicyRequest| TB.IlmRemovePolicyRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IlmRemovePolicyResponse, TContext>>
|
||||
@ -203,8 +203,7 @@ interface KibanaClient {
|
||||
existsAlias: <TContext = unknown>(params: T.IndicesExistsAliasRequest| TB.IndicesExistsAliasRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IndicesExistsAliasResponse, TContext>>
|
||||
existsIndexTemplate: <TContext = unknown>(params: T.IndicesExistsIndexTemplateRequest| TB.IndicesExistsIndexTemplateRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IndicesExistsIndexTemplateResponse, TContext>>
|
||||
existsTemplate: <TContext = unknown>(params: T.IndicesExistsTemplateRequest| TB.IndicesExistsTemplateRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IndicesExistsTemplateResponse, TContext>>
|
||||
existsType: <TContext = unknown>(params: T.IndicesExistsTypeRequest| TB.IndicesExistsTypeRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IndicesExistsTypeResponse, TContext>>
|
||||
fieldUsageStats: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
fieldUsageStats: <TContext = unknown>(params: T.IndicesFieldUsageStatsRequest| TB.IndicesFieldUsageStatsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IndicesFieldUsageStatsResponse, TContext>>
|
||||
flush: <TContext = unknown>(params?: T.IndicesFlushRequest| TB.IndicesFlushRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IndicesFlushResponse, TContext>>
|
||||
forcemerge: <TContext = unknown>(params?: T.IndicesForcemergeRequest| TB.IndicesForcemergeRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IndicesForcemergeResponse, TContext>>
|
||||
get: <TContext = unknown>(params: T.IndicesGetRequest| TB.IndicesGetRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.IndicesGetResponse, TContext>>
|
||||
@ -267,8 +266,8 @@ interface KibanaClient {
|
||||
mget: <TDocument = unknown, TContext = unknown>(params?: T.MgetRequest| TB.MgetRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MgetResponse<TDocument>, TContext>>
|
||||
migration: {
|
||||
deprecations: <TContext = unknown>(params?: T.MigrationDeprecationsRequest| TB.MigrationDeprecationsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MigrationDeprecationsResponse, TContext>>
|
||||
getFeatureUpgradeStatus: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
postFeatureUpgrade: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
getFeatureUpgradeStatus: <TContext = unknown>(params?: T.MigrationGetFeatureUpgradeStatusRequest| TB.MigrationGetFeatureUpgradeStatusRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MigrationGetFeatureUpgradeStatusResponse, TContext>>
|
||||
postFeatureUpgrade: <TContext = unknown>(params?: T.MigrationPostFeatureUpgradeRequest| TB.MigrationPostFeatureUpgradeRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MigrationPostFeatureUpgradeResponse, TContext>>
|
||||
}
|
||||
ml: {
|
||||
closeJob: <TContext = unknown>(params: T.MlCloseJobRequest| TB.MlCloseJobRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlCloseJobResponse, TContext>>
|
||||
@ -301,12 +300,13 @@ interface KibanaClient {
|
||||
getInfluencers: <TContext = unknown>(params: T.MlGetInfluencersRequest| TB.MlGetInfluencersRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlGetInfluencersResponse, TContext>>
|
||||
getJobStats: <TContext = unknown>(params?: T.MlGetJobStatsRequest| TB.MlGetJobStatsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlGetJobStatsResponse, TContext>>
|
||||
getJobs: <TContext = unknown>(params?: T.MlGetJobsRequest| TB.MlGetJobsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlGetJobsResponse, TContext>>
|
||||
getModelSnapshotUpgradeStats: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
getModelSnapshots: <TContext = unknown>(params: T.MlGetModelSnapshotsRequest| TB.MlGetModelSnapshotsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlGetModelSnapshotsResponse, TContext>>
|
||||
getOverallBuckets: <TContext = unknown>(params: T.MlGetOverallBucketsRequest| TB.MlGetOverallBucketsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlGetOverallBucketsResponse, TContext>>
|
||||
getRecords: <TContext = unknown>(params: T.MlGetRecordsRequest| TB.MlGetRecordsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlGetRecordsResponse, TContext>>
|
||||
getTrainedModels: <TContext = unknown>(params?: T.MlGetTrainedModelsRequest| TB.MlGetTrainedModelsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlGetTrainedModelsResponse, TContext>>
|
||||
getTrainedModelsStats: <TContext = unknown>(params?: T.MlGetTrainedModelsStatsRequest| TB.MlGetTrainedModelsStatsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlGetTrainedModelsStatsResponse, TContext>>
|
||||
inferTrainedModelDeployment: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
inferTrainedModelDeployment: <TContext = unknown>(params: T.MlInferTrainedModelDeploymentRequest| TB.MlInferTrainedModelDeploymentRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlInferTrainedModelDeploymentResponse, TContext>>
|
||||
info: <TContext = unknown>(params?: T.MlInfoRequest| TB.MlInfoRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlInfoResponse, TContext>>
|
||||
openJob: <TContext = unknown>(params: T.MlOpenJobRequest| TB.MlOpenJobRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlOpenJobResponse, TContext>>
|
||||
postCalendarEvents: <TContext = unknown>(params: T.MlPostCalendarEventsRequest| TB.MlPostCalendarEventsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlPostCalendarEventsResponse, TContext>>
|
||||
@ -321,17 +321,17 @@ interface KibanaClient {
|
||||
putJob: <TContext = unknown>(params: T.MlPutJobRequest| TB.MlPutJobRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlPutJobResponse, TContext>>
|
||||
putTrainedModel: <TContext = unknown>(params: T.MlPutTrainedModelRequest| TB.MlPutTrainedModelRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlPutTrainedModelResponse, TContext>>
|
||||
putTrainedModelAlias: <TContext = unknown>(params: T.MlPutTrainedModelAliasRequest| TB.MlPutTrainedModelAliasRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlPutTrainedModelAliasResponse, TContext>>
|
||||
putTrainedModelDefinitionPart: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
putTrainedModelVocabulary: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
putTrainedModelDefinitionPart: <TContext = unknown>(params: T.MlPutTrainedModelDefinitionPartRequest| TB.MlPutTrainedModelDefinitionPartRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlPutTrainedModelDefinitionPartResponse, TContext>>
|
||||
putTrainedModelVocabulary: <TContext = unknown>(params: T.MlPutTrainedModelVocabularyRequest| TB.MlPutTrainedModelVocabularyRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlPutTrainedModelVocabularyResponse, TContext>>
|
||||
resetJob: <TContext = unknown>(params: T.MlResetJobRequest| TB.MlResetJobRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlResetJobResponse, TContext>>
|
||||
revertModelSnapshot: <TContext = unknown>(params: T.MlRevertModelSnapshotRequest| TB.MlRevertModelSnapshotRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlRevertModelSnapshotResponse, TContext>>
|
||||
setUpgradeMode: <TContext = unknown>(params?: T.MlSetUpgradeModeRequest| TB.MlSetUpgradeModeRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlSetUpgradeModeResponse, TContext>>
|
||||
startDataFrameAnalytics: <TContext = unknown>(params: T.MlStartDataFrameAnalyticsRequest| TB.MlStartDataFrameAnalyticsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlStartDataFrameAnalyticsResponse, TContext>>
|
||||
startDatafeed: <TContext = unknown>(params: T.MlStartDatafeedRequest| TB.MlStartDatafeedRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlStartDatafeedResponse, TContext>>
|
||||
startTrainedModelDeployment: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
startTrainedModelDeployment: <TContext = unknown>(params: T.MlStartTrainedModelDeploymentRequest| TB.MlStartTrainedModelDeploymentRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlStartTrainedModelDeploymentResponse, TContext>>
|
||||
stopDataFrameAnalytics: <TContext = unknown>(params: T.MlStopDataFrameAnalyticsRequest| TB.MlStopDataFrameAnalyticsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlStopDataFrameAnalyticsResponse, TContext>>
|
||||
stopDatafeed: <TContext = unknown>(params: T.MlStopDatafeedRequest| TB.MlStopDatafeedRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlStopDatafeedResponse, TContext>>
|
||||
stopTrainedModelDeployment: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
stopTrainedModelDeployment: <TContext = unknown>(params: T.MlStopTrainedModelDeploymentRequest| TB.MlStopTrainedModelDeploymentRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlStopTrainedModelDeploymentResponse, TContext>>
|
||||
updateDataFrameAnalytics: <TContext = unknown>(params: T.MlUpdateDataFrameAnalyticsRequest| TB.MlUpdateDataFrameAnalyticsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlUpdateDataFrameAnalyticsResponse, TContext>>
|
||||
updateDatafeed: <TContext = unknown>(params: T.MlUpdateDatafeedRequest| TB.MlUpdateDatafeedRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlUpdateDatafeedResponse, TContext>>
|
||||
updateFilter: <TContext = unknown>(params: T.MlUpdateFilterRequest| TB.MlUpdateFilterRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlUpdateFilterResponse, TContext>>
|
||||
@ -342,14 +342,14 @@ interface KibanaClient {
|
||||
validateDetector: <TContext = unknown>(params?: T.MlValidateDetectorRequest| TB.MlValidateDetectorRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MlValidateDetectorResponse, TContext>>
|
||||
}
|
||||
monitoring: {
|
||||
bulk: <TSource = unknown, TContext = unknown>(params: T.MonitoringBulkRequest<TSource>| TB.MonitoringBulkRequest<TSource>, options?: TransportRequestOptions) => Promise<TransportResult<T.MonitoringBulkResponse, TContext>>
|
||||
bulk: <TDocument = unknown, TPartialDocument = unknown, TContext = unknown>(params: T.MonitoringBulkRequest<TDocument, TPartialDocument>| TB.MonitoringBulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions) => Promise<TransportResult<T.MonitoringBulkResponse, TContext>>
|
||||
}
|
||||
msearch: <TDocument = unknown, TContext = unknown>(params?: T.MsearchRequest| TB.MsearchRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MsearchResponse<TDocument>, TContext>>
|
||||
msearchTemplate: <TDocument = unknown, TContext = unknown>(params?: T.MsearchTemplateRequest| TB.MsearchTemplateRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MsearchTemplateResponse<TDocument>, TContext>>
|
||||
msearch: <TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>, TContext = unknown>(params?: T.MsearchRequest| TB.MsearchRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MsearchResponse<TDocument, TAggregations>, TContext>>
|
||||
msearchTemplate: <TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>, TContext = unknown>(params?: T.MsearchTemplateRequest| TB.MsearchTemplateRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MsearchTemplateResponse<TDocument, TAggregations>, TContext>>
|
||||
mtermvectors: <TContext = unknown>(params?: T.MtermvectorsRequest| TB.MtermvectorsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.MtermvectorsResponse, TContext>>
|
||||
nodes: {
|
||||
clearRepositoriesMeteringArchive: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
getRepositoriesMeteringInfo: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
clearRepositoriesMeteringArchive: <TContext = unknown>(params: T.NodesClearRepositoriesMeteringArchiveRequest| TB.NodesClearRepositoriesMeteringArchiveRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.NodesClearRepositoriesMeteringArchiveResponse, TContext>>
|
||||
getRepositoriesMeteringInfo: <TContext = unknown>(params: T.NodesGetRepositoriesMeteringInfoRequest| TB.NodesGetRepositoriesMeteringInfoRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.NodesGetRepositoriesMeteringInfoResponse, TContext>>
|
||||
hotThreads: <TContext = unknown>(params?: T.NodesHotThreadsRequest| TB.NodesHotThreadsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.NodesHotThreadsResponse, TContext>>
|
||||
info: <TContext = unknown>(params?: T.NodesInfoRequest| TB.NodesInfoRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.NodesInfoResponse, TContext>>
|
||||
reloadSecureSettings: <TContext = unknown>(params?: T.NodesReloadSecureSettingsRequest| TB.NodesReloadSecureSettingsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.NodesReloadSecureSettingsResponse, TContext>>
|
||||
@ -370,18 +370,18 @@ interface KibanaClient {
|
||||
getRollupIndexCaps: <TContext = unknown>(params: T.RollupGetRollupIndexCapsRequest| TB.RollupGetRollupIndexCapsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.RollupGetRollupIndexCapsResponse, TContext>>
|
||||
putJob: <TContext = unknown>(params: T.RollupPutJobRequest| TB.RollupPutJobRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.RollupPutJobResponse, TContext>>
|
||||
rollup: <TContext = unknown>(params: T.RollupRollupRequest| TB.RollupRollupRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.RollupRollupResponse, TContext>>
|
||||
rollupSearch: <TDocument = unknown, TContext = unknown>(params: T.RollupRollupSearchRequest| TB.RollupRollupSearchRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.RollupRollupSearchResponse<TDocument>, TContext>>
|
||||
rollupSearch: <TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>, TContext = unknown>(params: T.RollupRollupSearchRequest| TB.RollupRollupSearchRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.RollupRollupSearchResponse<TDocument, TAggregations>, TContext>>
|
||||
startJob: <TContext = unknown>(params: T.RollupStartJobRequest| TB.RollupStartJobRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.RollupStartJobResponse, TContext>>
|
||||
stopJob: <TContext = unknown>(params: T.RollupStopJobRequest| TB.RollupStopJobRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.RollupStopJobResponse, TContext>>
|
||||
}
|
||||
scriptsPainlessExecute: <TResult = unknown, TContext = unknown>(params?: T.ScriptsPainlessExecuteRequest| TB.ScriptsPainlessExecuteRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.ScriptsPainlessExecuteResponse<TResult>, TContext>>
|
||||
scroll: <TDocument = unknown, TContext = unknown>(params?: T.ScrollRequest| TB.ScrollRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.ScrollResponse<TDocument>, TContext>>
|
||||
search: <TDocument = unknown, TContext = unknown>(params?: T.SearchRequest| TB.SearchRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SearchResponse<TDocument>, TContext>>
|
||||
scroll: <TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>, TContext = unknown>(params?: T.ScrollRequest| TB.ScrollRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.ScrollResponse<TDocument, TAggregations>, TContext>>
|
||||
search: <TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>, TContext = unknown>(params?: T.SearchRequest| TB.SearchRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SearchResponse<TDocument, TAggregations>, TContext>>
|
||||
searchMvt: <TContext = unknown>(params: T.SearchMvtRequest| TB.SearchMvtRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SearchMvtResponse, TContext>>
|
||||
searchShards: <TContext = unknown>(params?: T.SearchShardsRequest| TB.SearchShardsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SearchShardsResponse, TContext>>
|
||||
searchTemplate: <TDocument = unknown, TContext = unknown>(params?: T.SearchTemplateRequest| TB.SearchTemplateRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SearchTemplateResponse<TDocument>, TContext>>
|
||||
searchableSnapshots: {
|
||||
cacheStats: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
cacheStats: <TContext = unknown>(params?: T.SearchableSnapshotsCacheStatsRequest| TB.SearchableSnapshotsCacheStatsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SearchableSnapshotsCacheStatsResponse, TContext>>
|
||||
clearCache: <TContext = unknown>(params?: T.SearchableSnapshotsClearCacheRequest| TB.SearchableSnapshotsClearCacheRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SearchableSnapshotsClearCacheResponse, TContext>>
|
||||
mount: <TContext = unknown>(params: T.SearchableSnapshotsMountRequest| TB.SearchableSnapshotsMountRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SearchableSnapshotsMountResponse, TContext>>
|
||||
stats: <TContext = unknown>(params?: T.SearchableSnapshotsStatsRequest| TB.SearchableSnapshotsStatsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SearchableSnapshotsStatsResponse, TContext>>
|
||||
@ -403,8 +403,8 @@ interface KibanaClient {
|
||||
deleteUser: <TContext = unknown>(params: T.SecurityDeleteUserRequest| TB.SecurityDeleteUserRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityDeleteUserResponse, TContext>>
|
||||
disableUser: <TContext = unknown>(params: T.SecurityDisableUserRequest| TB.SecurityDisableUserRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityDisableUserResponse, TContext>>
|
||||
enableUser: <TContext = unknown>(params: T.SecurityEnableUserRequest| TB.SecurityEnableUserRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityEnableUserResponse, TContext>>
|
||||
enrollKibana: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
enrollNode: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
enrollKibana: <TContext = unknown>(params?: T.SecurityEnrollKibanaRequest| TB.SecurityEnrollKibanaRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityEnrollKibanaResponse, TContext>>
|
||||
enrollNode: <TContext = unknown>(params?: T.SecurityEnrollNodeRequest| TB.SecurityEnrollNodeRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityEnrollNodeResponse, TContext>>
|
||||
getApiKey: <TContext = unknown>(params?: T.SecurityGetApiKeyRequest| TB.SecurityGetApiKeyRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityGetApiKeyResponse, TContext>>
|
||||
getBuiltinPrivileges: <TContext = unknown>(params?: T.SecurityGetBuiltinPrivilegesRequest| TB.SecurityGetBuiltinPrivilegesRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityGetBuiltinPrivilegesResponse, TContext>>
|
||||
getPrivileges: <TContext = unknown>(params?: T.SecurityGetPrivilegesRequest| TB.SecurityGetPrivilegesRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityGetPrivilegesResponse, TContext>>
|
||||
@ -423,13 +423,13 @@ interface KibanaClient {
|
||||
putRole: <TContext = unknown>(params: T.SecurityPutRoleRequest| TB.SecurityPutRoleRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityPutRoleResponse, TContext>>
|
||||
putRoleMapping: <TContext = unknown>(params: T.SecurityPutRoleMappingRequest| TB.SecurityPutRoleMappingRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityPutRoleMappingResponse, TContext>>
|
||||
putUser: <TContext = unknown>(params: T.SecurityPutUserRequest| TB.SecurityPutUserRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityPutUserResponse, TContext>>
|
||||
queryApiKeys: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
samlAuthenticate: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
samlCompleteLogout: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
samlInvalidate: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
samlLogout: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
samlPrepareAuthentication: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
samlServiceProviderMetadata: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
queryApiKeys: <TContext = unknown>(params?: T.SecurityQueryApiKeysRequest| TB.SecurityQueryApiKeysRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecurityQueryApiKeysResponse, TContext>>
|
||||
samlAuthenticate: <TContext = unknown>(params?: T.SecuritySamlAuthenticateRequest| TB.SecuritySamlAuthenticateRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecuritySamlAuthenticateResponse, TContext>>
|
||||
samlCompleteLogout: <TContext = unknown>(params?: T.SecuritySamlCompleteLogoutRequest| TB.SecuritySamlCompleteLogoutRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecuritySamlCompleteLogoutResponse, TContext>>
|
||||
samlInvalidate: <TContext = unknown>(params?: T.SecuritySamlInvalidateRequest| TB.SecuritySamlInvalidateRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecuritySamlInvalidateResponse, TContext>>
|
||||
samlLogout: <TContext = unknown>(params?: T.SecuritySamlLogoutRequest| TB.SecuritySamlLogoutRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecuritySamlLogoutResponse, TContext>>
|
||||
samlPrepareAuthentication: <TContext = unknown>(params?: T.SecuritySamlPrepareAuthenticationRequest| TB.SecuritySamlPrepareAuthenticationRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecuritySamlPrepareAuthenticationResponse, TContext>>
|
||||
samlServiceProviderMetadata: <TContext = unknown>(params: T.SecuritySamlServiceProviderMetadataRequest| TB.SecuritySamlServiceProviderMetadataRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SecuritySamlServiceProviderMetadataResponse, TContext>>
|
||||
}
|
||||
shutdown: {
|
||||
deleteNode: <TContext = unknown>(params: T.ShutdownDeleteNodeRequest| TB.ShutdownDeleteNodeRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.ShutdownDeleteNodeResponse, TContext>>
|
||||
@ -463,9 +463,9 @@ interface KibanaClient {
|
||||
}
|
||||
sql: {
|
||||
clearCursor: <TContext = unknown>(params?: T.SqlClearCursorRequest| TB.SqlClearCursorRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SqlClearCursorResponse, TContext>>
|
||||
deleteAsync: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
getAsync: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
getAsyncStatus: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
deleteAsync: <TContext = unknown>(params: T.SqlDeleteAsyncRequest| TB.SqlDeleteAsyncRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SqlDeleteAsyncResponse, TContext>>
|
||||
getAsync: <TContext = unknown>(params: T.SqlGetAsyncRequest| TB.SqlGetAsyncRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SqlGetAsyncResponse, TContext>>
|
||||
getAsyncStatus: <TContext = unknown>(params: T.SqlGetAsyncStatusRequest| TB.SqlGetAsyncStatusRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SqlGetAsyncStatusResponse, TContext>>
|
||||
query: <TContext = unknown>(params?: T.SqlQueryRequest| TB.SqlQueryRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SqlQueryResponse, TContext>>
|
||||
translate: <TContext = unknown>(params?: T.SqlTranslateRequest| TB.SqlTranslateRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.SqlTranslateResponse, TContext>>
|
||||
}
|
||||
@ -491,7 +491,7 @@ interface KibanaClient {
|
||||
startTransform: <TContext = unknown>(params: T.TransformStartTransformRequest| TB.TransformStartTransformRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.TransformStartTransformResponse, TContext>>
|
||||
stopTransform: <TContext = unknown>(params: T.TransformStopTransformRequest| TB.TransformStopTransformRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.TransformStopTransformResponse, TContext>>
|
||||
updateTransform: <TContext = unknown>(params: T.TransformUpdateTransformRequest| TB.TransformUpdateTransformRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.TransformUpdateTransformResponse, TContext>>
|
||||
upgradeTransforms: <TContext = unknown>(params?: T.TODO, options?: TransportRequestOptions) => Promise<TransportResult<T.TODO, unknown>>
|
||||
upgradeTransforms: <TContext = unknown>(params?: T.TransformUpgradeTransformsRequest| TB.TransformUpgradeTransformsRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.TransformUpgradeTransformsResponse, TContext>>
|
||||
}
|
||||
update: <TDocumentR = unknown, TDocument = unknown, TPartialDocument = unknown, TContext = unknown>(params: T.UpdateRequest<TDocument, TPartialDocument>| TB.UpdateRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions) => Promise<TransportResult<T.UpdateResponse<TDocumentR>, TContext>>
|
||||
updateByQuery: <TContext = unknown>(params: T.UpdateByQueryRequest| TB.UpdateByQueryRequest, options?: TransportRequestOptions) => Promise<TransportResult<T.UpdateByQueryResponse, TContext>>
|
||||
|
||||
2626
src/api/types.ts
2626
src/api/types.ts
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -20,6 +20,7 @@
|
||||
import { ConnectionOptions as TlsConnectionOptions } from 'tls'
|
||||
import { URL } from 'url'
|
||||
import buffer from 'buffer'
|
||||
import os from 'os'
|
||||
import {
|
||||
Transport,
|
||||
UndiciConnection,
|
||||
@ -173,7 +174,9 @@ export default class Client extends API {
|
||||
tls: null,
|
||||
caFingerprint: null,
|
||||
agent: null,
|
||||
headers: {},
|
||||
headers: {
|
||||
'user-agent': `elasticsearch-js/${clientVersion} Node.js ${nodeVersion}; Transport ${transportVersion}; (${os.platform()} ${os.release()} ${os.arch()})`
|
||||
},
|
||||
nodeFilter: null,
|
||||
generateRequestId: null,
|
||||
name: 'elasticsearch-js',
|
||||
@ -251,7 +254,12 @@ export default class Client extends API {
|
||||
context: options.context,
|
||||
productCheck: 'Elasticsearch',
|
||||
maxResponseSize: options.maxResponseSize,
|
||||
maxCompressedResponseSize: options.maxCompressedResponseSize
|
||||
maxCompressedResponseSize: options.maxCompressedResponseSize,
|
||||
vendoredHeaders: {
|
||||
jsonContentType: 'application/vnd.elasticsearch+json; compatible-with=8',
|
||||
ndjsonContentType: 'application/vnd.elasticsearch+x-ndjson; compatible-with=8',
|
||||
accept: 'application/vnd.elasticsearch+json; compatible-with=8,text/plain'
|
||||
}
|
||||
})
|
||||
|
||||
this.helpers = new Helpers({
|
||||
|
||||
@ -19,6 +19,9 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const fetch = require('node-fetch')
|
||||
|
||||
function runInParallel (client, operation, options, clientOptions) {
|
||||
if (options.length === 0) return Promise.resolve()
|
||||
const operations = options.map(opts => {
|
||||
@ -65,6 +68,9 @@ function isXPackTemplate (name) {
|
||||
if (name.startsWith('.transform-')) {
|
||||
return true
|
||||
}
|
||||
if (name.startsWith('.deprecation-')) {
|
||||
return true
|
||||
}
|
||||
switch (name) {
|
||||
case '.watches':
|
||||
case 'logstash-index-template':
|
||||
@ -84,14 +90,49 @@ function isXPackTemplate (name) {
|
||||
case 'synthetics-settings':
|
||||
case 'synthetics-mappings':
|
||||
case '.snapshot-blob-cache':
|
||||
case '.deprecation-indexing-template':
|
||||
case '.deprecation-indexing-mappings':
|
||||
case '.deprecation-indexing-settings':
|
||||
case 'data-streams-mappings':
|
||||
case '.logs-deprecation.elasticsearch-default':
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
module.exports = { runInParallel, delve, to, sleep, isXPackTemplate }
|
||||
async function getSpec () {
|
||||
const response = await fetch('https://raw.githubusercontent.com/elastic/elasticsearch-specification/main/output/schema/schema.json')
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
let spec = null
|
||||
|
||||
// some keys for the path used in the yaml test are not support in the client
|
||||
// for example: snapshot.createRepository({ repository }) will not work.
|
||||
// This code changes the params to the appropriate name, in the example above,
|
||||
// "repository" will be renamed to "name"
|
||||
async function updateParams (cmd) {
|
||||
if (spec == null) {
|
||||
spec = await getSpec()
|
||||
}
|
||||
const endpoint = spec.endpoints.find(endpoint => endpoint.name === cmd.api)
|
||||
assert(endpoint != null)
|
||||
if (endpoint.request == null) return cmd
|
||||
|
||||
const type = spec.types.find(type => type.name.name === endpoint.request.name && type.name.namespace === endpoint.request.namespace)
|
||||
assert(type != null)
|
||||
|
||||
const pathParams = type.path.reduce((acc, val) => {
|
||||
if (val.codegenName != null) {
|
||||
acc[val.name] = val.codegenName
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
for (const key in cmd.params) {
|
||||
if (pathParams[key] != null) {
|
||||
cmd.params[pathParams[key]] = cmd.params[key]
|
||||
delete cmd.params[key]
|
||||
}
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
module.exports = { runInParallel, delve, to, sleep, isXPackTemplate, updateParams }
|
||||
|
||||
@ -29,6 +29,7 @@ const { join, sep } = require('path')
|
||||
const yaml = require('js-yaml')
|
||||
const ms = require('ms')
|
||||
const { Client } = require('../../index')
|
||||
const { kProductCheck } = require('@elastic/transport/lib/symbols')
|
||||
const build = require('./test-runner')
|
||||
const { sleep } = require('./helper')
|
||||
const createJunitReporter = require('./reporter')
|
||||
@ -49,6 +50,8 @@ const freeSkips = {
|
||||
'Body params with array param override query string',
|
||||
'Body params with string param scroll id override query string'
|
||||
],
|
||||
'free/cat.allocation/10_basic.yml': ['*'],
|
||||
'free/cat.snapshots/10_basic.yml': ['Test cat snapshots output'],
|
||||
// TODO: remove this once 'arbitrary_key' is implemented
|
||||
// https://github.com/elastic/elasticsearch/pull/41492
|
||||
'indices.split/30_copy_settings.yml': ['*'],
|
||||
@ -62,9 +65,11 @@ const freeSkips = {
|
||||
'search.aggregation/240_max_buckets.yml': ['*'],
|
||||
// the yaml runner assumes that null means "does not exists",
|
||||
// while null is a valid json value, so the check will fail
|
||||
'search/320_disallow_queries.yml': ['Test disallow expensive queries']
|
||||
'search/320_disallow_queries.yml': ['Test disallow expensive queries'],
|
||||
'free/tsdb/90_unsupported_operations.yml': ['noop update']
|
||||
}
|
||||
const platinumBlackList = {
|
||||
'api_key/20_query.yml': ['*'],
|
||||
'analytics/histogram.yml': ['Histogram requires values in increasing order'],
|
||||
// this two test cases are broken, we should
|
||||
// return on those in the future.
|
||||
@ -93,9 +98,15 @@ const platinumBlackList = {
|
||||
// The cleanup fails with a index not found when retrieving the jobs
|
||||
'ml/get_datafeed_stats.yml': ['Test get datafeed stats when total_search_time_ms mapping is missing'],
|
||||
'ml/bucket_correlation_agg.yml': ['Test correlation bucket agg simple'],
|
||||
// start should be a string
|
||||
'ml/jobs_get_result_overall_buckets.yml': ['Test overall buckets given epoch start and end params'],
|
||||
// this can't happen with the client
|
||||
'ml/start_data_frame_analytics.yml': ['Test start with inconsistent body/param ids'],
|
||||
'ml/stop_data_frame_analytics.yml': ['Test stop with inconsistent body/param ids'],
|
||||
'ml/preview_datafeed.yml': ['*'],
|
||||
// Investigate why is failing
|
||||
'ml/inference_crud.yml': ['*'],
|
||||
'ml/categorization_agg.yml': ['Test categorization aggregation with poor settings'],
|
||||
// investigate why this is failing
|
||||
'monitoring/bulk/10_basic.yml': ['*'],
|
||||
'monitoring/bulk/20_privileges.yml': ['*'],
|
||||
@ -161,6 +172,8 @@ function runner (opts = {}) {
|
||||
}
|
||||
}
|
||||
const client = new Client(options)
|
||||
// TODO: remove the following line once https://github.com/elastic/elasticsearch/issues/82358 is fixed
|
||||
client.transport[kProductCheck] = null
|
||||
log('Loading yaml suite')
|
||||
start({ client, isXPack: opts.isXPack })
|
||||
.catch(err => {
|
||||
|
||||
@ -1,52 +0,0 @@
|
||||
# `elasticsearch-js` integration test suite
|
||||
|
||||
> What? A README to explain how the integration test work??
|
||||
|
||||
Yes.
|
||||
|
||||
## Background
|
||||
Elasticsearch offers its entire API via HTTP REST endpoints. You can find the whole API specification for every version [here](https://github.com/elastic/elasticsearch/tree/master/rest-api-spec/src/main/resources/rest-api-spec/api).<br/>
|
||||
To support different languages at the same time, the Elasticsearch team decided to provide a [YAML specification](https://github.com/elastic/elasticsearch/tree/master/rest-api-spec/src/main/resources/rest-api-spec/test) to test every endpoint, body, headers, warning, error and so on.<br/>
|
||||
This testing suite uses that specification to generate the test for the specified version of Elasticsearch on the fly.
|
||||
|
||||
## Run
|
||||
Run the testing suite is very easy, you just need to run the preconfigured npm script:
|
||||
```sh
|
||||
npm run test:integration
|
||||
```
|
||||
|
||||
The first time you run this command, the Elasticsearch repository will be cloned inside the integration test folder, to be able to access the YAML specification, so it might take some time *(luckily, only the first time)*.<br/>
|
||||
Once the Elasticsearch repository has been cloned, the testing suite will connect to the provided Elasticsearch instance and then checkout the build hash in the repository. Finally, it will start running every test.
|
||||
|
||||
The specification does not allow the test to be run in parallel, so it might take a while to run the entire testing suite; on my machine, `MacBookPro15,2 core i7 2.7GHz 16GB of RAM` it takes around four minutes.
|
||||
|
||||
### Exit on the first failure
|
||||
Bu default the suite will run all the test, even if one assertion has failed. If you want to stop the test at the first failure, use the bailout option:
|
||||
```sh
|
||||
npm run test:integration -- --bail
|
||||
```
|
||||
|
||||
### Calculate the code coverage
|
||||
If you want to calculate the code coverage just run the testing suite with the following parameters, once the test ends, it will open a browser window with the results.
|
||||
```sh
|
||||
npm run test:integration -- --cov --coverage-report=html
|
||||
```
|
||||
|
||||
## How does this thing work?
|
||||
At first sight, it might seem complicated, but once you understand what the moving parts are, it's quite easy.
|
||||
1. Connects to the given Elasticsearch instance
|
||||
1. Gets the ES version and build hash
|
||||
1. Checkout to the given hash (and clone the repository if it is not present)
|
||||
1. Reads the folder list and for each folder the yaml file list
|
||||
1. Starts running folder by folder every file
|
||||
1. Read and parse the yaml files
|
||||
1. Creates a subtest structure to have a cleaner output
|
||||
1. Runs the assertions
|
||||
1. Repeat!
|
||||
|
||||
Inside the `index.js` file, you will find the connection, cloning, reading and parsing part of the test, while inside the `test-runner.js` file you will find the function to handle the assertions. Inside `test-runner.js`, we use a [queue](https://github.com/delvedor/workq) to be sure that everything is run in the correct order.
|
||||
|
||||
Checkout the [rest-api-spec readme](https://github.com/elastic/elasticsearch/blob/master/rest-api-spec/src/main/resources/rest-api-spec/test/README.asciidoc) if you want to know more about how the assertions work.
|
||||
|
||||
#### Why are we running the test with the `--harmony` flag?
|
||||
Because on Node v6 the regex lookbehinds are not supported.
|
||||
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
function runInParallel (client, operation, options, clientOptions) {
|
||||
if (options.length === 0) return Promise.resolve()
|
||||
const operations = options.map(opts => {
|
||||
const api = delve(client, operation).bind(client)
|
||||
return api(opts, clientOptions)
|
||||
})
|
||||
|
||||
return Promise.all(operations)
|
||||
}
|
||||
|
||||
// code from https://github.com/developit/dlv
|
||||
// needed to support an edge case: `a\.b`
|
||||
// where `a.b` is a single field: { 'a.b': true }
|
||||
function delve (obj, key, def, p) {
|
||||
p = 0
|
||||
// handle the key with a dot inside that is not a part of the path
|
||||
// and removes the backslashes from the key
|
||||
key = key.split
|
||||
? key.split(/(?<!\\)\./g).map(k => k.replace(/\\/g, ''))
|
||||
: key.replace(/\\/g, '')
|
||||
while (obj && p < key.length) obj = obj[key[p++]]
|
||||
return (obj === undefined || p < key.length) ? def : obj
|
||||
}
|
||||
|
||||
function to (promise) {
|
||||
return promise.then(data => [null, data], err => [err, undefined])
|
||||
}
|
||||
|
||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
||||
function isXPackTemplate (name) {
|
||||
if (name.startsWith('.monitoring-')) {
|
||||
return true
|
||||
}
|
||||
if (name.startsWith('.watch') || name.startsWith('.triggered_watches')) {
|
||||
return true
|
||||
}
|
||||
if (name.startsWith('.data-frame-')) {
|
||||
return true
|
||||
}
|
||||
if (name.startsWith('.ml-')) {
|
||||
return true
|
||||
}
|
||||
if (name.startsWith('.transform-')) {
|
||||
return true
|
||||
}
|
||||
switch (name) {
|
||||
case '.watches':
|
||||
case 'logstash-index-template':
|
||||
case '.logstash-management':
|
||||
case 'security_audit_log':
|
||||
case '.slm-history':
|
||||
case '.async-search':
|
||||
case 'saml-service-provider':
|
||||
case 'ilm-history':
|
||||
case 'logs':
|
||||
case 'logs-settings':
|
||||
case 'logs-mappings':
|
||||
case 'metrics':
|
||||
case 'metrics-settings':
|
||||
case 'metrics-mappings':
|
||||
case 'synthetics':
|
||||
case 'synthetics-settings':
|
||||
case 'synthetics-mappings':
|
||||
case '.snapshot-blob-cache':
|
||||
case '.deprecation-indexing-template':
|
||||
case '.deprecation-indexing-mappings':
|
||||
case '.deprecation-indexing-settings':
|
||||
case 'data-streams-mappings':
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
module.exports = { runInParallel, delve, to, sleep, isXPackTemplate }
|
||||
@ -1,204 +0,0 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const { createReadStream } = require('fs')
|
||||
const { join } = require('path')
|
||||
const split = require('split2')
|
||||
const { test, beforeEach, afterEach } = require('tap')
|
||||
const { waitCluster } = require('../../utils')
|
||||
const { Client } = require('../../../')
|
||||
|
||||
const datasetPath = join(__dirname, '..', '..', 'fixtures', 'stackoverflow.ndjson')
|
||||
const INDEX = `test-helpers-${process.pid}`
|
||||
const client = new Client({
|
||||
node: process.env.TEST_ES_SERVER || 'http://localhost:9200'
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await waitCluster(client)
|
||||
await client.indices.create({ index: INDEX })
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await client.indices.delete({ index: INDEX }, { ignore: 404 })
|
||||
})
|
||||
|
||||
test('bulk index', async t => {
|
||||
const stream = createReadStream(datasetPath)
|
||||
const result = await client.helpers.bulk({
|
||||
datasource: stream.pipe(split()),
|
||||
refreshOnCompletion: INDEX,
|
||||
onDrop (doc) {
|
||||
t.fail('It should not drop any document')
|
||||
},
|
||||
onDocument (doc) {
|
||||
return {
|
||||
index: { _index: INDEX }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.type(result.time, 'number')
|
||||
t.type(result.bytes, 'number')
|
||||
t.match(result, {
|
||||
total: 5000,
|
||||
successful: 5000,
|
||||
retry: 0,
|
||||
failed: 0,
|
||||
aborted: false
|
||||
})
|
||||
|
||||
const { body } = await client.count({ index: INDEX })
|
||||
t.match(body, { count: 5000 })
|
||||
})
|
||||
|
||||
test('bulk index with custom id', async t => {
|
||||
const stream = createReadStream(datasetPath)
|
||||
const result = await client.helpers.bulk({
|
||||
datasource: stream.pipe(split(JSON.parse)),
|
||||
onDrop (doc) {
|
||||
t.fail('It should not drop any document')
|
||||
},
|
||||
onDocument (doc) {
|
||||
return {
|
||||
index: {
|
||||
_index: INDEX,
|
||||
_id: doc.id
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.type(result.time, 'number')
|
||||
t.type(result.bytes, 'number')
|
||||
t.match(result, {
|
||||
total: 5000,
|
||||
successful: 5000,
|
||||
retry: 0,
|
||||
failed: 0,
|
||||
aborted: false
|
||||
})
|
||||
|
||||
const { body } = await client.get({
|
||||
index: INDEX,
|
||||
id: '19273860' // id of document n° 4242
|
||||
})
|
||||
|
||||
t.equal(body._index, INDEX)
|
||||
t.equal(body._id, '19273860')
|
||||
t.equal(body._source.id, '19273860')
|
||||
})
|
||||
|
||||
test('abort the operation on document drop', async t => {
|
||||
const stream = createReadStream(datasetPath)
|
||||
const b = client.helpers.bulk({
|
||||
datasource: stream.pipe(split(JSON.parse)),
|
||||
concurrency: 1,
|
||||
onDrop (doc) {
|
||||
t.equal(doc.status, 400)
|
||||
t.equal(doc.error.type, 'mapper_parsing_exception')
|
||||
t.equal(doc.document.id, '45924372')
|
||||
b.abort()
|
||||
},
|
||||
onDocument (doc) {
|
||||
if (doc.id === '45924372') { // id of document n° 500
|
||||
// this will break the mapping
|
||||
doc.title = { foo: 'bar' }
|
||||
}
|
||||
return {
|
||||
index: {
|
||||
_index: INDEX,
|
||||
_id: doc.id
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = await b
|
||||
t.type(result.time, 'number')
|
||||
t.type(result.bytes, 'number')
|
||||
t.equal(result.total - 1, result.successful)
|
||||
t.match(result, {
|
||||
retry: 0,
|
||||
failed: 1,
|
||||
aborted: true
|
||||
})
|
||||
})
|
||||
|
||||
test('bulk delete', async t => {
|
||||
const indexResult = await client.helpers.bulk({
|
||||
datasource: createReadStream(datasetPath).pipe(split(JSON.parse)),
|
||||
refreshOnCompletion: true,
|
||||
onDrop (doc) {
|
||||
t.fail('It should not drop any document')
|
||||
},
|
||||
onDocument (doc) {
|
||||
return {
|
||||
index: {
|
||||
_index: INDEX,
|
||||
_id: doc.id
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.type(indexResult.time, 'number')
|
||||
t.type(indexResult.bytes, 'number')
|
||||
t.match(indexResult, {
|
||||
total: 5000,
|
||||
successful: 5000,
|
||||
retry: 0,
|
||||
failed: 0,
|
||||
aborted: false
|
||||
})
|
||||
|
||||
const { body: afterIndex } = await client.count({ index: INDEX })
|
||||
t.match(afterIndex, { count: 5000 })
|
||||
|
||||
const deleteResult = await client.helpers.bulk({
|
||||
datasource: createReadStream(datasetPath).pipe(split(JSON.parse)),
|
||||
refreshOnCompletion: true,
|
||||
onDrop (doc) {
|
||||
t.fail('It should not drop any document')
|
||||
},
|
||||
onDocument (doc) {
|
||||
return {
|
||||
delete: {
|
||||
_index: INDEX,
|
||||
_id: doc.id
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.type(deleteResult.time, 'number')
|
||||
t.type(deleteResult.bytes, 'number')
|
||||
t.match(deleteResult, {
|
||||
total: 5000,
|
||||
successful: 5000,
|
||||
retry: 0,
|
||||
failed: 0,
|
||||
aborted: false
|
||||
})
|
||||
|
||||
const { body: afterDelete } = await client.count({ index: INDEX })
|
||||
t.match(afterDelete, { count: 0 })
|
||||
})
|
||||
@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const { createReadStream } = require('fs')
|
||||
const { join } = require('path')
|
||||
const split = require('split2')
|
||||
const { test, beforeEach, afterEach } = require('tap')
|
||||
const { waitCluster } = require('../../utils')
|
||||
const { Client, errors } = require('../../../')
|
||||
|
||||
const INDEX = `test-helpers-${process.pid}`
|
||||
const client = new Client({
|
||||
node: process.env.TEST_ES_SERVER || 'http://localhost:9200'
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await waitCluster(client)
|
||||
await client.indices.create({ index: INDEX })
|
||||
const stream = createReadStream(join(__dirname, '..', '..', 'fixtures', 'stackoverflow.ndjson'))
|
||||
const result = await client.helpers.bulk({
|
||||
datasource: stream.pipe(split()),
|
||||
refreshOnCompletion: true,
|
||||
onDocument (doc) {
|
||||
return {
|
||||
index: { _index: INDEX }
|
||||
}
|
||||
}
|
||||
})
|
||||
if (result.failed > 0) {
|
||||
throw new Error('Failed bulk indexing docs')
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await client.indices.delete({ index: INDEX }, { ignore: 404 })
|
||||
})
|
||||
|
||||
test('Basic', t => {
|
||||
t.plan(4)
|
||||
const m = client.helpers.msearch({ operations: 1 })
|
||||
|
||||
m.search(
|
||||
{ index: INDEX },
|
||||
{ query: { match: { title: 'javascript' } } },
|
||||
(err, result) => {
|
||||
t.error(err)
|
||||
t.equal(result.body.hits.total.value, 106)
|
||||
}
|
||||
)
|
||||
|
||||
m.search(
|
||||
{ index: INDEX },
|
||||
{ query: { match: { title: 'ruby' } } },
|
||||
(err, result) => {
|
||||
t.error(err)
|
||||
t.equal(result.body.hits.total.value, 29)
|
||||
}
|
||||
)
|
||||
|
||||
t.teardown(() => m.stop())
|
||||
})
|
||||
|
||||
test('Bad request', t => {
|
||||
t.plan(3)
|
||||
const m = client.helpers.msearch({ operations: 1 })
|
||||
|
||||
m.search(
|
||||
{ index: INDEX },
|
||||
{ query: { match: { title: 'javascript' } } },
|
||||
(err, result) => {
|
||||
t.error(err)
|
||||
t.equal(result.body.hits.total.value, 106)
|
||||
}
|
||||
)
|
||||
|
||||
m.search(
|
||||
{ index: INDEX },
|
||||
{ query: { foo: { title: 'ruby' } } },
|
||||
(err, result) => {
|
||||
t.ok(err instanceof errors.ResponseError)
|
||||
}
|
||||
)
|
||||
|
||||
t.teardown(() => m.stop())
|
||||
})
|
||||
|
||||
test('Send multiple request concurrently over the concurrency limit', t => {
|
||||
t.plan(20)
|
||||
const m = client.helpers.msearch({ operations: 1 })
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
m.search(
|
||||
{ index: INDEX },
|
||||
{ query: { match: { title: 'javascript' } } },
|
||||
(err, result) => {
|
||||
t.error(err)
|
||||
t.equal(result.body.hits.total.value, 106)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
t.teardown(() => m.stop())
|
||||
})
|
||||
@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const { createReadStream } = require('fs')
|
||||
const { join } = require('path')
|
||||
const split = require('split2')
|
||||
const { test, beforeEach, afterEach } = require('tap')
|
||||
const { waitCluster } = require('../../utils')
|
||||
const { Client } = require('../../../')
|
||||
|
||||
const INDEX = `test-helpers-${process.pid}`
|
||||
const client = new Client({
|
||||
node: process.env.TEST_ES_SERVER || 'http://localhost:9200'
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await waitCluster(client)
|
||||
await client.indices.create({ index: INDEX })
|
||||
const stream = createReadStream(join(__dirname, '..', '..', 'fixtures', 'stackoverflow.ndjson'))
|
||||
const result = await client.helpers.bulk({
|
||||
datasource: stream.pipe(split()),
|
||||
refreshOnCompletion: true,
|
||||
onDocument (doc) {
|
||||
return {
|
||||
index: { _index: INDEX }
|
||||
}
|
||||
}
|
||||
})
|
||||
if (result.failed > 0) {
|
||||
throw new Error('Failed bulk indexing docs')
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await client.indices.delete({ index: INDEX }, { ignore: 404 })
|
||||
})
|
||||
|
||||
test('search helper', async t => {
|
||||
const scrollSearch = client.helpers.scrollSearch({
|
||||
index: INDEX,
|
||||
body: {
|
||||
query: {
|
||||
match: {
|
||||
title: 'javascript'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let count = 0
|
||||
for await (const search of scrollSearch) {
|
||||
count += 1
|
||||
for (const doc of search.documents) {
|
||||
t.ok(doc.title.toLowerCase().includes('javascript'))
|
||||
}
|
||||
}
|
||||
t.equal(count, 11)
|
||||
})
|
||||
|
||||
test('clear a scroll search', async t => {
|
||||
const scrollSearch = client.helpers.scrollSearch({
|
||||
index: INDEX,
|
||||
body: {
|
||||
query: {
|
||||
match: {
|
||||
title: 'javascript'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let count = 0
|
||||
for await (const search of scrollSearch) {
|
||||
count += 1
|
||||
if (count === 2) {
|
||||
search.clear()
|
||||
}
|
||||
}
|
||||
t.equal(count, 2)
|
||||
})
|
||||
|
||||
test('scroll documents', async t => {
|
||||
const scrollSearch = client.helpers.scrollDocuments({
|
||||
index: INDEX,
|
||||
body: {
|
||||
query: {
|
||||
match: {
|
||||
title: 'javascript'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let count = 0
|
||||
for await (const doc of scrollSearch) {
|
||||
count += 1
|
||||
t.ok(doc.title.toLowerCase().includes('javascript'))
|
||||
}
|
||||
t.equal(count, 106)
|
||||
})
|
||||
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const { createReadStream } = require('fs')
|
||||
const { join } = require('path')
|
||||
const split = require('split2')
|
||||
const { test, beforeEach, afterEach } = require('tap')
|
||||
const { waitCluster } = require('../../utils')
|
||||
const { Client } = require('../../../')
|
||||
|
||||
const INDEX = `test-helpers-${process.pid}`
|
||||
const client = new Client({
|
||||
node: process.env.TEST_ES_SERVER || 'http://localhost:9200'
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await waitCluster(client)
|
||||
await client.indices.create({ index: INDEX })
|
||||
const stream = createReadStream(join(__dirname, '..', '..', 'fixtures', 'stackoverflow.ndjson'))
|
||||
const result = await client.helpers.bulk({
|
||||
datasource: stream.pipe(split()),
|
||||
refreshOnCompletion: true,
|
||||
onDocument (doc) {
|
||||
return {
|
||||
index: { _index: INDEX }
|
||||
}
|
||||
}
|
||||
})
|
||||
if (result.failed > 0) {
|
||||
throw new Error('Failed bulk indexing docs')
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await client.indices.delete({ index: INDEX }, { ignore: 404 })
|
||||
})
|
||||
|
||||
test('search helper', async t => {
|
||||
const results = await client.helpers.search({
|
||||
index: INDEX,
|
||||
body: {
|
||||
query: {
|
||||
match: {
|
||||
title: 'javascript'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
t.equal(results.length, 10)
|
||||
for (const result of results) {
|
||||
t.ok(result.title.toLowerCase().includes('javascript'))
|
||||
}
|
||||
})
|
||||
@ -1,385 +0,0 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
process.on('unhandledRejection', function (err) {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
const { writeFileSync, readFileSync, readdirSync, statSync } = require('fs')
|
||||
const { join, sep } = require('path')
|
||||
const yaml = require('js-yaml')
|
||||
const ms = require('ms')
|
||||
const { Client } = require('../../index')
|
||||
const build = require('./test-runner')
|
||||
const { sleep } = require('./helper')
|
||||
const createJunitReporter = require('./reporter')
|
||||
const downloadArtifacts = require('../../scripts/download-artifacts')
|
||||
|
||||
const yamlFolder = downloadArtifacts.locations.freeTestFolder
|
||||
const xPackYamlFolder = downloadArtifacts.locations.xPackTestFolder
|
||||
|
||||
const MAX_API_TIME = 1000 * 90
|
||||
const MAX_FILE_TIME = 1000 * 30
|
||||
const MAX_TEST_TIME = 1000 * 3
|
||||
|
||||
const freeSkips = {
|
||||
// TODO: remove this once 'arbitrary_key' is implemented
|
||||
// https://github.com/elastic/elasticsearch/pull/41492
|
||||
'indices.split/30_copy_settings.yml': ['*'],
|
||||
'indices.stats/50_disk_usage.yml': ['Disk usage stats'],
|
||||
'indices.stats/60_field_usage.yml': ['Field usage stats'],
|
||||
// skipping because we are booting ES with `discovery.type=single-node`
|
||||
// and this test will fail because of this configuration
|
||||
'nodes.stats/30_discovery.yml': ['*'],
|
||||
// the expected error is returning a 503,
|
||||
// which triggers a retry and the node to be marked as dead
|
||||
'search.aggregation/240_max_buckets.yml': ['*'],
|
||||
// the yaml runner assumes that null means "does not exists",
|
||||
// while null is a valid json value, so the check will fail
|
||||
'search/320_disallow_queries.yml': ['Test disallow expensive queries']
|
||||
}
|
||||
const platinumBlackList = {
|
||||
'analytics/histogram.yml': ['Histogram requires values in increasing order'],
|
||||
// this two test cases are broken, we should
|
||||
// return on those in the future.
|
||||
'analytics/top_metrics.yml': [
|
||||
'sort by keyword field fails',
|
||||
'sort by string script fails'
|
||||
],
|
||||
'cat.aliases/10_basic.yml': ['Empty cluster'],
|
||||
'index/10_with_id.yml': ['Index with ID'],
|
||||
'indices.get_alias/10_basic.yml': ['Get alias against closed indices'],
|
||||
'indices.get_alias/20_empty.yml': ['Check empty aliases when getting all aliases via /_alias'],
|
||||
'text_structure/find_structure.yml': ['*'],
|
||||
// https://github.com/elastic/elasticsearch/pull/39400
|
||||
'ml/jobs_crud.yml': ['Test put job with id that is already taken'],
|
||||
// object keys must me strings, and `0.0.toString()` is `0`
|
||||
'ml/evaluate_data_frame.yml': [
|
||||
'Test binary_soft_classifition precision',
|
||||
'Test binary_soft_classifition recall',
|
||||
'Test binary_soft_classifition confusion_matrix'
|
||||
],
|
||||
// it gets random failures on CI, must investigate
|
||||
'ml/set_upgrade_mode.yml': [
|
||||
'Attempt to open job when upgrade_mode is enabled',
|
||||
'Setting upgrade mode to disabled from enabled'
|
||||
],
|
||||
// The cleanup fails with a index not found when retrieving the jobs
|
||||
'ml/get_datafeed_stats.yml': ['Test get datafeed stats when total_search_time_ms mapping is missing'],
|
||||
'ml/bucket_correlation_agg.yml': ['Test correlation bucket agg simple'],
|
||||
'ml/preview_datafeed.yml': ['*'],
|
||||
// Investigate why is failing
|
||||
'ml/inference_crud.yml': ['*'],
|
||||
// investigate why this is failing
|
||||
'monitoring/bulk/10_basic.yml': ['*'],
|
||||
'monitoring/bulk/20_privileges.yml': ['*'],
|
||||
'license/20_put_license.yml': ['*'],
|
||||
'snapshot/10_basic.yml': ['*'],
|
||||
'snapshot/20_operator_privileges_disabled.yml': ['*'],
|
||||
// the body is correct, but the regex is failing
|
||||
'sql/sql.yml': ['Getting textual representation'],
|
||||
'searchable_snapshots/10_usage.yml': ['*'],
|
||||
'service_accounts/10_basic.yml': ['*'],
|
||||
// we are setting two certificates in the docker config
|
||||
'ssl/10_basic.yml': ['*'],
|
||||
// very likely, the index template has not been loaded yet.
|
||||
// we should run a indices.existsTemplate, but the name of the
|
||||
// template may vary during time.
|
||||
'transforms_crud.yml': [
|
||||
'Test basic transform crud',
|
||||
'Test transform with query and array of indices in source',
|
||||
'Test PUT continuous transform',
|
||||
'Test PUT continuous transform without delay set'
|
||||
],
|
||||
'transforms_force_delete.yml': [
|
||||
'Test force deleting a running transform'
|
||||
],
|
||||
'transforms_cat_apis.yml': ['*'],
|
||||
'transforms_start_stop.yml': ['*'],
|
||||
'transforms_stats.yml': ['*'],
|
||||
'transforms_stats_continuous.yml': ['*'],
|
||||
'transforms_update.yml': ['*'],
|
||||
// js does not support ulongs
|
||||
'unsigned_long/10_basic.yml': ['*'],
|
||||
'unsigned_long/20_null_value.yml': ['*'],
|
||||
'unsigned_long/30_multi_fields.yml': ['*'],
|
||||
'unsigned_long/40_different_numeric.yml': ['*'],
|
||||
'unsigned_long/50_script_values.yml': ['*'],
|
||||
// docker issue?
|
||||
'watcher/execute_watch/60_http_input.yml': ['*'],
|
||||
// the checks are correct, but for some reason the test is failing on js side
|
||||
// I bet is because the backslashes in the rg
|
||||
'watcher/execute_watch/70_invalid.yml': ['*'],
|
||||
'watcher/put_watch/10_basic.yml': ['*'],
|
||||
'xpack/15_basic.yml': ['*']
|
||||
}
|
||||
|
||||
function runner (opts = {}) {
|
||||
const options = { node: opts.node }
|
||||
if (opts.isXPack) {
|
||||
options.ssl = {
|
||||
ca: readFileSync(join(__dirname, '..', '..', '.ci', 'certs', 'ca.crt'), 'utf8'),
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
}
|
||||
const client = new Client(options)
|
||||
log('Loading yaml suite')
|
||||
start({ client, isXPack: opts.isXPack })
|
||||
.catch(err => {
|
||||
if (err.name === 'ResponseError') {
|
||||
console.error(err)
|
||||
console.log(JSON.stringify(err.meta, null, 2))
|
||||
} else {
|
||||
console.error(err)
|
||||
}
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
|
||||
async function waitCluster (client, times = 0) {
|
||||
try {
|
||||
await client.cluster.health({ waitForStatus: 'green', timeout: '50s' })
|
||||
} catch (err) {
|
||||
if (++times < 10) {
|
||||
await sleep(5000)
|
||||
return waitCluster(client, times)
|
||||
}
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
async function start ({ client, isXPack }) {
|
||||
log('Waiting for Elasticsearch')
|
||||
await waitCluster(client)
|
||||
|
||||
const { body } = await client.info()
|
||||
const { number: version, build_hash: hash } = body.version
|
||||
|
||||
log(`Downloading artifacts for hash ${hash}...`)
|
||||
await downloadArtifacts({ hash, version })
|
||||
|
||||
log(`Testing ${isXPack ? 'Platinum' : 'Free'} api...`)
|
||||
const junit = createJunitReporter()
|
||||
const junitTestSuites = junit.testsuites(`Integration test for ${isXPack ? 'Platinum' : 'Free'} api`)
|
||||
|
||||
const stats = {
|
||||
total: 0,
|
||||
skip: 0,
|
||||
pass: 0,
|
||||
assertions: 0
|
||||
}
|
||||
const folders = getAllFiles(isXPack ? xPackYamlFolder : yamlFolder)
|
||||
.filter(t => !/(README|TODO)/g.test(t))
|
||||
// we cluster the array based on the folder names,
|
||||
// to provide a better test log output
|
||||
.reduce((arr, file) => {
|
||||
const path = file.slice(file.indexOf('/rest-api-spec/test'), file.lastIndexOf('/'))
|
||||
let inserted = false
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
if (arr[i][0].includes(path)) {
|
||||
inserted = true
|
||||
arr[i].push(file)
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!inserted) arr.push([file])
|
||||
return arr
|
||||
}, [])
|
||||
|
||||
const totalTime = now()
|
||||
for (const folder of folders) {
|
||||
// pretty name
|
||||
const apiName = folder[0].slice(
|
||||
folder[0].indexOf(`${sep}rest-api-spec${sep}test`) + 19,
|
||||
folder[0].lastIndexOf(sep)
|
||||
)
|
||||
|
||||
log('Testing ' + apiName.slice(1))
|
||||
const apiTime = now()
|
||||
|
||||
for (const file of folder) {
|
||||
const testRunner = build({
|
||||
client,
|
||||
version,
|
||||
isXPack: file.includes('platinum')
|
||||
})
|
||||
const fileTime = now()
|
||||
const data = readFileSync(file, 'utf8')
|
||||
// get the test yaml (as object), some file has multiple yaml documents inside,
|
||||
// every document is separated by '---', so we split on the separator
|
||||
// and then we remove the empty strings, finally we parse them
|
||||
const tests = data
|
||||
.split('\n---\n')
|
||||
.map(s => s.trim())
|
||||
// empty strings
|
||||
.filter(Boolean)
|
||||
.map(parse)
|
||||
// null values
|
||||
.filter(Boolean)
|
||||
|
||||
// get setup and teardown if present
|
||||
let setupTest = null
|
||||
let teardownTest = null
|
||||
for (const test of tests) {
|
||||
if (test.setup) setupTest = test.setup
|
||||
if (test.teardown) teardownTest = test.teardown
|
||||
}
|
||||
|
||||
const cleanPath = file.slice(file.lastIndexOf(apiName))
|
||||
log(' ' + cleanPath)
|
||||
const junitTestSuite = junitTestSuites.testsuite(apiName.slice(1) + ' - ' + cleanPath)
|
||||
|
||||
for (const test of tests) {
|
||||
const testTime = now()
|
||||
const name = Object.keys(test)[0]
|
||||
if (name === 'setup' || name === 'teardown') continue
|
||||
const junitTestCase = junitTestSuite.testcase(name)
|
||||
|
||||
stats.total += 1
|
||||
if (shouldSkip(isXPack, file, name)) {
|
||||
stats.skip += 1
|
||||
junitTestCase.skip('This test is in the skip list of the client')
|
||||
junitTestCase.end()
|
||||
continue
|
||||
}
|
||||
log(' - ' + name)
|
||||
try {
|
||||
await testRunner.run(setupTest, test[name], teardownTest, stats, junitTestCase)
|
||||
stats.pass += 1
|
||||
} catch (err) {
|
||||
junitTestCase.failure(err)
|
||||
junitTestCase.end()
|
||||
junitTestSuite.end()
|
||||
junitTestSuites.end()
|
||||
generateJunitXmlReport(junit, isXPack ? 'platinum' : 'free')
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
}
|
||||
const totalTestTime = now() - testTime
|
||||
junitTestCase.end()
|
||||
if (totalTestTime > MAX_TEST_TIME) {
|
||||
log(' took too long: ' + ms(totalTestTime))
|
||||
} else {
|
||||
log(' took: ' + ms(totalTestTime))
|
||||
}
|
||||
}
|
||||
junitTestSuite.end()
|
||||
const totalFileTime = now() - fileTime
|
||||
if (totalFileTime > MAX_FILE_TIME) {
|
||||
log(` ${cleanPath} took too long: ` + ms(totalFileTime))
|
||||
} else {
|
||||
log(` ${cleanPath} took: ` + ms(totalFileTime))
|
||||
}
|
||||
}
|
||||
const totalApiTime = now() - apiTime
|
||||
if (totalApiTime > MAX_API_TIME) {
|
||||
log(`${apiName} took too long: ` + ms(totalApiTime))
|
||||
} else {
|
||||
log(`${apiName} took: ` + ms(totalApiTime))
|
||||
}
|
||||
}
|
||||
junitTestSuites.end()
|
||||
generateJunitXmlReport(junit, isXPack ? 'platinum' : 'free')
|
||||
log(`Total testing time: ${ms(now() - totalTime)}`)
|
||||
log(`Test stats:
|
||||
- Total: ${stats.total}
|
||||
- Skip: ${stats.skip}
|
||||
- Pass: ${stats.pass}
|
||||
- Assertions: ${stats.assertions}
|
||||
`)
|
||||
}
|
||||
|
||||
function log (text) {
|
||||
process.stdout.write(text + '\n')
|
||||
}
|
||||
|
||||
function now () {
|
||||
const ts = process.hrtime()
|
||||
return (ts[0] * 1e3) + (ts[1] / 1e6)
|
||||
}
|
||||
|
||||
function parse (data) {
|
||||
let doc
|
||||
try {
|
||||
doc = yaml.load(data, { schema: yaml.CORE_SCHEMA })
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
return doc
|
||||
}
|
||||
|
||||
function generateJunitXmlReport (junit, suite) {
|
||||
writeFileSync(
|
||||
join(__dirname, '..', '..', `${suite}-report-junit.xml`),
|
||||
junit.prettyPrint()
|
||||
)
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
const node = process.env.TEST_ES_SERVER || 'https://elastic:changeme@localhost:9200'
|
||||
const opts = {
|
||||
node,
|
||||
isXPack: process.env.TEST_SUITE !== 'free'
|
||||
}
|
||||
runner(opts)
|
||||
}
|
||||
|
||||
const shouldSkip = (isXPack, file, name) => {
|
||||
let list = Object.keys(freeSkips)
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const freeTest = freeSkips[list[i]]
|
||||
for (let j = 0; j < freeTest.length; j++) {
|
||||
if (file.endsWith(list[i]) && (name === freeTest[j] || freeTest[j] === '*')) {
|
||||
const testName = file.slice(file.indexOf(`${sep}elasticsearch${sep}`)) + ' / ' + name
|
||||
log(`Skipping test ${testName} because is blacklisted in the free test`)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file.includes('x-pack') || isXPack) {
|
||||
list = Object.keys(platinumBlackList)
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const platTest = platinumBlackList[list[i]]
|
||||
for (let j = 0; j < platTest.length; j++) {
|
||||
if (file.endsWith(list[i]) && (name === platTest[j] || platTest[j] === '*')) {
|
||||
const testName = file.slice(file.indexOf(`${sep}elasticsearch${sep}`)) + ' / ' + name
|
||||
log(`Skipping test ${testName} because is blacklisted in the platinum test`)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
const getAllFiles = dir =>
|
||||
readdirSync(dir).reduce((files, file) => {
|
||||
const name = join(dir, file)
|
||||
const isDirectory = statSync(name).isDirectory()
|
||||
return isDirectory ? [...files, ...getAllFiles(name)] : [...files, name]
|
||||
}, [])
|
||||
|
||||
module.exports = runner
|
||||
@ -1,109 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const { create } = require('xmlbuilder2')
|
||||
|
||||
function createJunitReporter () {
|
||||
const report = {}
|
||||
|
||||
return { testsuites, prettyPrint }
|
||||
|
||||
function prettyPrint () {
|
||||
return create(report).end({ prettyPrint: true })
|
||||
}
|
||||
|
||||
function testsuites (name) {
|
||||
assert(name, 'The testsuites name is required')
|
||||
assert(report.testsuites === undefined, 'Cannot set more than one testsuites block')
|
||||
const startTime = Date.now()
|
||||
|
||||
report.testsuites = {
|
||||
'@id': new Date().toISOString(),
|
||||
'@name': name
|
||||
}
|
||||
|
||||
const testsuiteList = []
|
||||
|
||||
return {
|
||||
testsuite: createTestSuite(testsuiteList),
|
||||
end () {
|
||||
report.testsuites['@time'] = Math.round((Date.now() - startTime) / 1000)
|
||||
report.testsuites['@tests'] = testsuiteList.reduce((acc, val) => {
|
||||
acc += val['@tests']
|
||||
return acc
|
||||
}, 0)
|
||||
report.testsuites['@failures'] = testsuiteList.reduce((acc, val) => {
|
||||
acc += val['@failures']
|
||||
return acc
|
||||
}, 0)
|
||||
report.testsuites['@skipped'] = testsuiteList.reduce((acc, val) => {
|
||||
acc += val['@skipped']
|
||||
return acc
|
||||
}, 0)
|
||||
if (testsuiteList.length) {
|
||||
report.testsuites.testsuite = testsuiteList
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createTestSuite (testsuiteList) {
|
||||
return function testsuite (name) {
|
||||
assert(name, 'The testsuite name is required')
|
||||
const startTime = Date.now()
|
||||
const suite = {
|
||||
'@id': new Date().toISOString(),
|
||||
'@name': name
|
||||
}
|
||||
const testcaseList = []
|
||||
testsuiteList.push(suite)
|
||||
return {
|
||||
testcase: createTestCase(testcaseList),
|
||||
end () {
|
||||
suite['@time'] = Math.round((Date.now() - startTime) / 1000)
|
||||
suite['@tests'] = testcaseList.length
|
||||
suite['@failures'] = testcaseList.filter(t => t.failure).length
|
||||
suite['@skipped'] = testcaseList.filter(t => t.skipped).length
|
||||
if (testcaseList.length) {
|
||||
suite.testcase = testcaseList
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createTestCase (testcaseList) {
|
||||
return function testcase (name) {
|
||||
assert(name, 'The testcase name is required')
|
||||
const startTime = Date.now()
|
||||
const tcase = {
|
||||
'@id': new Date().toISOString(),
|
||||
'@name': name
|
||||
}
|
||||
testcaseList.push(tcase)
|
||||
return {
|
||||
failure (error) {
|
||||
assert(error, 'The failure error object is required')
|
||||
tcase.failure = {
|
||||
'#': error.stack,
|
||||
'@message': error.message,
|
||||
'@type': error.code
|
||||
}
|
||||
},
|
||||
skip (reason) {
|
||||
if (typeof reason !== 'string') {
|
||||
reason = JSON.stringify(reason, null, 2)
|
||||
}
|
||||
tcase.skipped = {
|
||||
'#': reason
|
||||
}
|
||||
},
|
||||
end () {
|
||||
tcase['@time'] = Math.round((Date.now() - startTime) / 1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = createJunitReporter
|
||||
@ -1,909 +0,0 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/* eslint camelcase: 0 */
|
||||
|
||||
const assert = require('assert')
|
||||
const semver = require('semver')
|
||||
const helper = require('./helper')
|
||||
const deepEqual = require('fast-deep-equal')
|
||||
const { join } = require('path')
|
||||
const { locations } = require('../../scripts/download-artifacts')
|
||||
const { ConfigurationError } = require('../../lib/errors')
|
||||
|
||||
const { delve, to, isXPackTemplate, sleep } = helper
|
||||
|
||||
const supportedFeatures = [
|
||||
'gtelte',
|
||||
'regex',
|
||||
'benchmark',
|
||||
'stash_in_path',
|
||||
'groovy_scripting',
|
||||
'headers',
|
||||
'transform_and_set',
|
||||
'catch_unauthorized',
|
||||
'arbitrary_key'
|
||||
]
|
||||
|
||||
function build (opts = {}) {
|
||||
const client = opts.client
|
||||
const esVersion = opts.version
|
||||
const isXPack = opts.isXPack
|
||||
const stash = new Map()
|
||||
let response = null
|
||||
|
||||
/**
|
||||
* Runs a cleanup, removes all indices, aliases, templates, and snapshots
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async function cleanup (isXPack) {
|
||||
response = null
|
||||
stash.clear()
|
||||
|
||||
if (isXPack) {
|
||||
// wipe rollup jobs
|
||||
const { body: jobsList } = await client.rollup.getJobs({ id: '_all' })
|
||||
const jobsIds = jobsList.jobs.map(j => j.config.id)
|
||||
await helper.runInParallel(
|
||||
client, 'rollup.stopJob',
|
||||
jobsIds.map(j => ({ id: j, waitForCompletion: true }))
|
||||
)
|
||||
await helper.runInParallel(
|
||||
client, 'rollup.deleteJob',
|
||||
jobsIds.map(j => ({ id: j }))
|
||||
)
|
||||
|
||||
// delete slm policies
|
||||
const { body: policies } = await client.slm.getLifecycle()
|
||||
await helper.runInParallel(
|
||||
client, 'slm.deleteLifecycle',
|
||||
Object.keys(policies).map(p => ({ policy_id: p }))
|
||||
)
|
||||
|
||||
// remove 'x_pack_rest_user', used in some xpack test
|
||||
await client.security.deleteUser({ username: 'x_pack_rest_user' }, { ignore: [404] })
|
||||
|
||||
const { body: searchableSnapshotIndices } = await client.cluster.state({
|
||||
metric: 'metadata',
|
||||
filter_path: 'metadata.indices.*.settings.index.store.snapshot'
|
||||
})
|
||||
if (searchableSnapshotIndices.metadata != null && searchableSnapshotIndices.metadata.indices != null) {
|
||||
await helper.runInParallel(
|
||||
client, 'indices.delete',
|
||||
Object.keys(searchableSnapshotIndices.metadata.indices).map(i => ({ index: i })),
|
||||
{ ignore: [404] }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// clean snapshots
|
||||
const { body: repositories } = await client.snapshot.getRepository()
|
||||
for (const repository of Object.keys(repositories)) {
|
||||
await client.snapshot.delete({ repository, snapshot: '*' }, { ignore: [404] })
|
||||
await client.snapshot.deleteRepository({ repository }, { ignore: [404] })
|
||||
}
|
||||
|
||||
if (isXPack) {
|
||||
// clean data streams
|
||||
await client.indices.deleteDataStream({ name: '*', expand_wildcards: 'all' })
|
||||
}
|
||||
|
||||
// clean all indices
|
||||
await client.indices.delete({ index: '*,-.ds-ilm-history-*', expand_wildcards: 'open,closed,hidden' }, { ignore: [404] })
|
||||
|
||||
// delete templates
|
||||
const { body: templates } = await client.cat.templates({ h: 'name' })
|
||||
for (const template of templates.split('\n').filter(Boolean)) {
|
||||
if (isXPackTemplate(template)) continue
|
||||
const { body } = await client.indices.deleteTemplate({ name: template }, { ignore: [404] })
|
||||
if (JSON.stringify(body).includes(`index_template [${template}] missing`)) {
|
||||
await client.indices.deleteIndexTemplate({ name: template }, { ignore: [404] })
|
||||
}
|
||||
}
|
||||
|
||||
// delete component template
|
||||
const { body } = await client.cluster.getComponentTemplate()
|
||||
const components = body.component_templates.filter(c => !isXPackTemplate(c.name)).map(c => c.name)
|
||||
if (components.length > 0) {
|
||||
await client.cluster.deleteComponentTemplate({ name: components.join(',') }, { ignore: [404] })
|
||||
}
|
||||
|
||||
// Remove any cluster setting
|
||||
const { body: settings } = await client.cluster.getSettings()
|
||||
const newSettings = {}
|
||||
for (const setting in settings) {
|
||||
if (Object.keys(settings[setting]).length === 0) continue
|
||||
newSettings[setting] = {}
|
||||
for (const key in settings[setting]) {
|
||||
newSettings[setting][`${key}.*`] = null
|
||||
}
|
||||
}
|
||||
if (Object.keys(newSettings).length > 0) {
|
||||
await client.cluster.putSettings({ body: newSettings })
|
||||
}
|
||||
|
||||
if (isXPack) {
|
||||
// delete ilm policies
|
||||
const preserveIlmPolicies = [
|
||||
'ilm-history-ilm-policy', 'slm-history-ilm-policy',
|
||||
'watch-history-ilm-policy', 'ml-size-based-ilm-policy',
|
||||
'logs', 'metrics'
|
||||
]
|
||||
const { body: policies } = await client.ilm.getLifecycle()
|
||||
for (const policy in policies) {
|
||||
if (preserveIlmPolicies.includes(policy)) continue
|
||||
await client.ilm.deleteLifecycle({ policy })
|
||||
}
|
||||
|
||||
// delete autofollow patterns
|
||||
const { body: patterns } = await client.ccr.getAutoFollowPattern()
|
||||
for (const { name } of patterns.patterns) {
|
||||
await client.ccr.deleteAutoFollowPattern({ name })
|
||||
}
|
||||
|
||||
// delete all tasks
|
||||
const { body: nodesTask } = await client.tasks.list()
|
||||
const tasks = Object.keys(nodesTask.nodes)
|
||||
.reduce((acc, node) => {
|
||||
const { tasks } = nodesTask.nodes[node]
|
||||
Object.keys(tasks).forEach(id => {
|
||||
if (tasks[id].cancellable) acc.push(id)
|
||||
})
|
||||
return acc
|
||||
}, [])
|
||||
|
||||
await helper.runInParallel(
|
||||
client, 'tasks.cancel',
|
||||
tasks.map(id => ({ taskId: id }))
|
||||
)
|
||||
}
|
||||
|
||||
const { body: shutdownNodes } = await client.shutdown.getNode()
|
||||
if (shutdownNodes._nodes == null && shutdownNodes.cluster_name == null) {
|
||||
for (const node of shutdownNodes.nodes) {
|
||||
await client.shutdown.deleteNode({ node_id: node.node_id })
|
||||
}
|
||||
}
|
||||
|
||||
// wait for pending task before resolving the promise
|
||||
await sleep(100)
|
||||
while (true) {
|
||||
const { body } = await client.cluster.pendingTasks()
|
||||
if (body.tasks.length === 0) break
|
||||
await sleep(500)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the given test.
|
||||
* It runs the test components in the following order:
|
||||
* - skip check
|
||||
* - xpack user
|
||||
* - setup
|
||||
* - the actual test
|
||||
* - teardown
|
||||
* - xpack cleanup
|
||||
* - cleanup
|
||||
* @param {object} setup (null if not needed)
|
||||
* @param {object} test
|
||||
* @oaram {object} teardown (null if not needed)
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async function run (setup, test, teardown, stats, junit) {
|
||||
// if we should skip a feature in the setup/teardown section
|
||||
// we should skip the entire test file
|
||||
const skip = getSkip(setup) || getSkip(teardown)
|
||||
if (skip && shouldSkip(esVersion, skip)) {
|
||||
junit.skip(skip)
|
||||
logSkip(skip)
|
||||
return
|
||||
}
|
||||
|
||||
if (isXPack) {
|
||||
// Some xpack test requires this user
|
||||
// tap.comment('Creating x-pack user')
|
||||
try {
|
||||
await client.security.putUser({
|
||||
username: 'x_pack_rest_user',
|
||||
body: { password: 'x-pack-test-password', roles: ['superuser'] }
|
||||
})
|
||||
} catch (err) {
|
||||
assert.ifError(err, 'should not error: security.putUser')
|
||||
}
|
||||
}
|
||||
|
||||
if (setup) await exec('Setup', setup, stats, junit)
|
||||
|
||||
await exec('Test', test, stats, junit)
|
||||
|
||||
if (teardown) await exec('Teardown', teardown, stats, junit)
|
||||
|
||||
await cleanup(isXPack)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the stashed values of a command
|
||||
* let's say the we have stashed the `master` value,
|
||||
* is_true: nodes.$master.transport.profiles
|
||||
* becomes
|
||||
* is_true: nodes.new_value.transport.profiles
|
||||
* @param {object|string} the action to update
|
||||
* @returns {object|string} the updated action
|
||||
*/
|
||||
function fillStashedValues (obj) {
|
||||
if (typeof obj === 'string') {
|
||||
return getStashedValues(obj)
|
||||
}
|
||||
// iterate every key of the object
|
||||
for (const key in obj) {
|
||||
const val = obj[key]
|
||||
// if the key value is a string, and the string includes '${'
|
||||
// that we must update the content of '${...}'.
|
||||
// eg: 'Basic ${auth}' we search the stahed value 'auth'
|
||||
// and the resulting value will be 'Basic valueOfAuth'
|
||||
if (typeof val === 'string' && val.includes('${')) {
|
||||
while (obj[key].includes('${')) {
|
||||
const val = obj[key]
|
||||
const start = val.indexOf('${')
|
||||
const end = val.indexOf('}', val.indexOf('${'))
|
||||
const stashedKey = val.slice(start + 2, end)
|
||||
const stashed = stash.get(stashedKey)
|
||||
obj[key] = val.slice(0, start) + stashed + val.slice(end + 1)
|
||||
}
|
||||
continue
|
||||
}
|
||||
// handle json strings, eg: '{"hello":"$world"}'
|
||||
if (typeof val === 'string' && val.includes('"$')) {
|
||||
while (obj[key].includes('"$')) {
|
||||
const val = obj[key]
|
||||
const start = val.indexOf('"$')
|
||||
const end = val.indexOf('"', start + 1)
|
||||
const stashedKey = val.slice(start + 2, end)
|
||||
const stashed = '"' + stash.get(stashedKey) + '"'
|
||||
obj[key] = val.slice(0, start) + stashed + val.slice(end + 1)
|
||||
}
|
||||
continue
|
||||
}
|
||||
// if the key value is a string, and the string includes '$'
|
||||
// we run the "update value" code
|
||||
if (typeof val === 'string' && val.includes('$')) {
|
||||
// update the key value
|
||||
obj[key] = getStashedValues(val)
|
||||
continue
|
||||
}
|
||||
|
||||
// go deep in the object
|
||||
if (val !== null && typeof val === 'object') {
|
||||
fillStashedValues(val)
|
||||
}
|
||||
}
|
||||
|
||||
return obj
|
||||
|
||||
function getStashedValues (str) {
|
||||
const arr = str
|
||||
// we split the string on the dots
|
||||
// handle the key with a dot inside that is not a part of the path
|
||||
.split(/(?<!\\)\./g)
|
||||
// we update every field that start with '$'
|
||||
.map(part => {
|
||||
if (part[0] === '$') {
|
||||
const stashed = stash.get(part.slice(1))
|
||||
if (stashed == null) {
|
||||
throw new Error(`Cannot find stashed value '${part}' for '${JSON.stringify(obj)}'`)
|
||||
}
|
||||
return stashed
|
||||
}
|
||||
return part
|
||||
})
|
||||
|
||||
// recreate the string value only if the array length is higher than one
|
||||
// otherwise return the first element which in some test this could be a number,
|
||||
// and call `.join` will coerce it to a string.
|
||||
return arr.length > 1 ? arr.join('.') : arr[0]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stashes a value
|
||||
* @param {string} the key to search in the previous response
|
||||
* @param {string} the name to identify the stashed value
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function set (key, name) {
|
||||
if (key.includes('_arbitrary_key_')) {
|
||||
let currentVisit = null
|
||||
for (const path of key.split('.')) {
|
||||
if (path === '_arbitrary_key_') {
|
||||
const keys = Object.keys(currentVisit)
|
||||
const arbitraryKey = keys[getRandomInt(0, keys.length)]
|
||||
stash.set(name, arbitraryKey)
|
||||
} else {
|
||||
currentVisit = delve(response, path)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
stash.set(name, delve(response, key))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a given transformation and stashes the result.
|
||||
* @param {string} the name to identify the stashed value
|
||||
* @param {string} the transformation function as string
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function transform_and_set (name, transform) {
|
||||
if (/base64EncodeCredentials/.test(transform)) {
|
||||
const [user, password] = transform
|
||||
.slice(transform.indexOf('(') + 1, -1)
|
||||
.replace(/ /g, '')
|
||||
.split(',')
|
||||
const userAndPassword = `${delve(response, user)}:${delve(response, password)}`
|
||||
stash.set(name, Buffer.from(userAndPassword).toString('base64'))
|
||||
} else {
|
||||
throw new Error(`Unknown transform: '${transform}'`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a client command
|
||||
* @param {object} the action to perform
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async function doAction (action, stats) {
|
||||
const cmd = parseDo(action)
|
||||
let api
|
||||
try {
|
||||
api = delve(client, cmd.method).bind(client)
|
||||
} catch (err) {
|
||||
console.error(`\nError: Cannot find the method '${cmd.method}' in the client.\n`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const options = { ignore: cmd.params.ignore, headers: action.headers }
|
||||
if (!Array.isArray(options.ignore)) options.ignore = [options.ignore]
|
||||
if (cmd.params.ignore) delete cmd.params.ignore
|
||||
|
||||
// ndjson apis should always send the body as an array
|
||||
if (isNDJson(cmd.api) && !Array.isArray(cmd.params.body)) {
|
||||
cmd.params.body = [cmd.params.body]
|
||||
}
|
||||
|
||||
const [err, result] = await to(api(cmd.params, options))
|
||||
let warnings = result ? result.warnings : null
|
||||
const body = result ? result.body : null
|
||||
|
||||
if (action.warnings && warnings === null) {
|
||||
assert.fail('We should get a warning header', action.warnings)
|
||||
} else if (!action.warnings && warnings !== null) {
|
||||
// if there is only the 'default shard will change'
|
||||
// warning we skip the check, because the yaml
|
||||
// spec may not be updated
|
||||
let hasDefaultShardsWarning = false
|
||||
warnings.forEach(h => {
|
||||
if (/default\snumber\sof\sshards/g.test(h)) {
|
||||
hasDefaultShardsWarning = true
|
||||
}
|
||||
})
|
||||
|
||||
if (hasDefaultShardsWarning === true && warnings.length > 1) {
|
||||
assert.fail('We are not expecting warnings', warnings)
|
||||
}
|
||||
} else if (action.warnings && warnings !== null) {
|
||||
// if the yaml warnings do not contain the
|
||||
// 'default shard will change' warning
|
||||
// we do not check it presence in the warnings array
|
||||
// because the yaml spec may not be updated
|
||||
let hasDefaultShardsWarning = false
|
||||
action.warnings.forEach(h => {
|
||||
if (/default\snumber\sof\sshards/g.test(h)) {
|
||||
hasDefaultShardsWarning = true
|
||||
}
|
||||
})
|
||||
|
||||
if (hasDefaultShardsWarning === false) {
|
||||
warnings = warnings.filter(h => !h.test(/default\snumber\sof\sshards/g))
|
||||
}
|
||||
|
||||
stats.assertions += 1
|
||||
assert.ok(deepEqual(warnings, action.warnings))
|
||||
}
|
||||
|
||||
if (action.catch) {
|
||||
stats.assertions += 1
|
||||
assert.ok(
|
||||
parseDoError(err, action.catch),
|
||||
`the error should be: ${action.catch}`
|
||||
)
|
||||
try {
|
||||
response = JSON.parse(err.body)
|
||||
} catch (e) {
|
||||
response = err.body
|
||||
}
|
||||
} else {
|
||||
stats.assertions += 1
|
||||
assert.ifError(err, `should not error: ${cmd.method}`, action)
|
||||
response = body
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an actual test
|
||||
* @param {string} the name of the test
|
||||
* @param {object} the actions to perform
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async function exec (name, actions, stats, junit) {
|
||||
// tap.comment(name)
|
||||
for (const action of actions) {
|
||||
if (action.skip) {
|
||||
if (shouldSkip(esVersion, action.skip)) {
|
||||
junit.skip(fillStashedValues(action.skip))
|
||||
logSkip(fillStashedValues(action.skip))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (action.do) {
|
||||
await doAction(fillStashedValues(action.do), stats)
|
||||
}
|
||||
|
||||
if (action.set) {
|
||||
const key = Object.keys(action.set)[0]
|
||||
set(fillStashedValues(key), action.set[key])
|
||||
}
|
||||
|
||||
if (action.transform_and_set) {
|
||||
const key = Object.keys(action.transform_and_set)[0]
|
||||
transform_and_set(key, action.transform_and_set[key])
|
||||
}
|
||||
|
||||
if (action.match) {
|
||||
stats.assertions += 1
|
||||
const key = Object.keys(action.match)[0]
|
||||
match(
|
||||
// in some cases, the yaml refers to the body with an empty string
|
||||
key === '$body' || key === ''
|
||||
? response
|
||||
: delve(response, fillStashedValues(key)),
|
||||
key === '$body'
|
||||
? action.match[key]
|
||||
: fillStashedValues(action.match)[key],
|
||||
action.match
|
||||
)
|
||||
}
|
||||
|
||||
if (action.lt) {
|
||||
stats.assertions += 1
|
||||
const key = Object.keys(action.lt)[0]
|
||||
lt(
|
||||
delve(response, fillStashedValues(key)),
|
||||
fillStashedValues(action.lt)[key]
|
||||
)
|
||||
}
|
||||
|
||||
if (action.gt) {
|
||||
stats.assertions += 1
|
||||
const key = Object.keys(action.gt)[0]
|
||||
gt(
|
||||
delve(response, fillStashedValues(key)),
|
||||
fillStashedValues(action.gt)[key]
|
||||
)
|
||||
}
|
||||
|
||||
if (action.lte) {
|
||||
stats.assertions += 1
|
||||
const key = Object.keys(action.lte)[0]
|
||||
lte(
|
||||
delve(response, fillStashedValues(key)),
|
||||
fillStashedValues(action.lte)[key]
|
||||
)
|
||||
}
|
||||
|
||||
if (action.gte) {
|
||||
stats.assertions += 1
|
||||
const key = Object.keys(action.gte)[0]
|
||||
gte(
|
||||
delve(response, fillStashedValues(key)),
|
||||
fillStashedValues(action.gte)[key]
|
||||
)
|
||||
}
|
||||
|
||||
if (action.length) {
|
||||
stats.assertions += 1
|
||||
const key = Object.keys(action.length)[0]
|
||||
length(
|
||||
key === '$body' || key === ''
|
||||
? response
|
||||
: delve(response, fillStashedValues(key)),
|
||||
key === '$body'
|
||||
? action.length[key]
|
||||
: fillStashedValues(action.length)[key]
|
||||
)
|
||||
}
|
||||
|
||||
if (action.is_true) {
|
||||
stats.assertions += 1
|
||||
const isTrue = fillStashedValues(action.is_true)
|
||||
is_true(
|
||||
delve(response, isTrue),
|
||||
isTrue
|
||||
)
|
||||
}
|
||||
|
||||
if (action.is_false) {
|
||||
stats.assertions += 1
|
||||
const isFalse = fillStashedValues(action.is_false)
|
||||
is_false(
|
||||
delve(response, isFalse),
|
||||
isFalse
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { run }
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given value is truthy
|
||||
* @param {any} the value to check
|
||||
* @param {string} an optional message
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function is_true (val, msg) {
|
||||
assert.ok(val, `expect truthy value: ${msg} - value: ${JSON.stringify(val)}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given value is falsey
|
||||
* @param {any} the value to check
|
||||
* @param {string} an optional message
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function is_false (val, msg) {
|
||||
assert.ok(!val, `expect falsey value: ${msg} - value: ${JSON.stringify(val)}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two values are the same
|
||||
* @param {any} the first value
|
||||
* @param {any} the second value
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function match (val1, val2, action) {
|
||||
// both values are objects
|
||||
if (typeof val1 === 'object' && typeof val2 === 'object') {
|
||||
assert.ok(deepEqual(val1, val2), action)
|
||||
// the first value is the body as string and the second a pattern string
|
||||
} else if (
|
||||
typeof val1 === 'string' && typeof val2 === 'string' &&
|
||||
val2.startsWith('/') && (val2.endsWith('/\n') || val2.endsWith('/'))
|
||||
) {
|
||||
const regStr = val2
|
||||
// match all comments within a "regexp" match arg
|
||||
.replace(/([\S\s]?)#[^\n]*\n/g, (match, prevChar) => {
|
||||
return prevChar === '\\' ? match : `${prevChar}\n`
|
||||
})
|
||||
// remove all whitespace from the expression, all meaningful
|
||||
// whitespace is represented with \s
|
||||
.replace(/\s/g, '')
|
||||
.slice(1, -1)
|
||||
// 'm' adds the support for multiline regex
|
||||
assert.ok(new RegExp(regStr, 'm').test(val1), `should match pattern provided: ${val2}, action: ${JSON.stringify(action)}`)
|
||||
// tap.match(val1, new RegExp(regStr, 'm'), `should match pattern provided: ${val2}, action: ${JSON.stringify(action)}`)
|
||||
// everything else
|
||||
} else {
|
||||
assert.equal(val1, val2, `should be equal: ${val1} - ${val2}, action: ${JSON.stringify(action)}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the first value is less than the second
|
||||
* It also verifies that the two values are numbers
|
||||
* @param {any} the first value
|
||||
* @param {any} the second value
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function lt (val1, val2) {
|
||||
;[val1, val2] = getNumbers(val1, val2)
|
||||
assert.ok(val1 < val2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the first value is greater than the second
|
||||
* It also verifies that the two values are numbers
|
||||
* @param {any} the first value
|
||||
* @param {any} the second value
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function gt (val1, val2) {
|
||||
;[val1, val2] = getNumbers(val1, val2)
|
||||
assert.ok(val1 > val2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the first value is less than or equal the second
|
||||
* It also verifies that the two values are numbers
|
||||
* @param {any} the first value
|
||||
* @param {any} the second value
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function lte (val1, val2) {
|
||||
;[val1, val2] = getNumbers(val1, val2)
|
||||
assert.ok(val1 <= val2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the first value is greater than or equal the second
|
||||
* It also verifies that the two values are numbers
|
||||
* @param {any} the first value
|
||||
* @param {any} the second value
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function gte (val1, val2) {
|
||||
;[val1, val2] = getNumbers(val1, val2)
|
||||
assert.ok(val1 >= val2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given value has the specified length
|
||||
* @param {string|object|array} the object to check
|
||||
* @param {number} the expected length
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function length (val, len) {
|
||||
if (typeof val === 'string' || Array.isArray(val)) {
|
||||
assert.equal(val.length, len)
|
||||
} else if (typeof val === 'object' && val !== null) {
|
||||
assert.equal(Object.keys(val).length, len)
|
||||
} else {
|
||||
assert.fail(`length: the given value is invalid: ${val}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a `do` action object and returns a structured object,
|
||||
* where the action is the key and the parameter is the value.
|
||||
* Eg:
|
||||
* {
|
||||
* 'indices.create': {
|
||||
* 'index': 'test'
|
||||
* },
|
||||
* 'warnings': [
|
||||
* '[index] is deprecated'
|
||||
* ]
|
||||
* }
|
||||
* becomes
|
||||
* {
|
||||
* method: 'indices.create',
|
||||
* params: {
|
||||
* index: 'test'
|
||||
* },
|
||||
* warnings: [
|
||||
* '[index] is deprecated'
|
||||
* ]
|
||||
* }
|
||||
* @param {object}
|
||||
* @returns {object}
|
||||
*/
|
||||
function parseDo (action) {
|
||||
return Object.keys(action).reduce((acc, val) => {
|
||||
switch (val) {
|
||||
case 'catch':
|
||||
acc.catch = action.catch
|
||||
break
|
||||
case 'warnings':
|
||||
acc.warnings = action.warnings
|
||||
break
|
||||
case 'node_selector':
|
||||
acc.node_selector = action.node_selector
|
||||
break
|
||||
default:
|
||||
// converts underscore to camelCase
|
||||
// eg: put_mapping => putMapping
|
||||
acc.method = val.replace(/_([a-z])/g, g => g[1].toUpperCase())
|
||||
acc.api = val
|
||||
acc.params = camelify(action[val])
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
function camelify (obj) {
|
||||
const newObj = {}
|
||||
|
||||
// TODO: add camelCase support for this fields
|
||||
const doNotCamelify = ['copy_settings']
|
||||
|
||||
for (const key in obj) {
|
||||
const val = obj[key]
|
||||
let newKey = key
|
||||
if (!~doNotCamelify.indexOf(key)) {
|
||||
// if the key starts with `_` we should not camelify the first occurence
|
||||
// eg: _source_include => _sourceInclude
|
||||
newKey = key[0] === '_'
|
||||
? '_' + key.slice(1).replace(/_([a-z])/g, k => k[1].toUpperCase())
|
||||
: key.replace(/_([a-z])/g, k => k[1].toUpperCase())
|
||||
}
|
||||
|
||||
if (
|
||||
val !== null &&
|
||||
typeof val === 'object' &&
|
||||
!Array.isArray(val) &&
|
||||
key !== 'body'
|
||||
) {
|
||||
newObj[newKey] = camelify(val)
|
||||
} else {
|
||||
newObj[newKey] = val
|
||||
}
|
||||
}
|
||||
|
||||
return newObj
|
||||
}
|
||||
}
|
||||
|
||||
function parseDoError (err, spec) {
|
||||
const httpErrors = {
|
||||
bad_request: 400,
|
||||
unauthorized: 401,
|
||||
forbidden: 403,
|
||||
missing: 404,
|
||||
request_timeout: 408,
|
||||
conflict: 409,
|
||||
unavailable: 503
|
||||
}
|
||||
|
||||
if (httpErrors[spec]) {
|
||||
return err.statusCode === httpErrors[spec]
|
||||
}
|
||||
|
||||
if (spec === 'request') {
|
||||
return err.statusCode >= 400 && err.statusCode < 600
|
||||
}
|
||||
|
||||
if (spec.startsWith('/') && spec.endsWith('/')) {
|
||||
return new RegExp(spec.slice(1, -1), 'g').test(JSON.stringify(err.body))
|
||||
}
|
||||
|
||||
if (spec === 'param') {
|
||||
return err instanceof ConfigurationError
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
function getSkip (arr) {
|
||||
if (!Array.isArray(arr)) return null
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
if (arr[i].skip) return arr[i].skip
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// Gets two *maybe* numbers and returns two valida numbers
|
||||
// it throws if one or both are not a valid number
|
||||
// the returned value is an array with the new values
|
||||
function getNumbers (val1, val2) {
|
||||
const val1Numeric = Number(val1)
|
||||
if (isNaN(val1Numeric)) {
|
||||
throw new TypeError(`val1 is not a valid number: ${val1}`)
|
||||
}
|
||||
const val2Numeric = Number(val2)
|
||||
if (isNaN(val2Numeric)) {
|
||||
throw new TypeError(`val2 is not a valid number: ${val2}`)
|
||||
}
|
||||
return [val1Numeric, val2Numeric]
|
||||
}
|
||||
|
||||
function getRandomInt (min, max) {
|
||||
return Math.floor(Math.random() * (max - min)) + min
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a skip
|
||||
* @param {object} the actions
|
||||
* @returns {TestRunner}
|
||||
*/
|
||||
function logSkip (action) {
|
||||
if (action.reason && action.version) {
|
||||
console.log(`Skip: ${action.reason} (${action.version})`)
|
||||
} else if (action.features) {
|
||||
console.log(`Skip: ${JSON.stringify(action.features)})`)
|
||||
} else {
|
||||
console.log('Skipped')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides if a test should be skipped
|
||||
* @param {object} the actions
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function shouldSkip (esVersion, action) {
|
||||
let shouldSkip = false
|
||||
// skip based on the version
|
||||
if (action.version) {
|
||||
if (action.version.trim() === 'all') return true
|
||||
const versions = action.version.split(',').filter(Boolean)
|
||||
for (const version of versions) {
|
||||
const [min, max] = version.split('-').map(v => v.trim())
|
||||
// if both `min` and `max` are specified
|
||||
if (min && max) {
|
||||
shouldSkip = semver.satisfies(esVersion, action.version)
|
||||
// if only `min` is specified
|
||||
} else if (min) {
|
||||
shouldSkip = semver.gte(esVersion, min)
|
||||
// if only `max` is specified
|
||||
} else if (max) {
|
||||
shouldSkip = semver.lte(esVersion, max)
|
||||
// something went wrong!
|
||||
} else {
|
||||
throw new Error(`skip: Bad version range: ${action.version}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldSkip) return true
|
||||
|
||||
if (action.features) {
|
||||
if (!Array.isArray(action.features)) action.features = [action.features]
|
||||
// returns true if one of the features is not present in the supportedFeatures
|
||||
shouldSkip = !!action.features.filter(f => !~supportedFeatures.indexOf(f)).length
|
||||
}
|
||||
|
||||
if (shouldSkip) return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
function isNDJson (api) {
|
||||
const spec = require(join(locations.specFolder, `${api}.json`))
|
||||
const { content_type } = spec[Object.keys(spec)[0]].headers
|
||||
return Boolean(content_type && content_type.includes('application/x-ndjson'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the array syntax of keys and values
|
||||
* eg: 'hits.hits.1.stuff' to 'hits.hits[1].stuff'
|
||||
* @param {object} the action to update
|
||||
* @returns {obj} the updated action
|
||||
*/
|
||||
// function updateArraySyntax (obj) {
|
||||
// const newObj = {}
|
||||
|
||||
// for (const key in obj) {
|
||||
// const newKey = key.replace(/\.\d{1,}\./g, v => `[${v.slice(1, -1)}].`)
|
||||
// const val = obj[key]
|
||||
|
||||
// if (typeof val === 'string') {
|
||||
// newObj[newKey] = val.replace(/\.\d{1,}\./g, v => `[${v.slice(1, -1)}].`)
|
||||
// } else if (val !== null && typeof val === 'object') {
|
||||
// newObj[newKey] = updateArraySyntax(val)
|
||||
// } else {
|
||||
// newObj[newKey] = val
|
||||
// }
|
||||
// }
|
||||
|
||||
// return newObj
|
||||
// }
|
||||
|
||||
module.exports = build
|
||||
@ -29,7 +29,7 @@ const { join } = require('path')
|
||||
const { locations } = require('../../scripts/download-artifacts')
|
||||
const packageJson = require('../../package.json')
|
||||
|
||||
const { delve, to, isXPackTemplate, sleep } = helper
|
||||
const { delve, to, isXPackTemplate, sleep, updateParams } = helper
|
||||
|
||||
const supportedFeatures = [
|
||||
'gtelte',
|
||||
@ -58,6 +58,12 @@ function build (opts = {}) {
|
||||
response = null
|
||||
stash.clear()
|
||||
|
||||
await client.cluster.health({
|
||||
wait_for_no_initializing_shards: true,
|
||||
timeout: '70s',
|
||||
level: 'shards'
|
||||
})
|
||||
|
||||
if (isXPack) {
|
||||
// wipe rollup jobs
|
||||
const jobsList = await client.rollup.getJobs({ id: '_all' })
|
||||
@ -98,16 +104,24 @@ function build (opts = {}) {
|
||||
const repositories = await client.snapshot.getRepository()
|
||||
for (const repository of Object.keys(repositories)) {
|
||||
await client.snapshot.delete({ repository, snapshot: '*' }, { ignore: [404] })
|
||||
await client.snapshot.deleteRepository({ repository }, { ignore: [404] })
|
||||
await client.snapshot.deleteRepository({ name: repository }, { ignore: [404] })
|
||||
}
|
||||
|
||||
if (isXPack) {
|
||||
// clean data streams
|
||||
await client.indices.deleteDataStream({ name: '*' })
|
||||
await client.indices.deleteDataStream({ name: '*', expand_wildcards: 'all' })
|
||||
}
|
||||
|
||||
// clean all indices
|
||||
await client.indices.delete({ index: '*,-.ds-ilm-history-*', expand_wildcards: 'open,closed,hidden' }, { ignore: [404] })
|
||||
await client.indices.delete({
|
||||
index: [
|
||||
'*',
|
||||
'-.ds-ilm-history-*'
|
||||
],
|
||||
expand_wildcards: 'open,closed,hidden'
|
||||
}, {
|
||||
ignore: [404]
|
||||
})
|
||||
|
||||
// delete templates
|
||||
const templates = await client.cat.templates({ h: 'name' })
|
||||
@ -150,7 +164,7 @@ function build (opts = {}) {
|
||||
const policies = await client.ilm.getLifecycle()
|
||||
for (const policy in policies) {
|
||||
if (preserveIlmPolicies.includes(policy)) continue
|
||||
await client.ilm.deleteLifecycle({ policy })
|
||||
await client.ilm.deleteLifecycle({ name: policy })
|
||||
}
|
||||
|
||||
// delete autofollow patterns
|
||||
@ -371,7 +385,7 @@ function build (opts = {}) {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async function doAction (action, stats) {
|
||||
const cmd = parseDo(action)
|
||||
const cmd = await updateParams(parseDo(action))
|
||||
let api
|
||||
try {
|
||||
api = delve(client, cmd.method).bind(client)
|
||||
@ -450,6 +464,7 @@ function build (opts = {}) {
|
||||
|
||||
if (action.catch) {
|
||||
stats.assertions += 1
|
||||
assert.ok(err, `Expecting an error, but instead got ${JSON.stringify(err)}, the response was ${JSON.stringify(result)}`)
|
||||
assert.ok(
|
||||
parseDoError(err, action.catch),
|
||||
`the error should be: ${action.catch}`
|
||||
@ -620,16 +635,11 @@ function match (val1, val2, action) {
|
||||
val2.startsWith('/') && (val2.endsWith('/\n') || val2.endsWith('/'))
|
||||
) {
|
||||
const regStr = val2
|
||||
// match all comments within a "regexp" match arg
|
||||
.replace(/([\S\s]?)#[^\n]*\n/g, (match, prevChar) => {
|
||||
return prevChar === '\\' ? match : `${prevChar}\n`
|
||||
})
|
||||
// remove all whitespace from the expression, all meaningful
|
||||
// whitespace is represented with \s
|
||||
.replace(/\s/g, '')
|
||||
.replace(/(^|[^\\])#.*/g, '$1')
|
||||
.replace(/(^|[^\\])\s+/g, '$1')
|
||||
.slice(1, -1)
|
||||
// 'm' adds the support for multiline regex
|
||||
assert.ok(new RegExp(regStr, 'm').test(val1), `should match pattern provided: ${val2}, action: ${JSON.stringify(action)}`)
|
||||
assert.ok(new RegExp(regStr, 'm').test(val1), `should match pattern provided: ${val2}, but got: ${val1}`)
|
||||
// tap.match(val1, new RegExp(regStr, 'm'), `should match pattern provided: ${val2}, action: ${JSON.stringify(action)}`)
|
||||
// everything else
|
||||
} else {
|
||||
@ -745,6 +755,11 @@ function parseDo (action) {
|
||||
acc.method = val.replace(/_([a-z])/g, g => g[1].toUpperCase())
|
||||
acc.api = val
|
||||
acc.params = action[val] // camelify(action[val])
|
||||
if (typeof acc.params.body === 'string') {
|
||||
try {
|
||||
acc.params.body = JSON.parse(acc.params.body)
|
||||
} catch (err) {}
|
||||
}
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
@ -432,3 +432,12 @@ test('caFingerprint can\'t be configured over http / 2', t => {
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('user agent is in the correct format', t => {
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
const agentRaw = client.transport[symbols.kHeaders]['user-agent'] || ''
|
||||
const agentSplit = agentRaw.split(/\s+/)
|
||||
t.equal(agentSplit[0].split('/')[0], 'elasticsearch-js')
|
||||
t.ok(/^\d+\.\d+\.\d+/.test(agentSplit[0].split('/')[1]))
|
||||
t.end()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user