Wednesday, March 4, 2020

How to fix "The bulk request must be terminated by a newline [\\n]" issue on ElasticSearch Bulk Insert in Node.js develoopment?

i am doing a bulk insert action against the ElasticSearch with Node.js

i try to perform a bulk insert the data into index from a file.

here is the error from the action.

{
    "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
}

the root cause of this issue is newline character is different from unix and windows

for this sample data

{"index":{"_id":"pg1"}}
{"id":1,"title":"The Declaration of Independence of the United States of America","authors":["Jefferson, Thomas"],"subjects":["United States. Declaration of Independence","United States -- History -- Revolution, 1775-1783 -- Sources"]}

in windows show as







in unix display like this




from notepad++ editor, we can easily convert it to unix format.

from edit menu, click on the EOL conversion, then select Unix(LF)











Finally we need to ensure that the data encoding is "UTF-8"




No comments:

Post a Comment