Skip to content

Commit

Permalink
[KP] update ES client migration guide (elastic#73241)
Browse files Browse the repository at this point in the history
* add note about error format and FTR service

* add notice about lack of response typings

* more detailes example of search response type usage
  • Loading branch information
mshustov committed Aug 4, 2020
1 parent 80aef72 commit 49fa6b7
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 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,30 @@ 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';
type SearchSource = {...};
type SearchBody = SearchResponse<SearchSource>;
const { body } = await client.search<SearchBody>(...);
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

0 comments on commit 49fa6b7

Please sign in to comment.