Skip to content

Commit 111d126

Browse files
github-actions[bot]JoshMockszabosteve
authored
[DOCS] Adds getting started content based on the template (#1929) (#1931)
Co-authored-by: Josh Mock <joshua.mock@elastic.co> Co-authored-by: István Zoltán Szabó <szabosteve@gmail.com>
1 parent 135abcb commit 111d126

File tree

5 files changed

+171
-60
lines changed

5 files changed

+171
-60
lines changed

docs/getting-started.asciidoc

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
[[getting-started-js]]
2+
== Getting started
3+
4+
This page guides you through the installation process of the Node.js client,
5+
shows you how to instantiate the client, and how to perform basic Elasticsearch
6+
operations with it.
7+
8+
[discrete]
9+
=== Requirements
10+
11+
* https://nodejs.org/[Node.js] version 14.x or newer
12+
* https://docs.npmjs.com/downloading-and-installing-node-js-and-npm[`npm`], usually bundled with Node.js
13+
14+
[discrete]
15+
=== Installation
16+
17+
To install the latest version of the client, run the following command:
18+
19+
[source,shell]
20+
--------------------------
21+
npm install @elastic/elasticsearch
22+
--------------------------
23+
24+
Refer to the <<installation>> page to learn more.
25+
26+
27+
[discrete]
28+
=== Connecting
29+
30+
You can connect to the Elastic Cloud using an API key and the Elasticsearch
31+
endpoint.
32+
33+
[source,js]
34+
----
35+
const { Client } = require('@elastic/elasticsearch')
36+
const client = new Client({
37+
node: 'https://...', // Elasticsearch endpoint
38+
auth: {
39+
apiKey: { // API key ID and secret
40+
id: 'foo',
41+
api_key: 'bar',
42+
}
43+
}
44+
})
45+
----
46+
47+
Your Elasticsearch endpoint can be found on the **My deployment** page of your
48+
deployment:
49+
50+
image::images/es-endpoint.jpg[alt="Finding Elasticsearch endpoint",align="center"]
51+
52+
You can generate an API key on the **Management** page under Security.
53+
54+
image::images/create-api-key.png[alt="Create API key",align="center"]
55+
56+
For other connection options, refer to the <<client-connecting>> section.
57+
58+
59+
[discrete]
60+
=== Operations
61+
62+
Time to use Elasticsearch! This section walks you through the basic, and most
63+
important, operations of Elasticsearch.
64+
65+
66+
[discrete]
67+
==== Creating an index
68+
69+
This is how you create the `my_index` index:
70+
71+
[source,js]
72+
----
73+
await client.indices.create({ index: 'my_index' })
74+
----
75+
76+
77+
[discrete]
78+
==== Indexing documents
79+
80+
This is a simple way of indexing a document:
81+
82+
[source,js]
83+
----
84+
await client.index({
85+
index: 'my_index',
86+
id: 'my_document_id',
87+
document: {
88+
foo: 'foo',
89+
bar: 'bar',
90+
},
91+
})
92+
----
93+
94+
95+
[discrete]
96+
==== Getting documents
97+
98+
You can get documents by using the following code:
99+
100+
[source,js]
101+
----
102+
await client.get({
103+
index: 'my_index',
104+
id: 'my_document_id',
105+
})
106+
----
107+
108+
109+
[discrete]
110+
==== Searching documents
111+
112+
This is how you can create a single match query with the client:
113+
114+
[source,js]
115+
----
116+
await client.search({
117+
query: {
118+
match: {
119+
foo: 'foo'
120+
}
121+
}
122+
})
123+
----
124+
125+
126+
[discrete]
127+
==== Updating documents
128+
129+
This is how you can update a document, for example to add a new field:
130+
131+
[source,js]
132+
----
133+
await client.update({
134+
index: 'my_index',
135+
id: 'my_document_id',
136+
doc: {
137+
foo: 'bar',
138+
new_field: 'new value'
139+
}
140+
})
141+
----
142+
143+
144+
[discrete]
145+
==== Deleting documents
146+
147+
[source,js]
148+
----
149+
await client.delete({
150+
index: 'my_index',
151+
id: 'my_document_id',
152+
})
153+
----
154+
155+
156+
[discrete]
157+
==== Deleting an index
158+
159+
[source,js]
160+
----
161+
await client.indices.delete({ index: 'my_index' })
162+
----
163+
164+
165+
[discrete]
166+
== Further reading
167+
168+
* Use <<client-helpers>> for a more comfortable experience with the APIs.
169+
* For an elaborate example of how to ingest data into Elastic Cloud,
170+
refer to {cloud}/ec-getting-started-node-js.html[this page].

docs/images/create-api-key.png

78.7 KB
Loading

docs/images/es-endpoint.jpg

361 KB
Loading

docs/index.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include::{asciidoc-dir}/../../shared/versions/stack/{source_branch}.asciidoc[]
44
include::{asciidoc-dir}/../../shared/attributes.asciidoc[]
55

66
include::introduction.asciidoc[]
7+
include::getting-started.asciidoc[]
78
include::changelog.asciidoc[]
89
include::installation.asciidoc[]
910
include::connecting.asciidoc[]

docs/introduction.asciidoc

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,66 +17,6 @@ about the features of the client.
1717
* TypeScript support out of the box.
1818

1919

20-
[discrete]
21-
=== Quick start
22-
23-
[source,js]
24-
----
25-
'use strict'
26-
27-
const { Client } = require('@elastic/elasticsearch')
28-
const client = new Client({
29-
cloud: { id: '<cloud-id>' },
30-
auth: { apiKey: 'base64EncodedKey' }
31-
})
32-
33-
async function run () {
34-
// Let's start by indexing some data
35-
await client.index({
36-
index: 'game-of-thrones',
37-
document: {
38-
character: 'Ned Stark',
39-
quote: 'Winter is coming.'
40-
}
41-
})
42-
43-
await client.index({
44-
index: 'game-of-thrones',
45-
document: {
46-
character: 'Daenerys Targaryen',
47-
quote: 'I am the blood of the dragon.'
48-
}
49-
})
50-
51-
await client.index({
52-
index: 'game-of-thrones',
53-
document: {
54-
character: 'Tyrion Lannister',
55-
quote: 'A mind needs books like a sword needs a whetstone.'
56-
}
57-
})
58-
59-
// here we are forcing an index refresh, otherwise we will not
60-
// get any result in the consequent search
61-
await client.indices.refresh({ index: 'game-of-thrones' })
62-
63-
// Let's search!
64-
const result= await client.search({
65-
index: 'game-of-thrones',
66-
query: {
67-
match: { quote: 'winter' }
68-
}
69-
})
70-
71-
console.log(result.hits.hits)
72-
}
73-
74-
run().catch(console.log)
75-
----
76-
77-
TIP: For an elaborate example of how to ingest data into Elastic Cloud,
78-
refer to {cloud}/ec-getting-started-node-js.html[this page].
79-
8020
[discrete]
8121
==== Install multiple versions
8222

0 commit comments

Comments
 (0)