From a4bff1c2f0a870781ff9171e351530f98621142e Mon Sep 17 00:00:00 2001 From: delvedor Date: Thu, 1 Aug 2019 11:39:02 +0200 Subject: [PATCH 1/3] Bumped v6.8.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fad160542..7f46f6d71 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "main": "index.js", "types": "index.d.ts", "homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html", - "version": "6.8.1", + "version": "6.8.2", "keywords": [ "elasticsearch", "elastic", From 6194119e6203b0c7617c5d308b6384054491d7e9 Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Thu, 1 Aug 2019 12:20:29 +0200 Subject: [PATCH 2/3] Updated error handling in bulk example (#927) --- docs/examples/bulk.asciidoc | 112 ++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 43 deletions(-) diff --git a/docs/examples/bulk.asciidoc b/docs/examples/bulk.asciidoc index 7d87b7af1..e2104e4d1 100644 --- a/docs/examples/bulk.asciidoc +++ b/docs/examples/bulk.asciidoc @@ -8,57 +8,83 @@ This can greatly increase the indexing speed. ---- 'use strict' +require('array.prototype.flatmap').shim() const { Client } = require('@elastic/elasticsearch') -const client = new Client({ node: 'http://localhost:9200' }) +const client = new Client({ + node: 'http://localhost:9200' +}) async function run () { - const { body: bulkResponse } = await client.bulk({ - // here we are forcing an index refresh, - // otherwise we will not get any result - // in the consequent search - refresh: true, - body: [ - // operation to perform - { index: { _index: 'game-of-thrones' } }, - // the document to index - { - character: 'Ned Stark', - quote: 'Winter is coming.' - }, - - { index: { _index: 'game-of-thrones' } }, - { - character: 'Daenerys Targaryen', - quote: 'I am the blood of the dragon.' - }, - - { index: { _index: 'game-of-thrones' } }, - { - character: 'Tyrion Lannister', - quote: 'A mind needs books like a sword needs a whetstone.' - } - ] - }) - - if (bulkResponse.errors) { - console.log(bulkResponse) - process.exit(1) - } - - // Let's search! - const { body } = await client.search({ - index: 'game-of-thrones', + await client.indices.create({ + index: 'tweets', body: { - query: { - match: { - quote: 'winter' + mappings: { + properties: { + id: { type: 'integer' }, + text: { type: 'text' }, + user: { type: 'keyword' }, + time: { type: 'date' } } } } - }) + }, { ignore: [400] }) - console.log(body.hits.hits) + const dataset = [{ + id: 1, + text: 'If I fall, don\'t bring me back.', + user: 'jon', + date: new Date() + }, { + id: 2, + text: 'Witer is coming', + user: 'ned', + date: new Date() + }, { + id: 3, + text: 'A Lannister always pays his debts.', + user: 'tyrion', + date: new Date() + }, { + id: 4, + text: 'I am the blood of the dragon.', + user: 'daenerys', + date: new Date() + }, { + id: 5, // change this value to a string to see the bulk response with errors + text: 'A girl is Arya Stark of Winterfell. And I\'m going home.', + user: 'arya', + date: new Date() + }] + + const body = dataset.flatMap(doc => [{ index: { _index: 'tweets' } }, doc]) + + const { body: bulkResponse } = await client.bulk({ refresh: true, body }) + + if (bulkResponse.errors) { + const erroredDocuments = [] + // The items array has the same order of the dataset we just indexed. + // The presence of the `error` key indicates that the operation + // that we did for the document has failed. + bulkResponse.items.forEach((action, i) => { + const operation = Object.keys(action)[0] + if (action[operation].error) { + erroredDocuments.push({ + // If the status is 429 it means that you can retry the document, + // otherwise it's very likely a mapping error, and you should + // fix the document before to try it again. + status: action[operation].status, + error: action[operation].error, + operation: body[i * 2], + document: body[i * 2 + 1] + }) + } + }) + console.log(erroredDocuments) + } + + const { body: count } = await client.count({ index: 'tweets' }) + console.log(count) } run().catch(console.log) ----- \ No newline at end of file +---- From ef69bbd216dde0f19242e41c8a92035bfa6f1d22 Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Fri, 2 Aug 2019 11:49:21 +0200 Subject: [PATCH 3/3] Disable travis cache (#929) --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index ecbed2c22..662d05671 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,9 @@ node_js: - "10" - "8" +cache: + npm: false + os: - windows - linux