|
1 | | -<p align="center"> |
2 | | - <img src="https://github.com/elastic/elasticsearch-py/raw/main/docs/logo-elastic-glyph-color.svg" width="20%" alt="Elastic logo" /> |
3 | | -</p> |
| 1 | +# :warning: This package is deprecated |
4 | 2 |
|
5 | | -# Elasticsearch Serverless Client |
6 | | - |
7 | | -[](https://github.com/elastic/elasticsearch-serverless-js/actions/workflows/tests.yml) |
8 | | - |
9 | | -This is the official Node.js Elastic client for the [**Elasticsearch Cloud Serverless** service](https://www.elastic.co/elasticsearch/serverless). |
10 | | -If you're looking to develop your Node.js application with the Elasticsearch Stack, you should look at the [Elasticsearch Client](https://github.com/elastic/elasticsearch-js) instead. |
11 | | -If you're looking to develop your Node.js application with Elastic Enterprise Search, you should look at the [Enterprise Search Client](https://github.com/elastic/enterprise-search-js/). |
12 | | - |
13 | | -## Installation |
14 | | - |
15 | | -Install via npm: |
16 | | - |
17 | | -```shell |
18 | | -npm install @elastic/elasticsearch-serverless |
19 | | -``` |
20 | | - |
21 | | -### Instantiate a Client |
22 | | - |
23 | | -```javascript |
24 | | -const { Client } = require('@elastic/elasticsearch-serverless') |
25 | | -const client = new Client({ |
26 | | - node: 'https://', // serverless project URL |
27 | | - auth: { apiKey: 'your_api_key' }, // project API key |
28 | | -}) |
29 | | -``` |
30 | | - |
31 | | -### Using the API |
32 | | - |
33 | | -Once you've instantiated a client with your API key and Elasticsearch endpoint, you can start ingesting documents into Elasticsearch Service. |
34 | | -You can use the **Bulk API** for this. |
35 | | -This API allows you to index, update and delete several documents in one request. |
36 | | -You call the `bulk` API on the client with a body parameter, an Array of hashes that define the action and a document. |
37 | | -Here's an example of indexing some classic books into the `books` index: |
38 | | - |
39 | | -```javascript |
40 | | -// First we build our data: |
41 | | -const body = [ |
42 | | - {name: "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}, |
43 | | - {name: "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}, |
44 | | - {name: "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}, |
45 | | - {name: "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}, |
46 | | - {name: "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}, |
47 | | - {name: "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311} |
48 | | -] |
49 | | - |
50 | | -// Then we send the data using the bulk API helper: |
51 | | -const result = await client.helpers.bulk({ |
52 | | - datasource: body, |
53 | | - onDocument (doc) { |
54 | | - // instructs the bulk indexer to add each item in `body` to the books index |
55 | | - // you can optionally inspect each `doc` object to alter what action is performed per document |
56 | | - return { |
57 | | - index: { _index: 'books' } |
58 | | - } |
59 | | - } |
60 | | -}) |
61 | | -``` |
62 | | - |
63 | | -Now that some data is available, you can search your documents using the **Search API**: |
64 | | - |
65 | | -```js |
66 | | -const result = await client.search({ |
67 | | - index: 'books', |
68 | | - query: { |
69 | | - match: { |
70 | | - author: 'Ray Bradbury' |
71 | | - } |
72 | | - } |
73 | | -}) |
74 | | -console.log(result.hits.hits) |
75 | | -``` |
76 | | - |
77 | | -## Development |
78 | | - |
79 | | -See [CONTRIBUTING](./CONTRIBUTING.md). |
80 | | - |
81 | | -### Docs |
82 | | - |
83 | | -Some general notes about this project can be found in [the docs directory](./docs/). |
| 3 | +This package is deprecated and no longer being maintained. All Elasticsearch serverless functionality has been merged into the [`@elastic/elasticsearch` client](https://www.github.com/elastic/elasticsearch-js). |
0 commit comments