[DOCS] Reorganizes Introduction and Installation chapters (#1315)
This commit is contained in:
committed by
GitHub
parent
7b11152a12
commit
88ef53b0ef
@ -5,6 +5,7 @@ This document contains code snippets to show you how to connect to various {es}
|
|||||||
providers.
|
providers.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Elastic Cloud
|
=== Elastic Cloud
|
||||||
|
|
||||||
If you are using https://www.elastic.co/cloud[Elastic Cloud], the client offers
|
If you are using https://www.elastic.co/cloud[Elastic Cloud], the client offers
|
||||||
@ -38,6 +39,7 @@ const client = new Client({
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Basic authentication
|
=== Basic authentication
|
||||||
|
|
||||||
You can provide your credentials by passing the `username` and `password`
|
You can provide your credentials by passing the `username` and `password`
|
||||||
@ -69,6 +71,7 @@ const client = new Client({
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== ApiKey authentication
|
=== ApiKey authentication
|
||||||
|
|
||||||
You can use the
|
You can use the
|
||||||
@ -106,6 +109,7 @@ const client = new Client({
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== SSL configuration
|
=== SSL configuration
|
||||||
|
|
||||||
Without any additional configuration you can specify `https://` node urls, and
|
Without any additional configuration you can specify `https://` node urls, and
|
||||||
|
|||||||
@ -6,6 +6,7 @@ to install with `npm install elasticsearch` – you will encounter some breaking
|
|||||||
changes.
|
changes.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Don’t panic!
|
=== Don’t panic!
|
||||||
|
|
||||||
Every breaking change was carefully weighed, and each is justified. Furthermore,
|
Every breaking change was carefully weighed, and each is justified. Furthermore,
|
||||||
@ -13,6 +14,7 @@ the new codebase has been rewritten with modern JavaScript and has been
|
|||||||
carefully designed to be easy to maintain.
|
carefully designed to be easy to maintain.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Breaking changes
|
=== Breaking changes
|
||||||
|
|
||||||
* Minimum supported version of Node.js is `v8`.
|
* Minimum supported version of Node.js is `v8`.
|
||||||
@ -209,6 +211,7 @@ client.transport.request({
|
|||||||
})
|
})
|
||||||
----
|
----
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Talk is cheap. Show me the code.
|
=== Talk is cheap. Show me the code.
|
||||||
|
|
||||||
You can find a code snippet with the old client below followed by the same code
|
You can find a code snippet with the old client below followed by the same code
|
||||||
|
|||||||
@ -17,7 +17,7 @@ const client = new Client({
|
|||||||
})
|
})
|
||||||
----
|
----
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Basic options
|
=== Basic options
|
||||||
|
|
||||||
[cols=2*]
|
[cols=2*]
|
||||||
@ -242,6 +242,7 @@ const client = new Client({
|
|||||||
|===
|
|===
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Advanced configuration
|
=== Advanced configuration
|
||||||
|
|
||||||
If you need to customize the client behavior heavily, you are in the right
|
If you need to customize the client behavior heavily, you are in the right
|
||||||
@ -253,6 +254,7 @@ place! The client allows you to customize the following internals:
|
|||||||
* `Serializer` class
|
* `Serializer` class
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== `Transport`
|
=== `Transport`
|
||||||
|
|
||||||
This class is responsible for performing the request to {es} and handling
|
This class is responsible for performing the request to {es} and handling
|
||||||
@ -287,6 +289,7 @@ class MyTransport extends Transport {
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== `ConnectionPool`
|
=== `ConnectionPool`
|
||||||
|
|
||||||
This class is responsible for keeping in memory all the {es} Connection that we
|
This class is responsible for keeping in memory all the {es} Connection that we
|
||||||
@ -310,6 +313,7 @@ const client = new Client({
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== `Connection`
|
=== `Connection`
|
||||||
|
|
||||||
This class represents a single node, it holds every information we have on the
|
This class represents a single node, it holds every information we have on the
|
||||||
@ -333,6 +337,7 @@ const client = new Client({
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== `Serializer`
|
=== `Serializer`
|
||||||
|
|
||||||
This class is responsible for the serialization of every request, it offers the
|
This class is responsible for the serialization of every request, it offers the
|
||||||
|
|||||||
@ -6,12 +6,16 @@ The client comes with an handy collection of helpers to give you a more comforta
|
|||||||
CAUTION: The client helpers are experimental, and the API may change in the next minor releases.
|
CAUTION: The client helpers are experimental, and the API may change in the next minor releases.
|
||||||
The helpers will not work in any Node.js version lower than 10.
|
The helpers will not work in any Node.js version lower than 10.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Bulk Helper
|
=== Bulk Helper
|
||||||
|
|
||||||
~Added~ ~in~ ~`v7.7.0`~
|
~Added~ ~in~ ~`v7.7.0`~
|
||||||
|
|
||||||
Running Bulk requests can be complex due to the shape of the API, this helper aims to provide a nicer developer experience around the Bulk API.
|
Running Bulk requests can be complex due to the shape of the API, this helper aims to provide a nicer developer experience around the Bulk API.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Usage
|
==== Usage
|
||||||
[source,js]
|
[source,js]
|
||||||
----
|
----
|
||||||
@ -150,8 +154,12 @@ const b = client.helpers.bulk({
|
|||||||
|
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Supported operations
|
==== Supported operations
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
===== Index
|
===== Index
|
||||||
[source,js]
|
[source,js]
|
||||||
----
|
----
|
||||||
@ -165,6 +173,8 @@ client.helpers.bulk({
|
|||||||
})
|
})
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
===== Create
|
===== Create
|
||||||
[source,js]
|
[source,js]
|
||||||
----
|
----
|
||||||
@ -178,7 +188,10 @@ client.helpers.bulk({
|
|||||||
})
|
})
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
===== Update
|
===== Update
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
----
|
----
|
||||||
client.helpers.bulk({
|
client.helpers.bulk({
|
||||||
@ -195,7 +208,10 @@ client.helpers.bulk({
|
|||||||
})
|
})
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
===== Delete
|
===== Delete
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
----
|
----
|
||||||
client.helpers.bulk({
|
client.helpers.bulk({
|
||||||
@ -208,7 +224,10 @@ client.helpers.bulk({
|
|||||||
})
|
})
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Abort a bulk operation
|
==== Abort a bulk operation
|
||||||
|
|
||||||
If needed, you can abort a bulk operation at any time. The bulk helper returns a https://promisesaplus.com/[thenable], which has an `abort` method.
|
If needed, you can abort a bulk operation at any time. The bulk helper returns a https://promisesaplus.com/[thenable], which has an `abort` method.
|
||||||
|
|
||||||
NOTE: The abort method will stop the execution of the bulk operation, but if you are using a concurrency higher than one, the operations that are already running will not be stopped.
|
NOTE: The abort method will stop the execution of the bulk operation, but if you are using a concurrency higher than one, the operations that are already running will not be stopped.
|
||||||
@ -235,7 +254,10 @@ const b = client.helpers.bulk({
|
|||||||
console.log(await b)
|
console.log(await b)
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Passing custom options to the Bulk API
|
==== Passing custom options to the Bulk API
|
||||||
|
|
||||||
You can pass any option supported by the link:{ref}/docs-bulk.html#docs-bulk-api-query-params[Bulk API] to the helper, and the helper will use those options in conjuction with the Bulk
|
You can pass any option supported by the link:{ref}/docs-bulk.html#docs-bulk-api-query-params[Bulk API] to the helper, and the helper will use those options in conjuction with the Bulk
|
||||||
API call.
|
API call.
|
||||||
|
|
||||||
@ -252,6 +274,8 @@ const result = await client.helpers.bulk({
|
|||||||
})
|
})
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Usage with an async generator
|
==== Usage with an async generator
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
@ -282,6 +306,8 @@ const result = await client.helpers.bulk({
|
|||||||
console.log(result)
|
console.log(result)
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Multi Search Helper
|
=== Multi Search Helper
|
||||||
|
|
||||||
~Added~ ~in~ ~`v7.8.0`~
|
~Added~ ~in~ ~`v7.8.0`~
|
||||||
@ -290,7 +316,10 @@ If you are sending search request at a high rate, this helper might be useful fo
|
|||||||
It will use the mutli search API under the hood to batch the requests and improve the overall performances of your application. +
|
It will use the mutli search API under the hood to batch the requests and improve the overall performances of your application. +
|
||||||
The `result` exposes a `documents` property as well, which allows you to access directly the hits sources.
|
The `result` exposes a `documents` property as well, which allows you to access directly the hits sources.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Usage
|
==== Usage
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
----
|
----
|
||||||
const { Client } = require('@elastic/elasticsearch')
|
const { Client } = require('@elastic/elasticsearch')
|
||||||
@ -372,7 +401,10 @@ const m = client.helpers.msearch({
|
|||||||
|
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Stopping the Msearch Helper
|
==== Stopping the Msearch Helper
|
||||||
|
|
||||||
If needed, you can stop a msearch processor at any time. The msearch helper returns a https://promisesaplus.com/[thenable], which has an `stop` method.
|
If needed, you can stop a msearch processor at any time. The msearch helper returns a https://promisesaplus.com/[thenable], which has an `stop` method.
|
||||||
|
|
||||||
If you are creating multiple msearch helpers instances and using them for a limitied period of time, remember to always use the `stop` method once you have finished using them, otherwise your application will start leaking memory.
|
If you are creating multiple msearch helpers instances and using them for a limitied period of time, remember to always use the `stop` method once you have finished using them, otherwise your application will start leaking memory.
|
||||||
@ -405,6 +437,8 @@ m.search(
|
|||||||
setImmediate(() => m.stop())
|
setImmediate(() => m.stop())
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Search Helper
|
=== Search Helper
|
||||||
|
|
||||||
~Added~ ~in~ ~`v7.7.0`~
|
~Added~ ~in~ ~`v7.7.0`~
|
||||||
@ -430,6 +464,8 @@ for (const doc of documents) {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Scroll Search Helper
|
=== Scroll Search Helper
|
||||||
|
|
||||||
~Added~ ~in~ ~`v7.7.0`~
|
~Added~ ~in~ ~`v7.7.0`~
|
||||||
@ -455,6 +491,8 @@ for await (const result of scrollSearch) {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Clear a scroll search
|
==== Clear a scroll search
|
||||||
|
|
||||||
If needed, you can clear a scroll search by calling `result.clear()`:
|
If needed, you can clear a scroll search by calling `result.clear()`:
|
||||||
@ -468,6 +506,8 @@ for await (const result of scrollSearch) {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Quickly getting the documents
|
==== Quickly getting the documents
|
||||||
|
|
||||||
If you only need the documents from the result of a scroll search, you can access them via `result.documents`:
|
If you only need the documents from the result of a scroll search, you can access them via `result.documents`:
|
||||||
@ -479,6 +519,8 @@ for await (const result of scrollSearch) {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Scroll Documents Helper
|
=== Scroll Documents Helper
|
||||||
|
|
||||||
~Added~ ~in~ ~`v7.7.0`~
|
~Added~ ~in~ ~`v7.7.0`~
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
include::{asciidoc-dir}/../../shared/attributes.asciidoc[]
|
include::{asciidoc-dir}/../../shared/attributes.asciidoc[]
|
||||||
|
|
||||||
include::introduction.asciidoc[]
|
include::introduction.asciidoc[]
|
||||||
|
include::installation.asciidoc[]
|
||||||
include::usage.asciidoc[]
|
include::usage.asciidoc[]
|
||||||
include::configuration.asciidoc[]
|
include::configuration.asciidoc[]
|
||||||
include::reference.asciidoc[]
|
include::reference.asciidoc[]
|
||||||
|
|||||||
21
docs/installation.asciidoc
Normal file
21
docs/installation.asciidoc
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
[[installation]]
|
||||||
|
== Installation
|
||||||
|
|
||||||
|
This page guides you through the installation process of the client.
|
||||||
|
|
||||||
|
To install the latest version of the client, run the following command:
|
||||||
|
|
||||||
|
[source,sh]
|
||||||
|
----
|
||||||
|
npm install @elastic/elasticsearch
|
||||||
|
----
|
||||||
|
|
||||||
|
To install a specific major version of the client, run the following command:
|
||||||
|
|
||||||
|
[source,sh]
|
||||||
|
----
|
||||||
|
npm install @elastic/elasticsearch@<major>
|
||||||
|
----
|
||||||
|
|
||||||
|
To learn more about the supported major versions, please refer to the
|
||||||
|
<<js-compatibility-matrix>>.
|
||||||
@ -1,9 +1,11 @@
|
|||||||
[[introduction]]
|
[[introduction]]
|
||||||
== Introduction
|
== Introduction
|
||||||
|
|
||||||
The official Node.js client for {es}.
|
This is the official Node.js client for {es}. This page gives a quick overview
|
||||||
|
about the features of the client.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Features
|
=== Features
|
||||||
|
|
||||||
* One-to-one mapping with REST API.
|
* One-to-one mapping with REST API.
|
||||||
@ -15,15 +17,9 @@ The official Node.js client for {es}.
|
|||||||
* TypeScript support out of the box.
|
* TypeScript support out of the box.
|
||||||
|
|
||||||
|
|
||||||
=== Install
|
[discrete]
|
||||||
|
[[js-compatibility-matrix]]
|
||||||
[source,sh]
|
=== Compatibility matrix
|
||||||
----
|
|
||||||
npm install @elastic/elasticsearch
|
|
||||||
----
|
|
||||||
|
|
||||||
|
|
||||||
=== Compatibility
|
|
||||||
|
|
||||||
The minimum supported version of Node.js is `v8`.
|
The minimum supported version of Node.js is `v8`.
|
||||||
|
|
||||||
@ -50,13 +46,8 @@ using.
|
|||||||
|`5.x`
|
|`5.x`
|
||||||
|===
|
|===
|
||||||
|
|
||||||
To install a specific major version of the client, run the following command:
|
|
||||||
|
|
||||||
----
|
|
||||||
npm install @elastic/elasticsearch@<major>
|
|
||||||
----
|
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Browser
|
==== Browser
|
||||||
|
|
||||||
WARNING: There is no official support for the browser environment. It exposes
|
WARNING: There is no official support for the browser environment. It exposes
|
||||||
@ -64,6 +55,7 @@ your {es} instance to everyone, which could lead to security issues. We
|
|||||||
recommend you to write a lightweight proxy that uses this client instead.
|
recommend you to write a lightweight proxy that uses this client instead.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Quick start
|
=== Quick start
|
||||||
|
|
||||||
First of all, require, then initialize the client:
|
First of all, require, then initialize the client:
|
||||||
@ -176,7 +168,7 @@ async function run () {
|
|||||||
run().catch(console.log)
|
run().catch(console.log)
|
||||||
----
|
----
|
||||||
|
|
||||||
|
[discrete]
|
||||||
==== Install multiple versions
|
==== Install multiple versions
|
||||||
|
|
||||||
If you are using multiple versions of {es}, you need to use multiple versions of
|
If you are using multiple versions of {es}, you need to use multiple versions of
|
||||||
|
|||||||
@ -11,6 +11,8 @@ a large codebase with many events happening at the same time.
|
|||||||
To help you with this, the client offers you a correlation id system and other
|
To help you with this, the client offers you a correlation id system and other
|
||||||
features. Let's see them in action.
|
features. Let's see them in action.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Events
|
=== Events
|
||||||
|
|
||||||
The client is an event emitter, this means that you can listen for its event and
|
The client is an event emitter, this means that you can listen for its event and
|
||||||
@ -126,6 +128,7 @@ request: {
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Correlation id
|
=== Correlation id
|
||||||
|
|
||||||
Correlating events can be quite hard, especially if there are many events at the
|
Correlating events can be quite hard, especially if there are many events at the
|
||||||
@ -193,6 +196,7 @@ client.search({
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Context object
|
=== Context object
|
||||||
|
|
||||||
Sometimes, you might need to make some custom data available in your events, you
|
Sometimes, you might need to make some custom data available in your events, you
|
||||||
@ -268,6 +272,7 @@ client.search({
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Client name
|
=== Client name
|
||||||
|
|
||||||
If you are using multiple instances of the client or if you are using multiple
|
If you are using multiple instances of the client or if you are using multiple
|
||||||
@ -321,6 +326,7 @@ child.search({
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== X-Opaque-Id support
|
=== X-Opaque-Id support
|
||||||
|
|
||||||
To improve the overall observability, the client offers an easy way to configure
|
To improve the overall observability, the client offers an easy way to configure
|
||||||
|
|||||||
@ -33,6 +33,8 @@ the `Connection` component since it has very few responsibilities and
|
|||||||
it does not interact with other internal components other than getting
|
it does not interact with other internal components other than getting
|
||||||
requests and returning responses.
|
requests and returning responses.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== `@elastic/elasticsearch-mock`
|
=== `@elastic/elasticsearch-mock`
|
||||||
|
|
||||||
Writing each time a mock for your test can be annoying and error-prone,
|
Writing each time a mock for your test can be annoying and error-prone,
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
[[typescript]]
|
[[typescript]]
|
||||||
|
|
||||||
== TypeScript support
|
== TypeScript support
|
||||||
|
|
||||||
The client offers a first-class support for TypeScript, since it ships the type
|
The client offers a first-class support for TypeScript, since it ships the type
|
||||||
@ -39,6 +38,7 @@ console.log(response.body)
|
|||||||
You don't have to specify all the generics, but the order must be respected.
|
You don't have to specify all the generics, but the order must be respected.
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== A complete example
|
=== A complete example
|
||||||
|
|
||||||
[source,ts]
|
[source,ts]
|
||||||
|
|||||||
@ -81,6 +81,7 @@ client.search({
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Aborting a request
|
=== 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 calling the `request.abort()` method returned by the API.
|
||||||
@ -134,6 +135,7 @@ request.abort()
|
|||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Request specific options
|
=== Request specific options
|
||||||
If needed you can pass request specific options in a second object:
|
If needed you can pass request specific options in a second object:
|
||||||
|
|
||||||
@ -210,6 +212,8 @@ _Default:_ `null`
|
|||||||
_Default:_ `null`
|
_Default:_ `null`
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Connecting through a proxy
|
=== Connecting through a proxy
|
||||||
|
|
||||||
~Added~ ~in~ ~`v7.10.0`~
|
~Added~ ~in~ ~`v7.10.0`~
|
||||||
@ -250,6 +254,8 @@ const client = new Client({
|
|||||||
})
|
})
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[discrete]
|
||||||
=== Error handling
|
=== Error handling
|
||||||
|
|
||||||
The client exposes a variety of error objects that you can use to enhance your
|
The client exposes a variety of error objects that you can use to enhance your
|
||||||
|
|||||||
Reference in New Issue
Block a user