Skip to content

Commit

Permalink
Handle bulk errors in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor committed Apr 1, 2019
1 parent 74c37e5 commit ca0b33a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
7 changes: 6 additions & 1 deletion docs/examples/asStream.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })
async function run () {
await client.bulk({
const { body: bulkResponse } = await client.bulk({
refresh: true,
body: [
// operation to perform
Expand All @@ -36,6 +36,11 @@ async function run () {
]
})
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
// Let's search!
const { body } = await client.search({
index: 'game-of-thrones',
Expand Down
7 changes: 6 additions & 1 deletion docs/examples/bulk.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })
async function run () {
await client.bulk({
const { body: bulkResponse } = await client.bulk({
// here we are forcing an index refresh,
// otherwise we will not get any result
// in the consequent search
Expand Down Expand Up @@ -40,6 +40,11 @@ async function run () {
]
})
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
// Let's search!
const { body } = await client.search({
index: 'game-of-thrones',
Expand Down
7 changes: 6 additions & 1 deletion docs/examples/ignore.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })
async function run () {
await client.bulk({
const { body: bulkResponse } = await client.bulk({
refresh: true,
body: [
// operation to perform
Expand All @@ -35,6 +35,11 @@ async function run () {
]
})
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
// Let's search!
const { body } = await client.search({
index: 'game-of-thrones',
Expand Down
7 changes: 6 additions & 1 deletion docs/examples/msearch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })
async function run () {
await client.bulk({
const { body: bulkResponse } = await client.bulk({
refresh: true,
body: [
{ index: { _index: 'game-of-thrones' } },
Expand All @@ -34,6 +34,11 @@ async function run () {
]
})
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
const { body } = await client.msearch({
body: [
{ index: 'game-of-thrones' },
Expand Down
7 changes: 6 additions & 1 deletion docs/examples/scroll.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function run () {
const responseQueue = []
// Let's index some data!
await client.bulk({
const { body: bulkResponse } = await client.bulk({
// here we are forcing an index refresh,
// otherwise we will not get any result
// in the consequent search
Expand Down Expand Up @@ -49,6 +49,11 @@ async function run () {
]
})
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
// start things off by searching, setting a scroll timeout, and pushing
// our first response into the queue to be processed
const response = await client.search({
Expand Down
7 changes: 6 additions & 1 deletion docs/examples/suggest.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })
async function run () {
await client.bulk({
const { body: bulkResponse } = await client.bulk({
refresh: true,
body: [
{ index: { _index: 'game-of-thrones' } },
Expand All @@ -37,6 +37,11 @@ async function run () {
]
})
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
const { body } = await client.search({
index: 'game-of-thrones',
body: {
Expand Down
7 changes: 6 additions & 1 deletion docs/examples/transport.request.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })
async function run () {
await client.bulk({
const { body: bulkResponse } = await client.bulk({
refresh: true,
body: [
{ index: { _index: 'game-of-thrones' } },
Expand All @@ -39,6 +39,11 @@ async function run () {
]
})
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
const { body } = await client.transport.request({
method: 'POST',
path: '/game-of-thrones/_search',
Expand Down

0 comments on commit ca0b33a

Please sign in to comment.