|
| 1 | +--- |
| 2 | +title: Migration guide |
| 3 | +--- |
| 4 | + |
| 5 | +import Tabs from '@theme/Tabs'; |
| 6 | +import TabItem from '@theme/TabItem'; |
| 7 | + |
| 8 | +This document lists every known breaking change, not all of them may affect your application. |
| 9 | + |
| 10 | +:::caution |
| 11 | + |
| 12 | +The amount of changes in this new version is significant. If you were using a version older than v4, please also read [this migration guide](https://www.algolia.com/doc/api-client/getting-started/upgrade-guides/javascript/) |
| 13 | + |
| 14 | +**You should thoroughly test your application once the migration is over.** |
| 15 | + |
| 16 | +::: |
| 17 | + |
| 18 | +## Common breaking changes |
| 19 | + |
| 20 | +The changes below are effective on all of the API clients. |
| 21 | + |
| 22 | +| Previous | Latest | Description | |
| 23 | +| ----------- | :---------- | :------------------------------------------------- | |
| 24 | +| `initIndex` | **removed** | All methods are now available at the client level. | |
| 25 | + |
| 26 | +## API Client specific breaking changes |
| 27 | + |
| 28 | +The changes below are effective on the selected API client. |
| 29 | + |
| 30 | +For informations regarding the installation of the package, please see [the installation page](/docs/api-clients/installation) |
| 31 | + |
| 32 | +<Tabs |
| 33 | + groupId="language" |
| 34 | + defaultValue="js" |
| 35 | + values={[ |
| 36 | + { label: 'JavaScript', value: 'js', } |
| 37 | + ] |
| 38 | +}> |
| 39 | +<TabItem value="js"> |
| 40 | + |
| 41 | +| Previous | Latest | Description | |
| 42 | +| -------------------- | :------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 43 | +| `@algolia` | `@experimental-api-clients-automation` | **During the beta phase**, the clients are available under the NPM `@experimental-api-clients-automation` namespace, you can find a full list [here](https://www.npmjs.com/org/experimental-api-clients-automation). | |
| 44 | +| `algoliasearch/lite` | `algoliasearch-lite` | The lite version of the client now have [its own package](https://www.npmjs.com/package/@experimental-api-clients-automation/algoliasearch-lite). | |
| 45 | +| `search` | `searchClient` | Exported clients are suffixed by `Client`. | |
| 46 | + |
| 47 | +</TabItem> |
| 48 | +</Tabs> |
| 49 | + |
| 50 | +### Installation |
| 51 | + |
| 52 | +<Tabs |
| 53 | + groupId="language" |
| 54 | + defaultValue="js" |
| 55 | + values={[ |
| 56 | + { label: 'JavaScript', value: 'js', } |
| 57 | + ] |
| 58 | +}> |
| 59 | +<TabItem value="js"> |
| 60 | + |
| 61 | +To get started, first install the `algoliasearch` client. |
| 62 | + |
| 63 | +```bash |
| 64 | +yarn add @experimental-api-clients-automation/algoliasearch |
| 65 | +# or |
| 66 | +npm install @experimental-api-clients-automation/algoliasearch |
| 67 | +``` |
| 68 | + |
| 69 | +You can now uninstall the previously added client. |
| 70 | + |
| 71 | +> Make sure to update all your imports. |
| 72 | +
|
| 73 | +```bash |
| 74 | +yarn remove algoliasearch |
| 75 | +# or |
| 76 | +npm uninstall algoliasearch |
| 77 | +``` |
| 78 | + |
| 79 | +You can continue this guide on [our installation page](/docs/api-clients/installation). |
| 80 | + |
| 81 | +</TabItem> |
| 82 | +</Tabs> |
| 83 | + |
| 84 | +### Importing algoliasearch using ES Modules |
| 85 | + |
| 86 | +<Tabs |
| 87 | + groupId="language" |
| 88 | + defaultValue="js" |
| 89 | + values={[ |
| 90 | + { label: 'JavaScript', value: 'js', } |
| 91 | + ] |
| 92 | +}> |
| 93 | +<TabItem value="js"> |
| 94 | + |
| 95 | +```diff |
| 96 | +- import algoliasearch from 'algoliasearch/lite'; |
| 97 | ++ import { algoliasearchLiteClient } from '@experimental-api-clients-automation/algoliasearch-lite'; |
| 98 | + |
| 99 | +- import algoliasearch from 'algoliasearch'; |
| 100 | ++ import { algoliasearch } from '@experimental-api-clients-automation/algoliasearch'; |
| 101 | +``` |
| 102 | + |
| 103 | +</TabItem> |
| 104 | +</Tabs> |
| 105 | + |
| 106 | +### Methods targetting an `indexName` |
| 107 | + |
| 108 | +<Tabs |
| 109 | + groupId="language" |
| 110 | + defaultValue="js" |
| 111 | + values={[ |
| 112 | + { label: 'JavaScript', value: 'js', } |
| 113 | + ] |
| 114 | +}> |
| 115 | +<TabItem value="js"> |
| 116 | + |
| 117 | +Prior to the `initIndex` removal stated in the [Common breaking changes](#common-breaking-changes), all methods previously available at the `initIndex` level requires the `indexName` to be sent with the query. |
| 118 | + |
| 119 | +```js |
| 120 | +import { algoliasearch } from '@experimental-api-clients-automation/algoliasearch'; |
| 121 | + |
| 122 | +const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>'); |
| 123 | + |
| 124 | +// only query string |
| 125 | +const searchResults = await client.search({ |
| 126 | + indexName: '<YOUR_INDEX_NAME>', |
| 127 | + searchParams: { query: 'myQuery' }, |
| 128 | +}); |
| 129 | + |
| 130 | +// with params |
| 131 | +const searchResults2 = await client.search({ |
| 132 | + indexName: '<YOUR_INDEX_NAME>', |
| 133 | + searchParams: { |
| 134 | + query: 'myQuery', |
| 135 | + attributesToRetrieve: ['firstname', 'lastname'], |
| 136 | + hitsPerPage: 50, |
| 137 | + }, |
| 138 | +}); |
| 139 | +``` |
| 140 | + |
| 141 | +</TabItem> |
| 142 | +</Tabs> |
0 commit comments