# The bulk request must be terminated by a newline

**URL:** <https://discuss.elastic.co/t/the-bulk-request-must-be-terminated-by-a-newline/280403>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [August 4, 2021, 8:58am UTC](https://discuss.elastic.co/t/the-bulk-request-must-be-terminated-by-a-newline/280403 "2021-08-04T08:58:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrJHD](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@DrJHD](https://discuss.elastic.co/u/DrJHD)\
**Post date:** [August 4, 2021, 8:58am UTC](https://discuss.elastic.co/t/the-bulk-request-must-be-terminated-by-a-newline/280403/1 "2021-08-04T08:58:03Z")

</div>

Despite reading the answers to the many variants of this question, I am stuck. I have tried 1, 2 and 3 "0a" characters at the end of my file (cut down - I have \>40 files) and get the same results. I must be missing something obvious, but I can't think what. My terminal session follows.

TIA,

John

```auto
dashboard@dashboard:~/es$ hexyl test.json
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000000│ 7b 20 22 69 6e 64 65 78 ┊ 22 20 3a 20 7b 20 22 5f │{ "index┊" : { "_│
│00000010│ 69 6e 64 65 78 22 20 3a ┊ 20 22 62 6f 6f 6b 73 22 │index" :┊ "books"│
│00000020│ 2c 20 22 5f 69 64 22 20 ┊ 3a 20 22 31 22 20 7d 20 │, "_id" ┊: "1" } │
│00000030│ 7d 0a 7b 22 66 69 6c 65 ┊ 22 3a 22 45 3a 5c 5c 42 │}_{"file┊":"E:\\B│
│00000040│ 4f 4f 4b 53 2f 41 4e 44 ┊ 45 52 53 45 4e 2f 53 41 │OOKS/AND┊ERSEN/SA│
│00000050│ 55 43 59 5f 42 4f 22 2c ┊ 22 63 6f 6e 74 65 6e 74 │UCY_BO",┊"content│
│00000060│ 73 22 3a 22 20 54 48 45 ┊ 20 45 4e 44 5c 6e 22 7d │s":" THE┊ END\n"}│
│00000070│ 0a 0a ┊ │__ ┊ │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘
dashboard@dashboard:~/es$ curl --data-binary -v -T test.json -H 'Content-Type: application/json' http://worker1:31256/books/_bulk?format=yaml
---
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
dashboard@dashboard:~/es$ curl --data-binary -v -T test.json -H 'Content-Type: application/x-ndjson' http://worker1:31256/books/_bulk?format=yaml
---
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
dashboard@dashboard:~/es$ curl http://worker1:31256/_cat/indices
yellow open books HgdlldNLSPG_XyfNyYrWqA 1 1 0 0 208b 208b
dashboard@dashboard:~/es$ curl http://worker1:31256/
{
  "name" : "elasticsearch-7c4b4f7bd9-2crz8",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "sLqJwAqLShmZawWMaI-KXg",
  "version" : {
    "number" : "7.13.4",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "c5f60e894ca0c61cdbae4f5a686d9f08bcefc942",
    "build_date" : "2021-07-14T18:33:36.673943207Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

```

Update to clarify the file contents:

```auto
dashboard@dashboard:~/es$ cat test.json 
{ "index" : { "_index" : "books", "_id" : "1" } }
{"file":"E:\\BOOKS/ANDERSEN/SAUCY_BO","contents":" THE END\n"}

dashboard@dashboard:~/es$

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 4, 2021, 9:15am UTC](https://discuss.elastic.co/t/the-bulk-request-must-be-terminated-by-a-newline/280403/2 "2021-08-04T09:15:43Z")

</div>

unless I am misinterpreting that asciidump, you are ending your JSON data value with a newline, but you need to add a newline **after** all your json data... so `" THE┊ END"}\n` instead of `" THE┊ END\n"}`

---

<div class="post-metadata">

**Author:** ![DrJHD](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@DrJHD](https://discuss.elastic.co/u/DrJHD)\
**Post date:** [August 4, 2021, 9:22am UTC](https://discuss.elastic.co/t/the-bulk-request-must-be-terminated-by-a-newline/280403/3 "2021-08-04T09:22:09Z")

</div>

I think one of us is misinterpreting. The "\n" inside the JSON is 5c 6e, i.e. an escaped sequence. The two 0a characters (in this version) are after the closing quote and brace. They appear as underscores in the right hand side of the dump.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [August 4, 2021, 11:19am UTC](https://discuss.elastic.co/t/the-bulk-request-must-be-terminated-by-a-newline/280403/4 "2021-08-04T11:19:51Z")

</div>

Your `curl` command line is broken, it's setting `Content-Length: 2` so Elasticsearch is only reading the first two bytes of the request. I think the combination `--data-binary -v` means it's trying to send the literal string `-v`, which the `-T` is then overriding. Try this instead:

```auto
curl -v 'http://worker1:31256/books/_bulk?format=yaml' -H 'Content-type: application/x-ndjson' --data-binary @test.json

```

---

<div class="post-metadata">

**Author:** ![DrJHD](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@DrJHD](https://discuss.elastic.co/u/DrJHD)\
**Post date:** [August 4, 2021, 11:25am UTC](https://discuss.elastic.co/t/the-bulk-request-must-be-terminated-by-a-newline/280403/5 "2021-08-04T11:25:02Z")

</div>

Thank you. That was the problem. You have saved me hours.

Regards,

John

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 1, 2021, 11:25am UTC](https://discuss.elastic.co/t/the-bulk-request-must-be-terminated-by-a-newline/280403/6 "2021-09-01T11:25:48Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
