Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KP] update ES client migration guide #73241

Merged
merged 5 commits into from
Aug 4, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/core/MIGRATION_EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ const { body } = await client.asInternalUser.get<GetResponse>({ id: 'id' });
const { body } = await client.asInternalUser.get({ id: 'id' });
```

- the returned error types changed
- the returned error types changed

There are no longer specific errors for every HTTP status code (such as `BadRequest` or `NotFound`). A generic
`ResponseError` with the specific `statusCode` is thrown instead.
Expand All @@ -1097,6 +1097,7 @@ try {
if(e instanceof errors.NotFound) {
// do something
}
if(e.status === 401) {}
}
```

Expand All @@ -1115,6 +1116,7 @@ try {
if(e.name === 'ResponseError' && e.statusCode === 404) {
// do something
}
if(e.statusCode === 401) {...}
}
```

Expand Down Expand Up @@ -1178,6 +1180,28 @@ const request = client.asCurrentUser.ping({}, {
});
```

- the new client doesn't provide exhaustive typings for the response object yet. You might have to copy
response type definitions from the Legacy Elasticsearch library until https://github.com/elastic/elasticsearch-js/pull/970 merged.

```ts
// platform provides a few typings for internal purposes
import { SearchResponse } from 'src/core/server';
const { body } = await client.search<SearchResponse<any>>(...)
mshustov marked this conversation as resolved.
Show resolved Hide resolved
interface Info {...}
const { body } = await client.info<Info>(...)
```

- Functional tests are subject to migration to the new client as well.
before:
```ts
const client = getService('legacyEs');
```

after:
```ts
const client = getService('es');
```

Please refer to the [Breaking changes list](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/breaking-changes.html)
for more information about the changes between the legacy and new client.

Expand Down