Skip to content

Commit 759138c

Browse files
authored
Update docs for v8 (#1572)
1 parent a0c5c98 commit 759138c

37 files changed

+311
-1260
lines changed

README.md

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ of `^7.10.0`).
4545
| --------------- |------------------| ---------------------- |
4646
| `8.x` | `December 2019` | `7.11` (early 2021) |
4747
| `10.x` | `April 2021` | `7.12` (mid 2021) |
48+
| `12.x` | `April 2022` | `8.2` (early 2022) |
4849

4950
### Compatibility
5051

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

5455
| Elasticsearch Version | Client Version |
5556
| --------------------- |----------------|
56-
| `main` | `main` |
57+
| `8.x` | `8.x` |
5758
| `7.x` | `7.x` |
5859
| `6.x` | `6.x` |
5960
| `5.x` | `5.x` |
@@ -74,60 +75,16 @@ We recommend that you write a lightweight proxy that uses this client instead, y
7475
- [Usage](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#client-usage)
7576
- [Client configuration](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-configuration.html)
7677
- [API reference](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html)
77-
- [Breaking changes coming from the old client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/breaking-changes.html)
7878
- [Authentication](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#authentication)
7979
- [Observability](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/observability.html)
8080
- [Creating a child client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/child.html)
81-
- [Extend the client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/extend.html)
8281
- [Client helpers](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-helpers.html)
8382
- [Typescript support](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/typescript.html)
8483
- [Testing](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-testing.html)
8584
- [Examples](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/examples.html)
8685

8786
## Quick start
8887

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

@@ -138,26 +95,23 @@ async function run () {
13895
// Let's start by indexing some data
13996
await client.index({
14097
index: 'game-of-thrones',
141-
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
142-
body: {
98+
document: {
14399
character: 'Ned Stark',
144100
quote: 'Winter is coming.'
145101
}
146102
})
147103

148104
await client.index({
149105
index: 'game-of-thrones',
150-
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
151-
body: {
106+
document: {
152107
character: 'Daenerys Targaryen',
153108
quote: 'I am the blood of the dragon.'
154109
}
155110
})
156111

157112
await client.index({
158113
index: 'game-of-thrones',
159-
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
160-
body: {
114+
document: {
161115
character: 'Tyrion Lannister',
162116
quote: 'A mind needs books like a sword needs a whetstone.'
163117
}
@@ -168,17 +122,14 @@ async function run () {
168122
await client.indices.refresh({ index: 'game-of-thrones' })
169123

170124
// Let's search!
171-
const { body } = await client.search({
125+
const result= await client.search({
172126
index: 'game-of-thrones',
173-
// type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
174-
body: {
175-
query: {
176-
match: { quote: 'winter' }
177-
}
127+
query: {
128+
match: { quote: 'winter' }
178129
}
179130
})
180131

181-
console.log(body.hits.hits)
132+
console.log(result.hits.hits)
182133
}
183134

184135
run().catch(console.log)
@@ -211,13 +162,13 @@ const { Client: Client7 } = require('es7')
211162
const client6 = new Client6({ node: 'http://localhost:9200' })
212163
const client7 = new Client7({ node: 'http://localhost:9201' })
213164

214-
client6.info(console.log)
215-
client7.info(console.log)
165+
client6.info().then(console.log, console.log)
166+
client7.info().then(console.log, console.log)
216167
```
217168

218-
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:
169+
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:
219170
```sh
220-
npm install esmaster@github:elastic/elasticsearch-js
171+
npm install esmain@github:elastic/elasticsearch-js
221172
```
222173

223174
## 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)