Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds bulk example to README #277

Merged
merged 3 commits into from
Aug 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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