Skip to content

Commit 65eed17

Browse files
author
charlotte
committed
add updateDocuments to the function list
1 parent 9db4422 commit 65eed17

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ let documents = [
7070
{ book_id: 42, title: "The Hitchhiker's Guide to the Galaxy" },
7171
]
7272

73-
await meili.Index('books').addDocuments(documents) // { "updateId": 0 }
73+
await meili.Index('books').addOrReplaceDocuments(documents) // { "updateId": 0 }
7474
```
7575

7676
With the `updateId`, you can check the status (`processed` of `failed`) of your documents addition thanks to this [method](#update-status).
@@ -146,7 +146,7 @@ let myDocuments = await meili
146146
#### Add documents <!-- omit in toc -->
147147

148148
```javascript
149-
meili.Index('books').addDocuments([{ book_id: 2, title: 'Madame Bovary' }])
149+
meili.Index('books').addOrReplaceDocuments([{ book_id: 2, title: 'Madame Bovary' }])
150150
```
151151

152152
Response:
@@ -333,10 +333,14 @@ This package works for MeiliSearch `v0.9.x`.
333333

334334
### Documents
335335

336-
- Add or update multiples documents:
336+
- Add or replace multiple documents:
337337

338338
`meili.Index('xxx').addDocuments(documents: object[]): Promise<Types.AsyncUpdateId>`
339339

340+
- Add or update multiple documents:
341+
342+
`meili.Index('xxx').updateDocuments(documents: object[]): Promise<Types.AsyncUpdateId>`
343+
340344
- Get Documents:
341345

342346
`meili.Index('xxx').getDocuments(params: Types.getDocumentsParams): Promise<object[]>`
@@ -349,7 +353,7 @@ This package works for MeiliSearch `v0.9.x`.
349353

350354
`meili.Index('xxx').deleteDocument(documentId: string): Promise<Types.AsyncUpdateId>`
351355

352-
- Delete multiples documents:
356+
- Delete multiple documents:
353357

354358
`meili.Index('xxx').deleteDocuments(documentsIds: string[]): Promise<Types.AsyncUpdateId>`
355359

src/__tests__/indexes.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ test('add-documents', async () => {
133133
meili.Index(indexAndIndentifier.uid).addDocuments(dataset)
134134
).resolves.toHaveProperty('updateId')
135135
})
136+
test('update-documents', async () => {
137+
await expect(
138+
meili.Index(index.uid).updateDocuments(dataset, {
139+
primaryKey: 'id',
140+
})
141+
).resolves.toHaveProperty('updateId')
142+
await expect(
143+
meili.Index(indexAndIndentifier.uid).addDocuments(dataset)
144+
).resolves.toHaveProperty('updateId')
145+
})
136146

137147
test('get-index-primary-key', async () => {
138148
await sleep(3 * 1000)
@@ -153,7 +163,7 @@ test('updates', async () => {
153163
await expect(meili.Index(index.uid).getUpdateStatus(0)).resolves.toHaveProperty(
154164
'status'
155165
)
156-
await expect(meili.Index(index.uid).getAllUpdateStatus()).resolves.toHaveLength(1)
166+
await expect(meili.Index(index.uid).getAllUpdateStatus()).resolves.toHaveLength(2)
157167
})
158168

159169
test('get-document', async () => {
@@ -508,7 +518,7 @@ test('delete-documents', async () => {
508518
await expect(
509519
meili.Index(index.uid).deleteDocuments([firstDocumentId, offsetDocumentId])
510520
).resolves.toHaveProperty('updateId')
511-
await sleep(1000)
521+
await sleep(2000)
512522
await expect(
513523
meili.Index(index.uid).getDocument(firstDocumentId)
514524
).rejects.toThrow()

src/indexes.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class Indexes {
198198
}
199199

200200
/**
201-
* Add or update multiples documents to an index
201+
* Add or replace multiples documents to an index
202202
* @memberof Documents
203203
* @method addDocuments
204204
*/
@@ -213,6 +213,22 @@ class Indexes {
213213
})
214214
}
215215

216+
/**
217+
* Add or update multiples documents to an index
218+
* @memberof Documents
219+
* @method updateDocuments
220+
*/
221+
updateDocuments(
222+
documents: object[],
223+
options?: Types.AddDocumentParams
224+
): Promise<Types.AsyncUpdateId> {
225+
const url = `/indexes/${this.indexUid}/documents`
226+
227+
return this.instance.put(url, documents, {
228+
params: options,
229+
})
230+
}
231+
216232
/**
217233
* Delete one document
218234
* @memberof Documents

0 commit comments

Comments
 (0)