Skip to content

Commit

Permalink
Adds bulk example to README (#277)
Browse files Browse the repository at this point in the history
* Adds bulk example to README

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>

* Add logging statement

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>

* Fix clientcode example

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
  • Loading branch information
harshavamsi committed Aug 26, 2022
1 parent e1fce54 commit 0a6e9b3
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var client = new Client({
});

async function search() {

// Create an index with non-default settings.
var index_name = 'books';
var settings = {
Expand Down Expand Up @@ -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: {
Expand All @@ -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,
Expand Down

0 comments on commit 0a6e9b3

Please sign in to comment.