@@ -34,35 +34,28 @@ npm install @elastic/elasticsearch-serverless
34
34
35
35
## Instantiate a client
36
36
37
- You can instantiate a client by running the following command :
37
+ Initialize the client using your Serverless project URL and API key, both provided by Elastic :
38
38
39
39
``` js
40
40
const { Client } = require (' @elastic/elasticsearch-serverless' )
41
41
const client = new Client ({
42
- cloud : { id : ' <cloud-id> ' },
43
- auth: { apiKey: ' base64EncodedKey ' }
42
+ node : ' https:// ' , // serverless project URL
43
+ auth: { apiKey: ' your_api_key ' }, // project API key
44
44
})
45
45
```
46
46
47
- You can find the Elasticsearch endpoint on the Cloud deployment management page.
48
-
49
- <DocImage url = " images/copy-endpoint.gif" alt = " Copy the endpoint for Elasticsearch" />
50
-
51
- You can create a new API Key under ** Stack Management** > ** Security** :
52
-
53
- <DocImage url = " images/setup-api-key.gif" alt = " Create and copy Apy Key" />
47
+ To get API keys or the URL for a project, see <DocLink id = " serverlessElasticsearchGetStarted" />.
54
48
55
49
## Using the API
56
50
57
- After you instantiate a client with your API key and Elasticsearch endpoint, you
58
- can start ingesting documents into the Elasticsearch Service. You can use the
59
- Bulk API for this. This API enables you to index, update, and delete several
60
- documents in one request.
51
+ After you've initialized the client, you can start ingesting documents.
52
+ You can use the Bulk API for this.
53
+ This API enables you to index, update, and delete several documents in one request.
61
54
62
55
### Creating an index and ingesting documents
63
56
64
57
You can call the ` bulk ` helper API with a list of documents and a handler for
65
- what action to perform on each handler .
58
+ what action to perform on each document .
66
59
67
60
The following is an example of bulk indexing some classic books into the ` books `
68
61
index:
@@ -106,15 +99,14 @@ await client.get({
106
99
107
100
### Searching
108
101
109
- Now that some data is available, you can search your documents using the
110
- ** Search API** :
102
+ Now that some data is available, you can search your documents using the ** Search API** :
111
103
112
104
``` js
113
105
const result = await client .search ({
114
106
index: ' books' ,
115
107
query: {
116
108
match: {
117
- author: ' Ray Bradbury '
109
+ author: ' ray bradbury '
118
110
}
119
111
}
120
112
})
0 commit comments