6
6
7
7
The official Node.js client for Elasticsearch.
8
8
9
- ## Features
10
- - One-to-one mapping with REST API.
11
- - Generalized, pluggable architecture.
12
- - Configurable, automatic discovery of cluster nodes.
13
- - Persistent, Keep-Alive connections.
14
- - Load balancing across all available nodes.
15
- - Child client support.
16
- - TypeScript support out of the box.
17
-
18
- ## Install
19
- ```
20
- npm install @elastic/elasticsearch
21
- ```
9
+ ## Installation
10
+
11
+ Refer to the [ Installation section] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/getting-started-js.html#_installation )
12
+ of the getting started documentation.
13
+
14
+ ## Connecting
15
+
16
+ Refer to the [ Connecting section] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/getting-started-js.html#_connecting )
17
+ of the getting started documentation.
18
+
19
+ ## Usage
20
+
21
+ * [ Creating an index] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/getting-started-js.html#_creating_an_index )
22
+ * [ Indexing a document] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/getting-started-js.html#_indexing_documents )
23
+ * [ Getting documents] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/getting-started-js.html#_getting_documents )
24
+ * [ Searching documents] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/getting-started-js.html#_searching_documents )
25
+ * [ Updating documents] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/getting-started-js.html#_updating_documents )
26
+ * [ Deleting documents] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/getting-started-js.html#_deleting_documents )
27
+ * [ Deleting an index] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/getting-started-js.html#_deleting_an_index )
22
28
23
29
### Node.js support
24
30
@@ -72,93 +78,45 @@ We recommend that you write a lightweight proxy that uses this client instead, y
72
78
73
79
## Documentation
74
80
75
- - [ Introduction] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/introduction.html )
76
- - [ Usage] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#client-usage )
77
- - [ Client configuration] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-configuration.html )
78
- - [ API reference] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html )
79
- - [ Authentication] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#authentication )
80
- - [ Observability] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/observability.html )
81
- - [ Creating a child client] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/child.html )
82
- - [ Client helpers] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-helpers.html )
83
- - [ Typescript support] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/typescript.html )
84
- - [ Testing] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-testing.html )
85
- - [ Examples] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/examples.html )
86
-
87
- ## Quick start
88
-
89
- ``` js
90
- ' use strict'
91
-
92
- const { Client } = require (' @elastic/elasticsearch' )
93
- const client = new Client ({
94
- cloud: { id: ' <cloud-id>' },
95
- auth: { apiKey: ' base64EncodedKey' }
96
- })
97
-
98
- async function run () {
99
- // Let's start by indexing some data
100
- await client .index ({
101
- index: ' game-of-thrones' ,
102
- document : {
103
- character: ' Ned Stark' ,
104
- quote: ' Winter is coming.'
105
- }
106
- })
107
-
108
- await client .index ({
109
- index: ' game-of-thrones' ,
110
- document : {
111
- character: ' Daenerys Targaryen' ,
112
- quote: ' I am the blood of the dragon.'
113
- }
114
- })
115
-
116
- await client .index ({
117
- index: ' game-of-thrones' ,
118
- document : {
119
- character: ' Tyrion Lannister' ,
120
- quote: ' A mind needs books like a sword needs a whetstone.'
121
- }
122
- })
123
-
124
- // here we are forcing an index refresh, otherwise we will not
125
- // get any result in the consequent search
126
- await client .indices .refresh ({ index: ' game-of-thrones' })
127
-
128
- // Let's search!
129
- const result = await client .search ({
130
- index: ' game-of-thrones' ,
131
- query: {
132
- match: { quote: ' winter' }
133
- }
134
- })
135
-
136
- console .log (result .hits .hits )
137
- }
138
-
139
- run ().catch (console .log )
140
- ```
81
+ * [ Introduction] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/introduction.html )
82
+ * [ Usage] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#client-usage )
83
+ * [ Client configuration] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-configuration.html )
84
+ * [ API reference] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html )
85
+ * [ Authentication] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#authentication )
86
+ * [ Observability] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/observability.html )
87
+ * [ Creating a child client] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/child.html )
88
+ * [ Client helpers] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-helpers.html )
89
+ * [ Typescript support] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/typescript.html )
90
+ * [ Testing] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-testing.html )
91
+ * [ Examples] ( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/examples.html )
141
92
142
93
## Install multiple versions
143
94
If you are using multiple versions of Elasticsearch, you need to use multiple versions of the client. In the past, install multiple versions of the same package was not possible, but with ` npm v6.9 ` , you can do that via aliasing.
144
95
145
96
The command you must run to install different version of the client is:
97
+
146
98
``` sh
147
99
npm install < alias> @npm:@elastic/elasticsearch@< version>
148
100
```
149
- So for example if you need to install ` 7.x ` and ` 6.x ` , you will run
101
+
102
+ So for example if you need to install ` 7.x ` and ` 6.x ` , you will run:
103
+
150
104
``` sh
151
105
npm install es6@npm:@elastic/elasticsearch@6
152
106
npm install es7@npm:@elastic/elasticsearch@7
153
107
```
108
+
154
109
And your ` package.json ` will look like the following:
110
+
155
111
``` json
156
112
"dependencies" : {
157
113
"es6" : " npm:@elastic/elasticsearch@^6.7.0" ,
158
114
"es7" : " npm:@elastic/elasticsearch@^7.0.0"
159
115
}
160
116
```
117
+
161
118
You will require the packages from your code by using the alias you have defined.
119
+
162
120
``` js
163
121
const { Client: Client6 } = require (' es6' )
164
122
const { Client: Client7 } = require (' es7' )
@@ -176,7 +134,10 @@ client6.info().then(console.log, console.log)
176
134
client7 .info ().then (console .log , console .log )
177
135
```
178
136
179
- 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:
137
+ Finally, if you want to install the client for the next version of Elasticsearch
138
+ * (the one that lives in Elasticsearch’s main branch)* , you can use the following
139
+ command:
140
+
180
141
``` sh
181
142
npm install esmain@github:elastic/elasticsearch-js
182
143
```
0 commit comments