Handle bulk errors in examples

This commit is contained in:
delvedor
2019-04-01 09:08:32 +02:00
parent 52cd07eca3
commit aea1ecfe15
7 changed files with 42 additions and 7 deletions

View File

@ -11,7 +11,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' }) const client = new Client({ node: 'http://localhost:9200' })
async function run () { async function run () {
await client.bulk({ const { body: bulkResponse } = await client.bulk({
refresh: true, refresh: true,
body: [ body: [
// operation to perform // operation to perform
@ -36,6 +36,11 @@ async function run () {
] ]
}) })
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
// Let's search! // Let's search!
const { body } = await client.search({ const { body } = await client.search({
index: 'game-of-thrones', index: 'game-of-thrones',

View File

@ -12,7 +12,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' }) const client = new Client({ node: 'http://localhost:9200' })
async function run () { async function run () {
await client.bulk({ const { body: bulkResponse } = await client.bulk({
// here we are forcing an index refresh, // here we are forcing an index refresh,
// otherwise we will not get any result // otherwise we will not get any result
// in the consequent search // in the consequent search
@ -40,6 +40,11 @@ async function run () {
] ]
}) })
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
// Let's search! // Let's search!
const { body } = await client.search({ const { body } = await client.search({
index: 'game-of-thrones', index: 'game-of-thrones',

View File

@ -10,7 +10,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' }) const client = new Client({ node: 'http://localhost:9200' })
async function run () { async function run () {
await client.bulk({ const { body: bulkResponse } = await client.bulk({
refresh: true, refresh: true,
body: [ body: [
// operation to perform // operation to perform
@ -35,6 +35,11 @@ async function run () {
] ]
}) })
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
// Let's search! // Let's search!
const { body } = await client.search({ const { body } = await client.search({
index: 'game-of-thrones', index: 'game-of-thrones',

View File

@ -11,7 +11,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' }) const client = new Client({ node: 'http://localhost:9200' })
async function run () { async function run () {
await client.bulk({ const { body: bulkResponse } = await client.bulk({
refresh: true, refresh: true,
body: [ body: [
{ index: { _index: 'game-of-thrones' } }, { index: { _index: 'game-of-thrones' } },
@ -34,6 +34,11 @@ async function run () {
] ]
}) })
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
const { body } = await client.msearch({ const { body } = await client.msearch({
body: [ body: [
{ index: 'game-of-thrones' }, { index: 'game-of-thrones' },

View File

@ -21,7 +21,7 @@ async function run () {
const responseQueue = [] const responseQueue = []
// Let's index some data! // Let's index some data!
await client.bulk({ const { body: bulkResponse } = await client.bulk({
// here we are forcing an index refresh, // here we are forcing an index refresh,
// otherwise we will not get any result // otherwise we will not get any result
// in the consequent search // in the consequent search
@ -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 // start things off by searching, setting a scroll timeout, and pushing
// our first response into the queue to be processed // our first response into the queue to be processed
const response = await client.search({ const response = await client.search({

View File

@ -14,7 +14,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' }) const client = new Client({ node: 'http://localhost:9200' })
async function run () { async function run () {
await client.bulk({ const { body: bulkResponse } = await client.bulk({
refresh: true, refresh: true,
body: [ body: [
{ index: { _index: 'game-of-thrones' } }, { index: { _index: 'game-of-thrones' } },
@ -37,6 +37,11 @@ async function run () {
] ]
}) })
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
const { body } = await client.search({ const { body } = await client.search({
index: 'game-of-thrones', index: 'game-of-thrones',
body: { body: {

View File

@ -16,7 +16,7 @@ const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' }) const client = new Client({ node: 'http://localhost:9200' })
async function run () { async function run () {
await client.bulk({ const { body: bulkResponse } = await client.bulk({
refresh: true, refresh: true,
body: [ body: [
{ index: { _index: 'game-of-thrones' } }, { index: { _index: 'game-of-thrones' } },
@ -39,6 +39,11 @@ async function run () {
] ]
}) })
if (bulkResponse.errors) {
console.log(bulkResponse)
process.exit(1)
}
const { body } = await client.transport.request({ const { body } = await client.transport.request({
method: 'POST', method: 'POST',
path: '/game-of-thrones/_search', path: '/game-of-thrones/_search',