mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[API] Use JSONStream instead of manually stringifying
This commit is contained in:
parent
6ceca8b1ba
commit
19be188367
2 changed files with 6 additions and 6 deletions
|
@ -76,6 +76,7 @@
|
|||
"@spalger/numeral": "^2.0.0",
|
||||
"@spalger/test-subj-selector": "0.2.1",
|
||||
"@spalger/ui-ace": "0.2.3",
|
||||
"JSONStream": "1.1.1",
|
||||
"angular": "1.4.7",
|
||||
"angular-bootstrap-colorpicker": "3.0.19",
|
||||
"angular-elastic": "2.5.0",
|
||||
|
|
|
@ -5,6 +5,7 @@ import hi from 'highland';
|
|||
import { patternToIngest } from '../../../../common/lib/convert_pattern_and_ingest_name';
|
||||
import { PassThrough } from 'stream';
|
||||
import bulkRequestSchema from '../../../lib/schemas/bulk_request_schema';
|
||||
import JSONStream from 'JSONStream';
|
||||
|
||||
export function registerBulk(server) {
|
||||
server.route({
|
||||
|
@ -34,7 +35,6 @@ export function registerBulk(server) {
|
|||
|
||||
let currentLine = 2; // Starts at 2 since we parse the header separately
|
||||
|
||||
responseStream.write('[');
|
||||
csv.pipe(parser);
|
||||
|
||||
hi(parser)
|
||||
|
@ -70,7 +70,7 @@ export function registerBulk(server) {
|
|||
})
|
||||
.parallel(2)
|
||||
.map((response) => {
|
||||
return JSON.stringify(_.reduce(response.items, (memo, docResponse) => {
|
||||
return _.reduce(response.items, (memo, docResponse) => {
|
||||
const indexResult = docResponse.index;
|
||||
if (indexResult.error) {
|
||||
if (_.isUndefined(_.get(memo, 'errors.index'))) {
|
||||
|
@ -83,13 +83,12 @@ export function registerBulk(server) {
|
|||
}
|
||||
|
||||
return memo;
|
||||
}, {created: 0}));
|
||||
}, {created: 0});
|
||||
})
|
||||
.stopOnError((err, push) => {
|
||||
push(null, JSON.stringify({created: 0, errors: {other: [err.message]}}));
|
||||
push(null, {created: 0, errors: {other: [err.message]}});
|
||||
})
|
||||
.intersperse(',')
|
||||
.append(']')
|
||||
.pipe(JSONStream.stringify())
|
||||
.pipe(responseStream);
|
||||
|
||||
reply(responseStream).type('application/json');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue