Skip to content

Update docs for v8 #1572

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 13 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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

Expand All @@ -53,7 +54,7 @@ Elasticsearch language clients are only backwards compatible with default distri

| Elasticsearch Version | Client Version |
| --------------------- |----------------|
| `main` | `main` |
| `8.x` | `8.x` |
| `7.x` | `7.x` |
| `6.x` | `6.x` |
| `5.x` | `5.x` |
Expand All @@ -74,60 +75,16 @@ 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)
- [Examples](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/examples.html)

## 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'

Expand All @@ -138,26 +95,23 @@ 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.'
}
})

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

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.'
}
Expand All @@ -168,17 +122,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)
Expand Down Expand Up @@ -211,13 +162,13 @@ const { Client: Client7 } = require('es7')
const client6 = new Client6({ node: 'http://localhost:9200' })
const client7 = new Client7({ node: 'http://localhost:9201' })

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
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-config.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ 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
}
Expand Down
28 changes: 4 additions & 24 deletions docs/basic-config.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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' }
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
})
----
|===
Loading