"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 be terminated by a newline [\n]”.

Any tips on how I can fix this?

Here is:

const params = {
        headers: {
          'Content-Type': 'application/x-ndjson',
          Authorization : `Basic ${encodedCredentials}`
        },
      };

      const data1 = {
        "amount" : "100",
        "@timestamp" : `${UTC_timestamp}`,
        "transaction_attributes" : {
        "channel" : "channel-foobarbaz",
        "session_id" : "session-1234",
        "information" : "iinformation-foobarbaznformation-foobarbaz"
        },
        "currency" : {
        "currency_description" : "my currency description",
        },
        "external_timestamp" : "2021-12-03T11:22:55.206229500Z"
};

      

    // execute a post
    let res = http.post(url,JSON.stringify(data1),params);

    check(res, { 
          "Create user response status code is 201": (r) => r.status == 201, 
      }
    );

Hi,

It seems like you need to add a new line at the end of your JSON.

Does the explanation at this link help?

Maybe something like:

let res = http.post(url,JSON.stringify(data1)+"\n",params);

Thanks man.
I had tried that before and it did not work.
I needed to re-write my datafile in a format that was accepted by elastic bulk.