# Load Json to Elasticsearch

**URL:** <https://discuss.elastic.co/t/load-json-to-elasticsearch/195235>\
**Category:** Elasticsearch\
**Created:** [August 14, 2019, 3:57pm UTC](https://discuss.elastic.co/t/load-json-to-elasticsearch/195235 "2019-08-14T15:57:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkajdos](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@mkajdos](https://discuss.elastic.co/u/mkajdos)\
**Post date:** [August 14, 2019, 3:57pm UTC](https://discuss.elastic.co/t/load-json-to-elasticsearch/195235/1 "2019-08-14T15:57:39Z")

</div>

I am new to Elasticseach and I am on the 7.3.0 release. On the documentation page: [https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-explore-data.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-explore-data.html)  
there is command to load the "accounts.json". I copied that into file "account.json" and ran the provided curl command with following results:

PS C:\cmsp1\Elasticsearch\> curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/\_bulk?pretty&refresh" --data-binary "@accounts.json"  
Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Content-Type: application/json" value of type "System.String" to type "System.Collections.IDictionary".  
At line:1 char:9

- curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/ ...
- 

```
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

```

  - CategoryInfo : InvalidArgument: (🙂 [Invoke-WebRequest], ParameterBindingException
  - FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

The first few lines of the account.json is:  
{"index":{"\_id":"1"}}  
{"account\_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes [Lane","employer":"Pyrami","email":"amberduke@pyrami.com](mailto:Lane%22,%22employer%22:%22Pyrami%22,%22email%22:%22amberduke@pyrami.com)","city":"Brogan","state":"IL"}  
{"index":{"\_id":"6"}}  
{"account\_number":6,"balance":5686,"firstname":"Hattie","lastname":"Bond","age":36,"gender":"M","address":"671 Bristol [Street","employer":"Netagy","email":"hattiebond@netagy.com](mailto:Street%22,%22employer%22:%22Netagy%22,%22email%22:%22hattiebond@netagy.com)","city":"Dante","state":"TN"}  
{"index":{"\_id":"13"}}  
Can you help? I run on Win 10

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [August 15, 2019, 8:18am UTC](https://discuss.elastic.co/t/load-json-to-elasticsearch/195235/2 "2019-08-15T08:18:17Z")

</div>

The problem here is that the command is being run with PowerShell, rather than curl.

For better or worse, [PowerShell aliased `curl` command to `Invoke-WebRequest`](https://daniel.haxx.se/blog/2016/08/19/removing-the-powershell-curl-alias/) in an early version, which [won't be removed in a future version](https://github.com/PowerShell/PowerShell-RFC/issues/16), due to the potential for breaking changes.

You have a few options:

1. Download [curl for Windows](https://curl.haxx.se/windows/) and invoke the `curl.exe` with the parameters as above. You may consider putting curl.exe in the path environment variable, and removing the `curl` alias in your PowerShell profile:

2. Use [WSL for Windows](https://docs.microsoft.com/en-us/windows/wsl/install-win10), and use `curl` within

3. Use PowerShell to make the request, rather than `curl`

---

<div class="post-metadata">

**Author:** ![mkajdos](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@mkajdos](https://discuss.elastic.co/u/mkajdos)\
**Post date:** [August 15, 2019, 12:24pm UTC](https://discuss.elastic.co/t/load-json-to-elasticsearch/195235/3 "2019-08-15T12:24:00Z")

</div>

Thank you for quick response.

I already had curl installed so I ran standard CMD with following results. Looking at the accounts.json file, all lines are terminated with CR/LF.

Is there some special configuration missing?  
Is the problem in the command formulation or in the source file?

C:\cmsp1\Elasticsearch\>curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/\_bulk?pretty&refresh" --data-binary "@accounts.json"  
{  
"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  
}

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [August 15, 2019, 2:03pm UTC](https://discuss.elastic.co/t/load-json-to-elasticsearch/195235/4 "2019-08-15T14:03:19Z")

</div>

Each line must end with `\n` and not `\r\n` in the new line delimited JSON bulk request body.

If you [save the file directly from GitHub](https://raw.githubusercontent.com/elastic/elasticsearch/master/docs/src/test/resources/accounts.json) with right-click \> save, it'll be `\n` delimited. The alternative is to change the existing file you have to replace `\r\n` with `\n`.

---

<div class="post-metadata">

**Author:** ![mkajdos](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@mkajdos](https://discuss.elastic.co/u/mkajdos)\
**Post date:** [August 15, 2019, 2:34pm UTC](https://discuss.elastic.co/t/load-json-to-elasticsearch/195235/5 "2019-08-15T14:34:45Z")

</div>

This worked - the termination must be Unix. Changed with Notepad++  
Thank you!

---

<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 12, 2019, 2:36pm UTC](https://discuss.elastic.co/t/load-json-to-elasticsearch/195235/6 "2019-09-12T14:36:19Z")

</div>

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