From 0a6e9b3988260c3a679b4eb26cd5cb222156ad74 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Fri, 26 Aug 2022 16:32:04 -0700 Subject: [PATCH] Adds bulk example to README (#277) * Adds bulk example to README Signed-off-by: Harsha Vamsi Kalluri * Add logging statement Signed-off-by: Harsha Vamsi Kalluri * Fix clientcode example Signed-off-by: Harsha Vamsi Kalluri Signed-off-by: Harsha Vamsi Kalluri --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f90b2cac..5dbbd8ecc 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ var client = new Client({ }); async function search() { + // Create an index with non-default settings. var index_name = 'books'; var settings = { @@ -112,7 +113,49 @@ async function search() { console.log('Adding document:'); console.log(response.body); - // Search for the document. + // Add documents in bulk + var bulk_documents = [ + { + index: { + _index: 'books-king', + _id: '2' + } + }, + { + title: 'IT', + author: 'Stephen Kings', + year: '1986', + }, + { + create: { + _index: 'test', + _id: '3' + } + }, + { + title: 'The Green Mile', + author: 'Stephen Kings', + year: '1996', + }, + { + create: { + _index: 'test', + _id: '4' + } + }, + { + title: 'Carrie', + author: 'Stephen Kings', + year: '1974', + } + ]; + + var response = await client.bulk({ body: bulk_documents }); + + console.log('Adding documents using the bulk API') + console.log(response.body); + + // Search for a document. var query = { query: { match: { @@ -131,7 +174,7 @@ async function search() { console.log('Search results:'); console.log(response.body.hits); - // Delete the document. + // Delete a document. var response = await client.delete({ index: index_name, id: id,