Skip to content

Commit 5086a19

Browse files
committed
Update docs for v8 (#1572)
1 parent 221f9a9 commit 5086a19

37 files changed

+311
-1260
lines changed

README.md

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ of `^7.10.0`).
5151
| --------------- |------------------| ---------------------- |
5252
| `8.x` | `December 2019` | `7.11` (early 2021) |
5353
| `10.x` | `April 2021` | `7.12` (mid 2021) |
54+
| `12.x` | `April 2022` | `8.2` (early 2022) |
5455

5556
### Compatibility
5657

@@ -59,7 +60,7 @@ Elasticsearch language clients are only backwards compatible with default distri
5960

6061
| Elasticsearch Version | Client Version |
6162
| --------------------- |----------------|
62-
| `master` | `master` |
63+
| `8.x` | `8.x` |
6364
| `7.x` | `7.x` |
6465
| `6.x` | `6.x` |
6566
| `5.x` | `5.x` |
@@ -80,60 +81,16 @@ We recommend that you write a lightweight proxy that uses this client instead, y
8081
- [Usage](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#client-usage)
8182
- [Client configuration](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-configuration.html)
8283
- [API reference](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html)
83-
- [Breaking changes coming from the old client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/breaking-changes.html)
8484
- [Authentication](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#authentication)
8585
- [Observability](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/observability.html)
8686
- [Creating a child client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/child.html)
87-
- [Extend the client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/extend.html)
8887
- [Client helpers](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-helpers.html)
8988
- [Typescript support](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/typescript.html)
9089
- [Testing](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-testing.html)
9190
- [Examples](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/examples.html)
9291

9392
## Quick start
9493

95-
First of all, require the client and initialize it:
96-
```js
97-
const { Client } = require('@elastic/elasticsearch')
98-
const client = new Client({ node: 'http://localhost:9200' })
99-
```
100-
101-
You can use both the callback-style API and the promise-style API, both behave the same way.
102-
```js
103-
// promise API
104-
const result = await client.search({
105-
index: 'my-index',
106-
body: {
107-
query: {
108-
match: { hello: 'world' }
109-
}
110-
}
111-
})
112-
113-
// callback API
114-
client.search({
115-
index: 'my-index',
116-
body: {
117-
query: {
118-
match: { hello: 'world' }
119-
}
120-
}
121-
}, (err, result) => {
122-
if (err) console.log(err)
123-
})
124-
```
125-
The returned value of **every** API call is formed as follows:
126-
```ts
127-
{
128-
body: object | boolean
129-
statusCode: number
130-
headers: object
131-
warnings: [string]
132-
meta: object
133-
}
134-
```
135-
136-
Let's see a complete example!
13794
```js
13895
'use strict'
13996

@@ -144,26 +101,23 @@ async function run () {
144101
// Let's start by indexing some data
145102
await client.index({
146103
index: 'game-of-thrones',
147-
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
148-
body: {
104+
document: {
149105
character: 'Ned Stark',
150106
quote: 'Winter is coming.'
151107
}
152108
})
153109

154110
await client.index({
155111
index: 'game-of-thrones',
156-
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
157-
body: {
112+
document: {
158113
character: 'Daenerys Targaryen',
159114
quote: 'I am the blood of the dragon.'
160115
}
161116
})
162117

163118
await client.index({
164119
index: 'game-of-thrones',
165-
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
166-
body: {
120+
document: {
167121
character: 'Tyrion Lannister',
168122
quote: 'A mind needs books like a sword needs a whetstone.'
169123
}
@@ -174,17 +128,14 @@ async function run () {
174128
await client.indices.refresh({ index: 'game-of-thrones' })
175129

176130
// Let's search!
177-
const { body } = await client.search({
131+
const result= await client.search({
178132
index: 'game-of-thrones',
179-
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
180-
body: {
181-
query: {
182-
match: { quote: 'winter' }
183-
}
133+
query: {
134+
match: { quote: 'winter' }
184135
}
185136
})
186137

187-
console.log(body.hits.hits)
138+
console.log(result.hits.hits)
188139
}
189140

190141
run().catch(console.log)
@@ -217,13 +168,13 @@ const { Client: Client7 } = require('es7')
217168
const client6 = new Client6({ node: 'http://localhost:9200' })
218169
const client7 = new Client7({ node: 'http://localhost:9201' })
219170

220-
client6.info(console.log)
221-
client7.info(console.log)
171+
client6.info().then(console.log, console.log)
172+
client7.info().then(console.log, console.log)
222173
```
223174

224-
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:
175+
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:
225176
```sh
226-
npm install esmaster@github:elastic/elasticsearch-js
177+
npm install esmain@github:elastic/elasticsearch-js
227178
```
228179

229180
## License

docs/advanced-config.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ is performed here, this means that if you want to swap the default HTTP client
4545

4646
[source,js]
4747
----
48-
const { Client, Connection } = require('@elastic/elasticsearch')
48+
const { Client, BaseConnection } = require('@elastic/elasticsearch')
4949
50-
class MyConnection extends Connection {
50+
class MyConnection extends BaseConnection {
5151
request (params, callback) {
5252
// your code
5353
}

docs/basic-config.asciidoc

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Or it can be an object (or an array of objects) that represents the node:
3232
----
3333
node: {
3434
url: new URL('http://localhost:9200'),
35-
ssl: 'ssl options',
35+
tls: 'tls options',
3636
agent: 'http agent options',
3737
id: 'custom node id',
3838
headers: { 'custom': 'headers' }
@@ -118,8 +118,8 @@ _Default:_ `false`
118118
_Options:_ `'gzip'`, `false` +
119119
_Default:_ `false`
120120

121-
|`ssl`
122-
|`http.SecureContextOptions` - ssl https://nodejs.org/api/tls.html[configuraton]. +
121+
|`tls`
122+
|`http.SecureContextOptions` - tls https://nodejs.org/api/tls.html[configuraton]. +
123123
_Default:_ `null`
124124

125125
|`proxy`
@@ -267,24 +267,4 @@ _Default:_ `null`
267267
|`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 +
268268
_Default:_ `null`
269269

270-
|===
271-
272-
[discrete]
273-
==== Performances considerations
274-
275-
By default, the client will protection you against prototype poisoning attacks.
276-
Read https://web.archive.org/web/20200319091159/https://hueniverse.com/square-brackets-are-the-enemy-ff5b9fd8a3e8?gi=184a27ee2a08[this article] to learn more.
277-
If needed you can disable prototype poisoning protection entirely or one of the two checks.
278-
Read the `secure-json-parse` https://github.com/fastify/secure-json-parse[documentation] to learn more.
279-
280-
While it's good to be safe, you should know that security always comes with a cost.
281-
With big enough payloads, this security check could causea drop in the overall performances,
282-
which might be a problem for your application.
283-
If you know you can trust the data stored in Elasticsearch, you can safely disable this check.
284-
285-
[source,js]
286-
----
287-
const client = new Client({
288-
disablePrototypePoisoningProtection: true
289-
})
290-
----
270+
|===

0 commit comments

Comments
 (0)