Skip to content

Commit

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

Signed-off-by: Harsha Vamsi Kalluri <[email protected]>

* Add logging statement

Signed-off-by: Harsha Vamsi Kalluri <[email protected]>

* Fix clientcode example

Signed-off-by: Harsha Vamsi Kalluri <[email protected]>

Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi authored and AMoo-Miki committed Jul 12, 2023
1 parent 717b9a9 commit 49cac0f
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 49cac0f

Please sign in to comment.