Bulk request throws error in elasticsearch 6.1.1











up vote
7
down vote

favorite
1












I recently upgraded to elasticsearch version 6.1.1 and now I can't bulk index documents from a json file. Wehn I do it inline, it works fine. Here are the contents of the document:



{"index" : {}}
{"name": "Carlson Barnes", "age": 34}
{"index":{}}
{"name": "Sheppard Stein","age": 39}
{"index":{}}
{"name": "Nixon Singleton","age": 36}
{"index":{}}
{"name": "Sharron Sosa","age": 33}
{"index":{}}
{"name": "Kendra Cabrera","age": 24}
{"index":{}}
{"name": "Young Robinson","age": 20}


When I run this command,



curl -XPUT 'localhost:9200/subscribers/ppl/_bulk?pretty' -H 'Content-Type: application/json' -d @customers_full.json


I get this error:



"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


It works fine if I send the data inline and in elasticsearch 5.x. I tried adding newlines as well as the newline character to the end of the file. Doesn't seem to work.










share|improve this question
























  • Issue resolved?
    – Sathishkumar Rakkiasamy
    Mar 17 at 19:16















up vote
7
down vote

favorite
1












I recently upgraded to elasticsearch version 6.1.1 and now I can't bulk index documents from a json file. Wehn I do it inline, it works fine. Here are the contents of the document:



{"index" : {}}
{"name": "Carlson Barnes", "age": 34}
{"index":{}}
{"name": "Sheppard Stein","age": 39}
{"index":{}}
{"name": "Nixon Singleton","age": 36}
{"index":{}}
{"name": "Sharron Sosa","age": 33}
{"index":{}}
{"name": "Kendra Cabrera","age": 24}
{"index":{}}
{"name": "Young Robinson","age": 20}


When I run this command,



curl -XPUT 'localhost:9200/subscribers/ppl/_bulk?pretty' -H 'Content-Type: application/json' -d @customers_full.json


I get this error:



"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


It works fine if I send the data inline and in elasticsearch 5.x. I tried adding newlines as well as the newline character to the end of the file. Doesn't seem to work.










share|improve this question
























  • Issue resolved?
    – Sathishkumar Rakkiasamy
    Mar 17 at 19:16













up vote
7
down vote

favorite
1









up vote
7
down vote

favorite
1






1





I recently upgraded to elasticsearch version 6.1.1 and now I can't bulk index documents from a json file. Wehn I do it inline, it works fine. Here are the contents of the document:



{"index" : {}}
{"name": "Carlson Barnes", "age": 34}
{"index":{}}
{"name": "Sheppard Stein","age": 39}
{"index":{}}
{"name": "Nixon Singleton","age": 36}
{"index":{}}
{"name": "Sharron Sosa","age": 33}
{"index":{}}
{"name": "Kendra Cabrera","age": 24}
{"index":{}}
{"name": "Young Robinson","age": 20}


When I run this command,



curl -XPUT 'localhost:9200/subscribers/ppl/_bulk?pretty' -H 'Content-Type: application/json' -d @customers_full.json


I get this error:



"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


It works fine if I send the data inline and in elasticsearch 5.x. I tried adding newlines as well as the newline character to the end of the file. Doesn't seem to work.










share|improve this question















I recently upgraded to elasticsearch version 6.1.1 and now I can't bulk index documents from a json file. Wehn I do it inline, it works fine. Here are the contents of the document:



{"index" : {}}
{"name": "Carlson Barnes", "age": 34}
{"index":{}}
{"name": "Sheppard Stein","age": 39}
{"index":{}}
{"name": "Nixon Singleton","age": 36}
{"index":{}}
{"name": "Sharron Sosa","age": 33}
{"index":{}}
{"name": "Kendra Cabrera","age": 24}
{"index":{}}
{"name": "Young Robinson","age": 20}


When I run this command,



curl -XPUT 'localhost:9200/subscribers/ppl/_bulk?pretty' -H 'Content-Type: application/json' -d @customers_full.json


I get this error:



"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


It works fine if I send the data inline and in elasticsearch 5.x. I tried adding newlines as well as the newline character to the end of the file. Doesn't seem to work.







json elasticsearch elasticsearch-5 bulk-load






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 7 at 21:58









Mehdi LAMRANI

6,252115999




6,252115999










asked Feb 2 at 9:52









Judy T Raj

235218




235218












  • Issue resolved?
    – Sathishkumar Rakkiasamy
    Mar 17 at 19:16


















  • Issue resolved?
    – Sathishkumar Rakkiasamy
    Mar 17 at 19:16
















Issue resolved?
– Sathishkumar Rakkiasamy
Mar 17 at 19:16




Issue resolved?
– Sathishkumar Rakkiasamy
Mar 17 at 19:16












7 Answers
7






active

oldest

votes

















up vote
13
down vote



accepted










Add empty line at the end of the JSON file and save the file and then try to run the below command



curl -XPOST localhost:9200/subscribers/ppl/_bulk?pretty --data-binary @customers_full.json -H 'Content-Type: application/json'


I hope it works fine for you.






share|improve this answer




























    up vote
    5
    down vote













    The error is pretty clear:



    The bulk request must be terminated by a newline [n]


    So you simply need to add a newline at the end of your customers_full.json file and you'll be ok.






    share|improve this answer





















    • I did that. I added a newline. I tried adding the newline character, still doesn't work.
      – Judy T Raj
      Feb 2 at 9:54










    • I tried the same thing against ES 6.1.3 and it worked perfectly
      – Val
      Feb 2 at 10:04






    • 1




      Instead of -d you should try to use --data-binary
      – Val
      Feb 2 at 10:41










    • That didn't work either.
      – Judy T Raj
      Feb 2 at 12:30










    • Can you gist your JSON file?
      – Val
      Feb 2 at 12:39




















    up vote
    3
    down vote













    As the document says: use the --data-binary flag instead of plain -d. The latter doesn’t preserve newlines and do not format the json.
    I faced this problem because of JSON formatting.






    share|improve this answer




























      up vote
      2
      down vote













      I ran into the same issue and spent hours adding and removing newlines before somebody pointed out I mis-typed the file name... So note that curl will throw the same error if the file is not actually present, making this super-confusing.






      share|improve this answer




























        up vote
        1
        down vote













        You need to use --data-binary instead of -d in your curl request. Please see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html






        share|improve this answer




























          up vote
          0
          down vote













          you just need to open json file and then go to the end of the file ( Ctrl+end) and then please Enter to break a new line.






          share|improve this answer




























            up vote
            0
            down vote













            Press Enter end of the line inside json file and run the command again .



            curl -H "Content-Type: application/x-ndjson" -XPOST 'localhost:9200/customers/personal/_bulk?pretty&refresh' --data-binary @"generated.json"






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48579980%2fbulk-request-throws-error-in-elasticsearch-6-1-1%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              7 Answers
              7






              active

              oldest

              votes








              7 Answers
              7






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              13
              down vote



              accepted










              Add empty line at the end of the JSON file and save the file and then try to run the below command



              curl -XPOST localhost:9200/subscribers/ppl/_bulk?pretty --data-binary @customers_full.json -H 'Content-Type: application/json'


              I hope it works fine for you.






              share|improve this answer

























                up vote
                13
                down vote



                accepted










                Add empty line at the end of the JSON file and save the file and then try to run the below command



                curl -XPOST localhost:9200/subscribers/ppl/_bulk?pretty --data-binary @customers_full.json -H 'Content-Type: application/json'


                I hope it works fine for you.






                share|improve this answer























                  up vote
                  13
                  down vote



                  accepted







                  up vote
                  13
                  down vote



                  accepted






                  Add empty line at the end of the JSON file and save the file and then try to run the below command



                  curl -XPOST localhost:9200/subscribers/ppl/_bulk?pretty --data-binary @customers_full.json -H 'Content-Type: application/json'


                  I hope it works fine for you.






                  share|improve this answer












                  Add empty line at the end of the JSON file and save the file and then try to run the below command



                  curl -XPOST localhost:9200/subscribers/ppl/_bulk?pretty --data-binary @customers_full.json -H 'Content-Type: application/json'


                  I hope it works fine for you.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 16 at 22:12









                  Sathishkumar Rakkiasamy

                  6241818




                  6241818
























                      up vote
                      5
                      down vote













                      The error is pretty clear:



                      The bulk request must be terminated by a newline [n]


                      So you simply need to add a newline at the end of your customers_full.json file and you'll be ok.






                      share|improve this answer





















                      • I did that. I added a newline. I tried adding the newline character, still doesn't work.
                        – Judy T Raj
                        Feb 2 at 9:54










                      • I tried the same thing against ES 6.1.3 and it worked perfectly
                        – Val
                        Feb 2 at 10:04






                      • 1




                        Instead of -d you should try to use --data-binary
                        – Val
                        Feb 2 at 10:41










                      • That didn't work either.
                        – Judy T Raj
                        Feb 2 at 12:30










                      • Can you gist your JSON file?
                        – Val
                        Feb 2 at 12:39

















                      up vote
                      5
                      down vote













                      The error is pretty clear:



                      The bulk request must be terminated by a newline [n]


                      So you simply need to add a newline at the end of your customers_full.json file and you'll be ok.






                      share|improve this answer





















                      • I did that. I added a newline. I tried adding the newline character, still doesn't work.
                        – Judy T Raj
                        Feb 2 at 9:54










                      • I tried the same thing against ES 6.1.3 and it worked perfectly
                        – Val
                        Feb 2 at 10:04






                      • 1




                        Instead of -d you should try to use --data-binary
                        – Val
                        Feb 2 at 10:41










                      • That didn't work either.
                        – Judy T Raj
                        Feb 2 at 12:30










                      • Can you gist your JSON file?
                        – Val
                        Feb 2 at 12:39















                      up vote
                      5
                      down vote










                      up vote
                      5
                      down vote









                      The error is pretty clear:



                      The bulk request must be terminated by a newline [n]


                      So you simply need to add a newline at the end of your customers_full.json file and you'll be ok.






                      share|improve this answer












                      The error is pretty clear:



                      The bulk request must be terminated by a newline [n]


                      So you simply need to add a newline at the end of your customers_full.json file and you'll be ok.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Feb 2 at 9:53









                      Val

                      99.9k6130167




                      99.9k6130167












                      • I did that. I added a newline. I tried adding the newline character, still doesn't work.
                        – Judy T Raj
                        Feb 2 at 9:54










                      • I tried the same thing against ES 6.1.3 and it worked perfectly
                        – Val
                        Feb 2 at 10:04






                      • 1




                        Instead of -d you should try to use --data-binary
                        – Val
                        Feb 2 at 10:41










                      • That didn't work either.
                        – Judy T Raj
                        Feb 2 at 12:30










                      • Can you gist your JSON file?
                        – Val
                        Feb 2 at 12:39




















                      • I did that. I added a newline. I tried adding the newline character, still doesn't work.
                        – Judy T Raj
                        Feb 2 at 9:54










                      • I tried the same thing against ES 6.1.3 and it worked perfectly
                        – Val
                        Feb 2 at 10:04






                      • 1




                        Instead of -d you should try to use --data-binary
                        – Val
                        Feb 2 at 10:41










                      • That didn't work either.
                        – Judy T Raj
                        Feb 2 at 12:30










                      • Can you gist your JSON file?
                        – Val
                        Feb 2 at 12:39


















                      I did that. I added a newline. I tried adding the newline character, still doesn't work.
                      – Judy T Raj
                      Feb 2 at 9:54




                      I did that. I added a newline. I tried adding the newline character, still doesn't work.
                      – Judy T Raj
                      Feb 2 at 9:54












                      I tried the same thing against ES 6.1.3 and it worked perfectly
                      – Val
                      Feb 2 at 10:04




                      I tried the same thing against ES 6.1.3 and it worked perfectly
                      – Val
                      Feb 2 at 10:04




                      1




                      1




                      Instead of -d you should try to use --data-binary
                      – Val
                      Feb 2 at 10:41




                      Instead of -d you should try to use --data-binary
                      – Val
                      Feb 2 at 10:41












                      That didn't work either.
                      – Judy T Raj
                      Feb 2 at 12:30




                      That didn't work either.
                      – Judy T Raj
                      Feb 2 at 12:30












                      Can you gist your JSON file?
                      – Val
                      Feb 2 at 12:39






                      Can you gist your JSON file?
                      – Val
                      Feb 2 at 12:39












                      up vote
                      3
                      down vote













                      As the document says: use the --data-binary flag instead of plain -d. The latter doesn’t preserve newlines and do not format the json.
                      I faced this problem because of JSON formatting.






                      share|improve this answer

























                        up vote
                        3
                        down vote













                        As the document says: use the --data-binary flag instead of plain -d. The latter doesn’t preserve newlines and do not format the json.
                        I faced this problem because of JSON formatting.






                        share|improve this answer























                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          As the document says: use the --data-binary flag instead of plain -d. The latter doesn’t preserve newlines and do not format the json.
                          I faced this problem because of JSON formatting.






                          share|improve this answer












                          As the document says: use the --data-binary flag instead of plain -d. The latter doesn’t preserve newlines and do not format the json.
                          I faced this problem because of JSON formatting.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 1 at 20:28









                          Utsav

                          406




                          406






















                              up vote
                              2
                              down vote













                              I ran into the same issue and spent hours adding and removing newlines before somebody pointed out I mis-typed the file name... So note that curl will throw the same error if the file is not actually present, making this super-confusing.






                              share|improve this answer

























                                up vote
                                2
                                down vote













                                I ran into the same issue and spent hours adding and removing newlines before somebody pointed out I mis-typed the file name... So note that curl will throw the same error if the file is not actually present, making this super-confusing.






                                share|improve this answer























                                  up vote
                                  2
                                  down vote










                                  up vote
                                  2
                                  down vote









                                  I ran into the same issue and spent hours adding and removing newlines before somebody pointed out I mis-typed the file name... So note that curl will throw the same error if the file is not actually present, making this super-confusing.






                                  share|improve this answer












                                  I ran into the same issue and spent hours adding and removing newlines before somebody pointed out I mis-typed the file name... So note that curl will throw the same error if the file is not actually present, making this super-confusing.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered May 30 at 20:45









                                  Raya Fratkina

                                  211




                                  211






















                                      up vote
                                      1
                                      down vote













                                      You need to use --data-binary instead of -d in your curl request. Please see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html






                                      share|improve this answer

























                                        up vote
                                        1
                                        down vote













                                        You need to use --data-binary instead of -d in your curl request. Please see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html






                                        share|improve this answer























                                          up vote
                                          1
                                          down vote










                                          up vote
                                          1
                                          down vote









                                          You need to use --data-binary instead of -d in your curl request. Please see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html






                                          share|improve this answer












                                          You need to use --data-binary instead of -d in your curl request. Please see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Mar 16 at 20:54









                                          Karim

                                          111




                                          111






















                                              up vote
                                              0
                                              down vote













                                              you just need to open json file and then go to the end of the file ( Ctrl+end) and then please Enter to break a new line.






                                              share|improve this answer

























                                                up vote
                                                0
                                                down vote













                                                you just need to open json file and then go to the end of the file ( Ctrl+end) and then please Enter to break a new line.






                                                share|improve this answer























                                                  up vote
                                                  0
                                                  down vote










                                                  up vote
                                                  0
                                                  down vote









                                                  you just need to open json file and then go to the end of the file ( Ctrl+end) and then please Enter to break a new line.






                                                  share|improve this answer












                                                  you just need to open json file and then go to the end of the file ( Ctrl+end) and then please Enter to break a new line.







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Feb 7 at 7:47









                                                  user6589750

                                                  11




                                                  11






















                                                      up vote
                                                      0
                                                      down vote













                                                      Press Enter end of the line inside json file and run the command again .



                                                      curl -H "Content-Type: application/x-ndjson" -XPOST 'localhost:9200/customers/personal/_bulk?pretty&refresh' --data-binary @"generated.json"






                                                      share|improve this answer

























                                                        up vote
                                                        0
                                                        down vote













                                                        Press Enter end of the line inside json file and run the command again .



                                                        curl -H "Content-Type: application/x-ndjson" -XPOST 'localhost:9200/customers/personal/_bulk?pretty&refresh' --data-binary @"generated.json"






                                                        share|improve this answer























                                                          up vote
                                                          0
                                                          down vote










                                                          up vote
                                                          0
                                                          down vote









                                                          Press Enter end of the line inside json file and run the command again .



                                                          curl -H "Content-Type: application/x-ndjson" -XPOST 'localhost:9200/customers/personal/_bulk?pretty&refresh' --data-binary @"generated.json"






                                                          share|improve this answer












                                                          Press Enter end of the line inside json file and run the command again .



                                                          curl -H "Content-Type: application/x-ndjson" -XPOST 'localhost:9200/customers/personal/_bulk?pretty&refresh' --data-binary @"generated.json"







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Oct 9 at 19:22









                                                          sourabh kumar verma

                                                          11




                                                          11






























                                                              draft saved

                                                              draft discarded




















































                                                              Thanks for contributing an answer to Stack Overflow!


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid



                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                              To learn more, see our tips on writing great answers.





                                                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                              Please pay close attention to the following guidance:


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid



                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                              To learn more, see our tips on writing great answers.




                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48579980%2fbulk-request-throws-error-in-elasticsearch-6-1-1%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              List item for chat from Array inside array React Native

                                                              Thiostrepton

                                                              Caerphilly