Unable to bulk insert docs into elastic search index: “Illegal Argument Exception: bulk request must be...












0















I want to insert the docs contained my my_docs.json into my elasticsearch index. My json file looks like this:



{"_index":"twitter","_type":"_doc","_id":"v8XSJ2cB_TizemYYi5mW","_score":1,"_source":{"user":"me","c":"2018-11-18T17:16:08.953Z","content":"this is cool stuff"}}

{"_index":"twitter","_type":"_doc","_id":"x8XbJ2cB_TizemYYxZmf","_score":1,"_source":{"user":"you","c":"2018-11-18T17:26:13.634Z","content":"this is some other cool stuff"}}


I tried: curl -XPUT 'http://localhost:9200/twitter/_bulk?pretty&refresh' -H "Content-Type: application/json" -d @my_docs.json



where twitter is my index.



I got an 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
}


I added a 'n' to the end of the file, but the problem persisted and I got the same error.



How do I fix this?










share|improve this question

























  • Have you seen stackoverflow.com/questions/48579980/… ?

    – Matthew Pope
    Nov 25 '18 at 16:54











  • It seems like you might need to specify the content type as data/binary.

    – Matthew Pope
    Nov 25 '18 at 16:55
















0















I want to insert the docs contained my my_docs.json into my elasticsearch index. My json file looks like this:



{"_index":"twitter","_type":"_doc","_id":"v8XSJ2cB_TizemYYi5mW","_score":1,"_source":{"user":"me","c":"2018-11-18T17:16:08.953Z","content":"this is cool stuff"}}

{"_index":"twitter","_type":"_doc","_id":"x8XbJ2cB_TizemYYxZmf","_score":1,"_source":{"user":"you","c":"2018-11-18T17:26:13.634Z","content":"this is some other cool stuff"}}


I tried: curl -XPUT 'http://localhost:9200/twitter/_bulk?pretty&refresh' -H "Content-Type: application/json" -d @my_docs.json



where twitter is my index.



I got an 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
}


I added a 'n' to the end of the file, but the problem persisted and I got the same error.



How do I fix this?










share|improve this question

























  • Have you seen stackoverflow.com/questions/48579980/… ?

    – Matthew Pope
    Nov 25 '18 at 16:54











  • It seems like you might need to specify the content type as data/binary.

    – Matthew Pope
    Nov 25 '18 at 16:55














0












0








0








I want to insert the docs contained my my_docs.json into my elasticsearch index. My json file looks like this:



{"_index":"twitter","_type":"_doc","_id":"v8XSJ2cB_TizemYYi5mW","_score":1,"_source":{"user":"me","c":"2018-11-18T17:16:08.953Z","content":"this is cool stuff"}}

{"_index":"twitter","_type":"_doc","_id":"x8XbJ2cB_TizemYYxZmf","_score":1,"_source":{"user":"you","c":"2018-11-18T17:26:13.634Z","content":"this is some other cool stuff"}}


I tried: curl -XPUT 'http://localhost:9200/twitter/_bulk?pretty&refresh' -H "Content-Type: application/json" -d @my_docs.json



where twitter is my index.



I got an 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
}


I added a 'n' to the end of the file, but the problem persisted and I got the same error.



How do I fix this?










share|improve this question
















I want to insert the docs contained my my_docs.json into my elasticsearch index. My json file looks like this:



{"_index":"twitter","_type":"_doc","_id":"v8XSJ2cB_TizemYYi5mW","_score":1,"_source":{"user":"me","c":"2018-11-18T17:16:08.953Z","content":"this is cool stuff"}}

{"_index":"twitter","_type":"_doc","_id":"x8XbJ2cB_TizemYYxZmf","_score":1,"_source":{"user":"you","c":"2018-11-18T17:26:13.634Z","content":"this is some other cool stuff"}}


I tried: curl -XPUT 'http://localhost:9200/twitter/_bulk?pretty&refresh' -H "Content-Type: application/json" -d @my_docs.json



where twitter is my index.



I got an 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
}


I added a 'n' to the end of the file, but the problem persisted and I got the same error.



How do I fix this?







json elasticsearch curl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 16:47







nz_21

















asked Nov 25 '18 at 16:41









nz_21nz_21

2031211




2031211













  • Have you seen stackoverflow.com/questions/48579980/… ?

    – Matthew Pope
    Nov 25 '18 at 16:54











  • It seems like you might need to specify the content type as data/binary.

    – Matthew Pope
    Nov 25 '18 at 16:55



















  • Have you seen stackoverflow.com/questions/48579980/… ?

    – Matthew Pope
    Nov 25 '18 at 16:54











  • It seems like you might need to specify the content type as data/binary.

    – Matthew Pope
    Nov 25 '18 at 16:55

















Have you seen stackoverflow.com/questions/48579980/… ?

– Matthew Pope
Nov 25 '18 at 16:54





Have you seen stackoverflow.com/questions/48579980/… ?

– Matthew Pope
Nov 25 '18 at 16:54













It seems like you might need to specify the content type as data/binary.

– Matthew Pope
Nov 25 '18 at 16:55





It seems like you might need to specify the content type as data/binary.

– Matthew Pope
Nov 25 '18 at 16:55












1 Answer
1






active

oldest

votes


















0














curl -H "Content-Type: application/json" -XPOST "localhost:9200/{index}/{type}/_bulk?pretty&refresh" --data-binary "@my_docs.json"


Note: The json file should have content in following format for the above to work:



{"index":{"_index":"my_index","_type":"_doc","_id":"1"}}
{"field1":"field 1 data 1","field2":11}
{"index":{"_index":"my_index","_type":"_doc","_id":"2"}}
{"field1":"field 1 data 2","field2":21}`


Each document above is represent by two lines. First line indicates where to index and what is the document id. The next line is actual data of the doc.






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',
    autoActivateHeartbeat: false,
    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%2f53469642%2funable-to-bulk-insert-docs-into-elastic-search-index-illegal-argument-exceptio%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    curl -H "Content-Type: application/json" -XPOST "localhost:9200/{index}/{type}/_bulk?pretty&refresh" --data-binary "@my_docs.json"


    Note: The json file should have content in following format for the above to work:



    {"index":{"_index":"my_index","_type":"_doc","_id":"1"}}
    {"field1":"field 1 data 1","field2":11}
    {"index":{"_index":"my_index","_type":"_doc","_id":"2"}}
    {"field1":"field 1 data 2","field2":21}`


    Each document above is represent by two lines. First line indicates where to index and what is the document id. The next line is actual data of the doc.






    share|improve this answer




























      0














      curl -H "Content-Type: application/json" -XPOST "localhost:9200/{index}/{type}/_bulk?pretty&refresh" --data-binary "@my_docs.json"


      Note: The json file should have content in following format for the above to work:



      {"index":{"_index":"my_index","_type":"_doc","_id":"1"}}
      {"field1":"field 1 data 1","field2":11}
      {"index":{"_index":"my_index","_type":"_doc","_id":"2"}}
      {"field1":"field 1 data 2","field2":21}`


      Each document above is represent by two lines. First line indicates where to index and what is the document id. The next line is actual data of the doc.






      share|improve this answer


























        0












        0








        0







        curl -H "Content-Type: application/json" -XPOST "localhost:9200/{index}/{type}/_bulk?pretty&refresh" --data-binary "@my_docs.json"


        Note: The json file should have content in following format for the above to work:



        {"index":{"_index":"my_index","_type":"_doc","_id":"1"}}
        {"field1":"field 1 data 1","field2":11}
        {"index":{"_index":"my_index","_type":"_doc","_id":"2"}}
        {"field1":"field 1 data 2","field2":21}`


        Each document above is represent by two lines. First line indicates where to index and what is the document id. The next line is actual data of the doc.






        share|improve this answer













        curl -H "Content-Type: application/json" -XPOST "localhost:9200/{index}/{type}/_bulk?pretty&refresh" --data-binary "@my_docs.json"


        Note: The json file should have content in following format for the above to work:



        {"index":{"_index":"my_index","_type":"_doc","_id":"1"}}
        {"field1":"field 1 data 1","field2":11}
        {"index":{"_index":"my_index","_type":"_doc","_id":"2"}}
        {"field1":"field 1 data 2","field2":21}`


        Each document above is represent by two lines. First line indicates where to index and what is the document id. The next line is actual data of the doc.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 0:26









        Nishant SainiNishant Saini

        1,204918




        1,204918






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469642%2funable-to-bulk-insert-docs-into-elastic-search-index-illegal-argument-exceptio%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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)