Bulk request broken on 8.2.0, "The bulk request must be terminated by a newline [\\n]" error
See original GitHub issue🐛 Bug Report
When performing a bulk request this is the result.
/app/node_modules/@elastic/transport/lib/Transport.js:476
throw new errors_1.ResponseError(result);
^
ResponseError: illegal_argument_exception: [illegal_argument_exception] Reason: The bulk request must be terminated by a newline [\n]
at SniffingTransport.request (/app/node_modules/@elastic/transport/lib/Transport.js:476:27)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Client.BulkApi [as bulk] (/app/node_modules/@elastic/elasticsearch/lib/api/api/bulk.js:51:12)
at async run (/app/export_import_indexes/test.js:58:24) {
meta: {
body: {
error: {
root_cause: [
{
type: 'illegal_argument_exception',
reason: 'The bulk request must be terminated by a newline [\\n]'
}
],
type: 'illegal_argument_exception',
reason: 'The bulk request must be terminated by a newline [\\n]'
},
status: 400
},
statusCode: 400,
headers: {
'x-elastic-product': 'Elasticsearch',
'content-type': 'application/json;charset=utf-8',
'content-length': '245'
},
meta: {
context: null,
request: {
params: {
method: 'POST',
path: '/_bulk',
body: `[{"index":{"_index":"tweets"}},{"id":1,"text":"If I fall, don't bring me back.","user":"jon","date":"2022-05-03T19:48:42.826Z"},{"index":{"_index":"tweets"}},{"id":2,"text":"Winter is coming","user":"ned","date":"2022-05-03T19:48:42.826Z"},{"index":{"_index":"tweets"}},{"id":3,"text":"A Lannister always pays his debts.","user":"tyrion","date":"2022-05-03T19:48:42.826Z"},{"index":{"_index":"tweets"}},{"id":4,"text":"I am the blood of the dragon.","user":"daenerys","date":"2022-05-03T19:48:42.826Z"},{"index":{"_index":"tweets"}},{"id":5,"text":"A girl is Arya Stark of Winterfell. And I'm going home.","user":"arya","date":"2022-05-03T19:48:42.826Z"}]`,
querystring: 'refresh=true',
headers: {
'user-agent': 'elastic-transport-js/8.2.0 (linux 5.13.0-40-generic-x64; Node.js v16.10.0)',
'x-elastic-client-meta': 'es=8.2.0,js=16.10.0,t=8.2.0,hc=16.10.0',
'content-type': 'application/vnd.elasticsearch+json; compatible-with=8',
accept: 'application/vnd.elasticsearch+json; compatible-with=8',
'content-length': '655'
}
},
options: {},
id: 2
},
name: 'elasticsearch-js',
connection: Connection {
url: <ref *1> URL {
[Symbol(context)]: URLContext {
flags: 400,
scheme: 'http:',
username: '',
password: '',
host: 'localhost',
port: 9200,
path: [Array],
query: null,
fragment: null
},
[Symbol(query)]: URLSearchParams {
[Symbol(query)]: [],
[Symbol(context)]: [Circular *1]
}
},
tls: null,
id: 'http://localhost:9200/',
timeout: 30000,
headers: {
authorization: 'Basic ZWxhc3RpYzpIR01kdUI5UkN1NE9nQUdDWHMyRA=='
},
deadCount: 0,
resurrectTimeout: 0,
_openRequests: 0,
weight: 1000,
pool: <ref *2> Pool {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
[Symbol(kCapture)]: false,
[Symbol(destroyed)]: false,
[Symbol(onDestroyed)]: [],
[Symbol(closed)]: false,
[Symbol(onClosed)]: [],
[Symbol(queue)]: FixedQueue {
tail: [FixedCircularBuffer],
head: [FixedCircularBuffer]
},
[Symbol(clients)]: [ [Client], [Client] ],
[Symbol(queued)]: 0,
[Symbol(onDrain)]: [Function: onDrain],
[Symbol(onConnect)]: [Function (anonymous)],
[Symbol(onDisconnect)]: [Function (anonymous)],
[Symbol(onConnectionError)]: [Function (anonymous)],
[Symbol(stats)]: PoolStats { [Symbol(pool)]: [Circular *2] },
[Symbol(connections)]: 256,
[Symbol(url)]: URL {
[Symbol(context)]: [URLContext],
[Symbol(query)]: [URLSearchParams]
},
[Symbol(options)]: {
keepAliveTimeout: 600000,
keepAliveMaxTimeout: 600000,
keepAliveTimeoutThreshold: 1000,
pipelining: 1,
maxHeaderSize: 16384,
headersTimeout: 30000,
bodyTimeout: 30000,
connect: [Function: connect]
},
[Symbol(factory)]: [Function: defaultFactory],
[Symbol(needDrain)]: false
},
[Symbol(status)]: 'alive',
[Symbol(ca fingerprint)]: null,
[Symbol(diagnostics)]: Diagnostic {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
[Symbol(kCapture)]: false
},
[Symbol(event emitter)]: EventEmitter {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
[Symbol(kCapture)]: false
}
},
attempts: 0,
aborted: false
},
warnings: [Getter]
}
}
To Reproduce
Steps to reproduce the behavior:
- Just perform any bulk request.
Paste your code here:
const { Client } = require('@elastic/elasticsearch')
const client = new Client({
node: 'http://localhost:9200',
});
async function run () {
await client.indices.create({
index: 'tweets',
operations: {
mappings: {
properties: {
id: { type: 'integer' },
text: { type: 'text' },
user: { type: 'keyword' },
time: { type: 'date' }
}
}
}
}, { ignore: [400] })
const dataset = [{
id: 1,
text: 'If I fall, don\'t bring me back.',
user: 'jon',
date: new Date()
}, {
id: 2,
text: 'Winter 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 operations = dataset.flatMap(doc => [{ index: { _index: 'tweets' } }, doc])
const bulkResponse = await client.bulk({ refresh: true, operations })
console.log(bulkResponse)
}
run()
Expected behavior
Performs the request and returns ok, just like in the 8.1.0 version:
Paste the results here:
{
took: 438,
errors: false,
items: [
{ index: [Object] },
{ index: [Object] },
{ index: [Object] },
{ index: [Object] },
{ index: [Object] }
]
}
Your Environment
- node version: 16.10.0
@elastic/elasticsearch
version: =8.2.0- os: Linux
- on 8.1.0 works just fine
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Bulk request throws error in Elasticsearch 6.1.1 - Stack Overflow
The error is pretty clear: The bulk request must be terminated by a newline [\n]. So you simply need to add a newline...
Read more >Issue with JSON bulk insert "The bulk request must be ...
I'm trying to bulk upload json to elasticsearch with the below data. I searched in the forums and found that last line should...
Read more >The bulk request must be terminated by a newline [\\n]
Hi, I am trying to BULK POST to elasticsearch in K6 but I am getting an error that : “The bulk request must...
Read more >The bulk request must be terminated by a newline
This tutorial will help you to troubleshoot the ElasticSearch Error – bulk request issues. This guide is written by well known ElasticSearch ...
Read more >The bulk request must be terminated by a newline · Issue ...
Hi, I'm importing 500 records in rails using the bulk method, ... Sporadic error: The bulk request must be terminated by a newline...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello! We can’t release an “official” patch release yet, as the client must follow the Stack release versioning. However, we have released a custom patch version just for
v8.2.0
to unblock you as quickly as possible. You should expect to see a definitivev8.2.1
in a few days. https://www.npmjs.com/package/@elastic/elasticsearch/v/8.2.0-patch.1You can install it by running
npm i @elastic/elasticsearch
, make sure that the version installed is8.2.0-patch.1
.Hi @delvedor
Can’t you release sooner? Until then you’re letting a broken version in the wild, it’s probably not something you want for users… At least you should remove version 8.2.0 from the npm registry, or mark it as deprecated, or whatever prevents users from installing it 😅
Cheers, David