# How to post a json array to elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757>\
**Category:** Elasticsearch\
**Created:** [November 19, 2012, 8:01am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757 "2012-11-19T08:01:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Wang](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Bill\_Wang](https://discuss.elastic.co/u/Bill_Wang)\
**Post date:** [November 19, 2012, 8:01am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/1 "2012-11-19T08:01:17Z")

</div>

Hi all,

I'm a newbie here, when I post an item to elasticsearch  
curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "@Location.json"

Location.json  
{  
"Name" : "aaa",  
"Age" : "20"  
}

However, if I want to post more than 1 item, I tried below  
Location.json  
[  
{ "Name" : "aaa","Age" : "20"},  
{ "Name" : "bbb","Age" : "30"}  
]  
It doesn't work.

somebody could tell me how to reach this.

Thanks,  
Bill

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 19, 2012, 8:20am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/2 "2012-11-19T08:20:22Z")

</div>

Welcome !

You have to send valid JSON.

Something like

> { "content" = [  
> { "Name" : "aaa","Age" : "20"},  
> { "Name" : "bbb","Age" : "30"}  
> ] }

See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 19 nov. 2012 à 09:01, Bill Wang [wiiee000@gmail.com](mailto:wiiee000@gmail.com) a écrit :

> Hi all,
> 
> I'm a newbie here, when I post an item to elasticsearch  
> curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "@Location.json"
> 
> Location.json  
> {  
> "Name" : "aaa",  
> "Age" : "20"  
> }
> 
> However, if I want to post more than 1 item, I tried below  
> Location.json  
> [  
> { "Name" : "aaa","Age" : "20"},  
> { "Name" : "bbb","Age" : "30"}  
> ]  
> It doesn't work.
> 
> somebody could tell me how to reach this.
> 
> ## Thanks, Bill

--

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [November 19, 2012, 8:22am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/3 "2012-11-19T08:22:22Z")

</div>

You'll need to do several POSTs for that, or to use the bulk API

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Elasticsearch expects a JSON _object_, not an array

On Mon, Nov 19, 2012 at 10:01 AM, Bill Wang [wiiee000@gmail.com](mailto:wiiee000@gmail.com) wrote:

> Hi all,
> 
> I'm a newbie here, when I post an item to elasticsearch  
> curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "@Location.json"
> 
> Location.json  
> {  
> "Name" : "aaa",  
> "Age" : "20"  
> }
> 
> However, if I want to post more than 1 item, I tried below  
> Location.json  
> [  
> { "Name" : "aaa","Age" : "20"},  
> { "Name" : "bbb","Age" : "30"}  
> ]  
> It doesn't work.
> 
> somebody could tell me how to reach this.
> 
> Thanks,  
> Bill
> 
> --

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 19, 2012, 8:28am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/4 "2012-11-19T08:28:25Z")

</div>

Sorry. I misread your question.

See Bulk indexing.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 19 nov. 2012 à 09:20, David Pilato [david@pilato.fr](mailto:david@pilato.fr) a écrit :

> Welcome !
> 
> You have to send valid JSON.
> 
> Something like
> 
> > { "content" = [  
> > { "Name" : "aaa","Age" : "20"},  
> > { "Name" : "bbb","Age" : "30"}  
> > ] }
> 
> See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 19 nov. 2012 à 09:01, Bill Wang [wiiee000@gmail.com](mailto:wiiee000@gmail.com) a écrit :
> 
> > Hi all,
> > 
> > I'm a newbie here, when I post an item to elasticsearch  
> > curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "@Location.json"
> > 
> > Location.json  
> > {  
> > "Name" : "aaa",  
> > "Age" : "20"  
> > }
> > 
> > However, if I want to post more than 1 item, I tried below  
> > Location.json  
> > [  
> > { "Name" : "aaa","Age" : "20"},  
> > { "Name" : "bbb","Age" : "30"}  
> > ]  
> > It doesn't work.
> > 
> > somebody could tell me how to reach this.
> > 
> > ## Thanks, Bill
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Bill\_Wang](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Bill\_Wang](https://discuss.elastic.co/u/Bill_Wang)\
**Post date:** [November 19, 2012, 9:01am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/5 "2012-11-19T09:01:37Z")

</div>

Thanks Itamar and David so much.  
However, I'm not able to use \_bulk successfully.

I got error below.  
curl -XPOST [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk) --data-binary  
"@Location.json"  
{"error":"ActionRequestValidationException[Validation Failed: 1: no  
requests add  
ed;]","status":500}

Location.json  
{"Id":"1230","Name":"Melbourne -  
Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}  
{"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}

I mapping Id as \_id.

On Monday, November 19, 2012 4:28:37 PM UTC+8, David Pilato wrote:

> Sorry. I misread your question.
> 
> See Bulk indexing.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 19 nov. 2012 à 09:20, David Pilato \<[da...@pilato.fr](mailto:da...@pilato.fr) \<javascript:\>\> a  
> écrit :
> 
> Welcome !
> 
> You have to send valid JSON.
> 
> Something like
> 
> { "content" = [  
> { "Name" : "aaa","Age" : "20"},  
> { "Name" : "bbb","Age" : "30"}  
> ] }
> 
> See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 19 nov. 2012 à 09:01, Bill Wang \<[wiie...@gmail.com](mailto:wiie...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hi all,
> 
> I'm a newbie here, when I post an item to elasticsearch  
> curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "@Location.json"
> 
> Location.json  
> {  
> "Name" : "aaa",  
> "Age" : "20"  
> }
> 
> However, if I want to post more than 1 item, I tried below  
> Location.json  
> [  
> { "Name" : "aaa","Age" : "20"},  
> { "Name" : "bbb","Age" : "30"}  
> ]  
> It doesn't work.
> 
> somebody could tell me how to reach this.
> 
> Thanks,  
> Bill
> 
> --
> 
> --

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 19, 2012, 9:06am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/6 "2012-11-19T09:06:03Z")

</div>

Have a look at [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/bulk.html)  
Your json file should look like:

> ```
> { "index" : { "_index" : "sg", "_type" : "Location", "_id" : "1230" } }
> 
> ```

> {"Id":"1230","Name":"Melbourne -  
> Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}

> ```
> { "index" : { "_index" : "sg", "_type" : "Location", "_id" : "1234" } }
> 
> ```

> {"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}

HTH

Le 19 novembre 2012 à 10:01, Bill Wang [wiiee000@gmail.com](mailto:wiiee000@gmail.com) a écrit :

> Thanks Itamar and David so much.  
> However, I'm not able to use \_bulk successfully.
> 
> I got error below.  
> curl -XPOST [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk) --data-binary  
> "@Location.json"  
> {"error":"ActionRequestValidationException[Validation Failed: 1: no requests  
> add  
> ed;]","status":500}
> 
> Location.json  
> {"Id":"1230","Name":"Melbourne -  
> Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}
> 
> {"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}
> 
> I mapping Id as \_id.
> 
> On Monday, November 19, 2012 4:28:37 PM UTC+8, David Pilato wrote:
> 
> > > Sorry. I misread your question.
> > 
> > See Bulk indexing.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 19 nov. 2012 à 09:20, David Pilato \< [da...@pilato.fr](mailto:da...@pilato.fr)\> a écrit :
> > 
> > ```
> > > > > Welcome !
> > 
> > ```
> > 
> > > ```
> > > You have to send valid JSON.
> > > 
> > > Something like
> > > 
> > > > > > > { "content" = [
> > > 
> > > ```
> > > 
> > > > ```
> > > > { "Name" : "aaa","Age" : "20"},
> > > > { "Name" : "bbb","Age" : "30"}
> > > > ] }
> > > > 
> > > > > > > 
> > > > 
> > > > ```
> > > 
> > > ```
> > > See
> > > 
> > > ```
> > > 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)  
> > > [http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> > > 
> > > ```
> > > --
> > > David ;-)
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 19 nov. 2012 à 09:01, Bill Wang <
> > > 
> > > ```
> > > 
> > > [http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)  
> > > [wiie...@gmail.com](mailto:wiie...@gmail.com)\> a écrit :
> > > 
> > > ```
> > > > > > > Hi all,
> > > 
> > > ```
> > > 
> > > > ```
> > > > I'm a newbie here, when I post an item to elasticsearch
> > > > curl -XPOST http://localhost:9200/sg/Location -d
> > > > 
> > > > ```
> > > > 
> > > > "@Location.json" [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > Location.json  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > { [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > "Name" : "aaa", [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > "Age" : "20" [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > } [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > However, if I want to post more than 1 item, I tried below  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > Location.json  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > [[http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > { "Name" : "aaa","Age" : "20"},  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > { "Name" : "bbb","Age" : "30"}  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > ] [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > It doesn't work. [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > somebody could tell me how to reach this.  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > Thanks,  
> > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > Bill [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> > > > 
> > > > ```
> > > > --
> > > > 
> > > > <http://localhost:9200/sg/Location>
> > > > 
> > > > > > > 
> > > > 
> > > > ```
> > > 
> > > ```
> > > --
> > > 
> > > <http://localhost:9200/sg/Location>
> > > 
> > > ```
> > > 
> > > > > >
> 
> --
> 
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)

[http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Bill\_Wang](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Bill\_Wang](https://discuss.elastic.co/u/Bill_Wang)\
**Post date:** [November 19, 2012, 9:22am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/7 "2012-11-19T09:22:25Z")

</div>

Thanks David a lot, you blow me away:)  
It works now.

this line looks redundant, is there a way to remove it to make it index  
automatically by mapping.  
{ "index" : { "\_index" : "sg", "\_type" : "Location", "\_id" : "1230" } }  
like the way curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "{"Id":"1230","Name":"Melbourne

- Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}"

On Monday, November 19, 2012 5:06:08 PM UTC+8, David Pilato wrote:

> Have a look at [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/bulk.html)  
> Your json file should look like:
> 
> { "index" : { "\_index" : "sg", "\_type" : "Location", "\_id" : "1230" } }
> 
> {"Id":"1230","Name":"Melbourne -  
> Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}
> 
> { "index" : { "\_index" : "sg", "\_type" : "Location", "\_id" : "1234" } }
> 
> {"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}
> 
> HTH
> 
> Le 19 novembre 2012 à 10:01, Bill Wang \<[wiie...@gmail.com](mailto:wiie...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Thanks Itamar and David so much.  
> However, I'm not able to use \_bulk successfully.
> 
> I got error below.  
> curl -XPOST [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk) --data-binary  
> "@Location.json"  
> {"error":"ActionRequestValidationException[Validation Failed: 1: no  
> requests add  
> ed;]","status":500}
> 
> Location.json  
> {"Id":"1230","Name":"Melbourne -  
> Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}  
> {"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}
> 
> I mapping Id as \_id.
> 
> On Monday, November 19, 2012 4:28:37 PM UTC+8, David Pilato wrote:
> 
> Sorry. I misread your question.
> 
> See Bulk indexing.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 19 nov. 2012 à 09:20, David Pilato \< [da...@pilato.fr](mailto:da...@pilato.fr)\> a écrit :
> 
> Welcome !
> 
> You have to send valid JSON.
> 
> Something like
> 
> { "content" = [  
> { "Name" : "aaa","Age" : "20"},  
> { "Name" : "bbb","Age" : "30"}  
> ] }
> 
> See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 19 nov. 2012 à 09:01, Bill Wang \<[http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)  
> [wiie...@gmail.com](mailto:wiie...@gmail.com)\> a écrit :
> 
> Hi all,
> 
> I'm a newbie here, when I post an item to elasticsearch  
> curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "@Location.json"[http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> Location.json  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> { [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> "Name" : "aaa", [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> "Age" : "20" [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> } [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> However, if I want to post more than 1 item, I tried below [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> Location.json  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [[http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> { "Name" : "aaa","Age" : "20"}, [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> { "Name" : "bbb","Age" : "30"} [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> ] [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> It doesn't work. [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> somebody could tell me how to reach this.[http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> Thanks,  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> Bill [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> 
> --
> 
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> 
> --
> 
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> 
> --
> 
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> 
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 19, 2012, 9:59am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/8 "2012-11-19T09:59:17Z")

</div>

You feel that you did redundant code but, in fact, no.

I mean that when you post or put a document with:

> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)

or

> [http://localhost:9200/sg/Location/1230](http://localhost:9200/sg/Location/1230)

Elasticsearch find sg as \_index, Location as \_type and 1230 as \_id.

That's why you have to send it within the bulk request even if it's look  
redundant.

HTH

Le 19 novembre 2012 à 10:22, Bill Wang [wiiee000@gmail.com](mailto:wiiee000@gmail.com) a écrit :

> Thanks David a lot, you blow me away:)  
> It works now.
> 
> this line looks redundant, is there a way to remove it to make it index  
> automatically by mapping.  
> { "index" : { "\_index" : "sg" , "\_type" : "Location" , "\_id" : "1230" } }  
> like the way curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d  
> "{"Id":"1230","Name":"Melbourne -  
> Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}"
> 
> On Monday, November 19, 2012 5:06:08 PM UTC+8, David Pilato wrote:
> 
> > > Have a look at  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/bulk.html)  
> > > [http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)  
> > > Your json file should look like:
> > 
> > ```
> > > > > 
> > 
> > ```
> > 
> > > ```
> > > { "index" : { "_index" : "sg", "_type" : "Location", "_id" : "1230"
> > > 
> > > ```
> > > 
> > > } }
> > > 
> > > > > {"Id":"1230","Name":"Melbourne -  
> > > > > Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}  
> > > > > [http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)
> > > 
> > > ```
> > > > > > > 
> > > 
> > > ```
> > > 
> > > > ```
> > > > { "index" : { "_index" : "sg", "_type" : "Location", "_id" :
> > > > 
> > > > ```
> > > > 
> > > > "1234" } }
> > > > 
> > > > ```
> > > > > > > <http://www.elasticsearch.org/guide/reference/api/bulk.html>
> > > > 
> > > > ```
> > > 
> > > ```
> > > > > > > <http://www.elasticsearch.org/guide/reference/api/bulk.html>
> > > 
> > > ```
> > > 
> > > > ```
> > > > {"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}
> > > > 
> > > > ```
> > > > 
> > > > [http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)
> > > > 
> > > > ```
> > > > HTH
> > > > 
> > > > Le 19 novembre 2012 à 10:01, Bill Wang <
> > > > 
> > > > ```
> > > > 
> > > > [http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)  
> > > > [wiie...@gmail.com](mailto:wiie...@gmail.com)\> a écrit :
> > > > 
> > > > ```
> > > > > > > > > Thanks Itamar and David so much.
> > > > 
> > > > ```
> > > > 
> > > > > ```
> > > > > However, I'm not able to use _bulk successfully.
> > > > > 
> > > > > I got error below.
> > > > > curl -XPOST http://localhost:9200/sg/Location/_bulk
> > > > > 
> > > > > ```
> > > > > 
> > > > > --data-binary "@Location.json"  
> > > > > [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> > > > > [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> > > > > {"error":"ActionRequestValidationException[Validation  
> > > > > Failed: 1: no requests add [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> > > > > ed;]","status":500}
> > > > > 
> > > > > ```
> > > > > Location.json <http://localhost:9200/sg/Location/_bulk>
> > > > > {"Id":"1230","Name":"Melbourne -
> > > > > 
> > > > > ```
> > > > > 
> > > > > Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}  
> > > > > [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)
> > > > > 
> > > > > ```
> > > > > {"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}
> > > > > 
> > > > > ```
> > > > > 
> > > > > [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)
> > > > > 
> > > > > ```
> > > > > I mapping Id as _id.
> > > > > 
> > > > > On Monday, November 19, 2012 4:28:37 PM UTC+8, David
> > > > > 
> > > > > ```
> > > > > 
> > > > > Pilato wrote: [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> > > > > \> \> \> \> \> \> [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)
> > > > > 
> > > > > > ```
> > > > > > Sorry. I misread your question.
> > > > > > 
> > > > > > See Bulk indexing.
> > > > > > 
> > > > > > --
> > > > > > David ;-)
> > > > > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > > > > 
> > > > > > Le 19 nov. 2012 à 09:20, David Pilato <
> > > > > > 
> > > > > > ```
> > > > > > 
> > > > > > [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk) [da...@pilato.fr](mailto:da...@pilato.fr) \> a écrit  
> > > > > > :
> > > > > > 
> > > > > > ```
> > > > > > <http://localhost:9200/sg/Location/_bulk>
> > > > > > 
> > > > > > > > > > > > > <http://localhost:9200/sg/Location/_bulk>
> > > > > > 
> > > > > > ```
> > > > > > 
> > > > > > > ```
> > > > > > > Welcome !
> > > > > > > 
> > > > > > > You have to send valid JSON.
> > > > > > > 
> > > > > > > Something like
> > > > > > > 
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > "content" = [
> > > > > > > 
> > > > > > > ```
> > > > > > > 
> > > > > > > > ```
> > > > > > > > { "Name" : "aaa","Age" : "20"},
> > > > > > > > { "Name" : "bbb","Age" : "30"}
> > > > > > > > ] }
> > > > > > > > 
> > > > > > > > > > > > > > > 
> > > > > > > > 
> > > > > > > > ```
> > > > > > > 
> > > > > > > ```
> > > > > > > See <http://localhost:9200/sg/Location/_bulk>
> > > > > > > 
> > > > > > > ```
> > > > > > > 
> > > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)  
> > > > > > > [http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> > > > > > > 
> > > > > > > ```
> > > > > > > --
> > > > > > > David ;-)
> > > > > > > Twitter : @dadoonet / @elasticsearchfr /
> > > > > > > 
> > > > > > > ```
> > > > > > > 
> > > > > > > @scrutmydocs  
> > > > > > > [http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> > > > > > > 
> > > > > > > ```
> > > > > > > Le 19 nov. 2012 à 09:01, Bill Wang <
> > > > > > > 
> > > > > > > ```
> > > > > > > 
> > > > > > > [http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)  
> > > > > > > [wiie...@gmail.com](mailto:wiie...@gmail.com)\> a écrit :
> > > > > > > 
> > > > > > > ```
> > > > > > > > > > > > > > > Hi
> > > > > > > > > > > > > > > all,
> > > > > > > 
> > > > > > > ```
> > > > > > > 
> > > > > > > > ```
> > > > > > > > I'm a newbie here, when I post an item to
> > > > > > > > 
> > > > > > > > ```
> > > > > > > > 
> > > > > > > > elasticsearch  
> > > > > > > > curl -XPOST  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "@Location.json"  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > Location.json  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > { [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > "Name" : "aaa",  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > "Age" : "20"  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > } [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > However, if I want to post more than 1  
> > > > > > > > item, I tried below [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > Location.json  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > [[http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > { "Name" : "aaa","Age" : "20"},  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > { "Name" : "bbb","Age" : "30"}  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > ] [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > It doesn't work.  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > somebody could tell me how to reach this.  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > Thanks,  
> > > > > > > > [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> > > > > > > > Bill [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> > > > > > > > 
> > > > > > > > ```
> > > > > > > > --
> > > > > > > > 
> > > > > > > > <http://localhost:9200/sg/Location>
> > > > > > > > 
> > > > > > > > > > > > > > > 
> > > > > > > > 
> > > > > > > > ```
> > > > > > > 
> > > > > > > ```
> > > > > > > --
> > > > > > > 
> > > > > > > <http://localhost:9200/sg/Location>
> > > > > > > 
> > > > > > > > > > > > > > > > > > 
> > > > > > > 
> > > > > > > ```
> > > > > 
> > > > > ```
> > > > > --
> > > > > 
> > > > > <http://localhost:9200/sg/Location>
> > > > > 
> > > > > <http://localhost:9200/sg/Location>
> > > > > 
> > > > > --
> > > > > David Pilato
> > > > > http://www.scrutmydocs.org/ <http://www.scrutmydocs.org/>
> > > > > http://dev.david.pilato.fr/ <http://dev.david.pilato.fr/>
> > > > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > > > 
> > > > > > > > > 
> > > > > 
> > > > > ```
> > > > 
> > > > ```
> > > > --
> > > > 
> > > > > > > 
> > > > 
> > > > ```
> > > > 
> > > > > >

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Anders](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anders/32/1948_2.png) [@Anders](https://discuss.elastic.co/u/Anders)\
**Post date:** [November 28, 2013, 7:35am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/9 "2013-11-28T07:35:57Z")

</div>

Has this behavior been changed?

Looking at

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

"The endpoints are /\_bulk, /{index}/\_bulk, and {index}/type/\_bulk. When the  
index or the index/type are provided, they will be used by default on bulk  
items that don’t provide them explicitly."

What are the minimal information required for bulk indexing?  
[http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
{ "index" : {"\_id" : "1230" } }  
{"Id":"1230","Name":"Melbourne -  
Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}  
{ "index" : {"\_id" : "1234" } }  
{"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}

Is the meta-line still required? If so, is "\_id" still required? Or is {  
"index" : {} } enough?

Is it feasible to bulk load files with millions of items or should they be  
divided into smaller chunks? Hundreds of MB, tens of MB or less than 1MB?

Den måndagen den 19:e november 2012 kl. 10:59:24 UTC+1 skrev David Pilato:

> You feel that you did redundant code but, in fact, no.
> 
> I mean that when you post or put a document with:
> 
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> 
> or
> 
> [http://localhost:9200/sg/Location/1230](http://localhost:9200/sg/Location/1230)
> 
> Elasticsearch find sg as \_index, Location as \_type and 1230 as \_id.
> 
> That's why you have to send it within the bulk request even if it's look  
> redundant.
> 
> HTH
> 
> Le 19 novembre 2012 à 10:22, Bill Wang \<[wiie...@gmail.com](mailto:wiie...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Thanks David a lot, you blow me away:)  
> It works now.
> 
> this line looks redundant, is there a way to remove it to make it index  
> automatically by mapping.  
> { "index" : { "\_index" : "sg" , "\_type" : "Location" , "\_id" :  
> "1230" } }  
> like the way curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "{"Id":"1230","Name":"Melbourne
> 
> - Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}"
> 
> On Monday, November 19, 2012 5:06:08 PM UTC+8, David Pilato wrote:
> 
> Have a look at  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/bulk.html)  
> Your json file should look like:
> 
> { "index" : { "\_index" : "sg", "\_type" : "Location", "\_id" : "1230" } }
> 
> {"Id":"1230","Name":"Melbourne -  
> Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}[http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)
> 
> { "index" : { "\_index" : "sg", "\_type" : "Location", "\_id" : "1234" } }
> 
> [http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)
> 
> [http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)
> 
> {"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}[http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)
> 
> HTH
> 
> Le 19 novembre 2012 à 10:01, Bill Wang \<[http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)  
> [wiie...@gmail.com](mailto:wiie...@gmail.com)\> a écrit :
> 
> Thanks Itamar and David so much.  
> However, I'm not able to use \_bulk successfully.
> 
> I got error below.  
> curl -XPOST [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk) --data-binary  
> "@Location.json" [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> {"error":"ActionRequestValidationException[Validation Failed: 1: no  
> requests add [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> ed;]","status":500}
> 
> Location.json  
> [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> {"Id":"1230","Name":"Melbourne -  
> Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}  
> [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)
> 
> {"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}[http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)
> 
> I mapping Id as \_id.
> 
> On Monday, November 19, 2012 4:28:37 PM UTC+8, David Pilato wrote:  
> [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)
> 
> [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> Sorry. I misread your question.
> 
> See Bulk indexing.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 19 nov. 2012 à 09:20, David Pilato \<  
> [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk) [da...@pilato.fr](mailto:da...@pilato.fr) \> a écrit :
> 
> [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)
> 
> [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> Welcome !
> 
> You have to send valid JSON.
> 
> Something like
> 
> { "content" = [  
> { "Name" : "aaa","Age" : "20"},  
> { "Name" : "bbb","Age" : "30"}  
> ] }
> 
> See [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs  
> [http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)  
> Le 19 nov. 2012 à 09:01, Bill Wang \<[http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)  
> [wiie...@gmail.com](mailto:wiie...@gmail.com)\> a écrit :
> 
> Hi all,
> 
> I'm a newbie here, when I post an item to elasticsearch  
> curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "@Location.json"  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)[http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> Location.json  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> { [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> "Name" : "aaa", [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> "Age" : "20" [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> } [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> However, if I want to post more than 1 item, I tried below [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> Location.json  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [[http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> { "Name" : "aaa","Age" : "20"}, [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> { "Name" : "bbb","Age" : "30"} [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> ] [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> It doesn't work. [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> somebody could tell me how to reach this.[http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> Thanks,  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> Bill [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> 
> --
> 
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> 
> --
> 
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> 
> --
> 
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
> [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d226e9c7-9a47-40a6-8fd5-be7d4a5a2b6c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d226e9c7-9a47-40a6-8fd5-be7d4a5a2b6c%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 28, 2013, 8:33am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/10 "2013-11-28T08:33:22Z")

</div>

Yes meta line is required. You can use bulk for indexing, deleting, updating…  
So we need to know what you want to do.

I'm not aware of any "shortcut" like op\_type=index which will basically say that only index operations are provided in the JSON stream.

It could be a feature request I guess…

For your last comment, make sure that you don't send too many element per bulk request. I often found (for my use cases) that 10k docs per bulk is enough.  
Don't forget that your bulk request needs at some point to be loaded in memory on the node which get the bulk bulk request.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 28 novembre 2013 at 08:36:00, Anders (anders@waglund.se) a écrit:

Has this behavior been changed?

Looking at [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html)  
"The endpoints are /\_bulk, /{index}/\_bulk, and {index}/type/\_bulk. When the index or the index/type are provided, they will be used by default on bulk items that don’t provide them explicitly."

What are the minimal information required for bulk indexing?  
[http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk)  
{ "index" : {"\_id" : "1230" } }  
{"Id":"1230","Name":"Melbourne - Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}  
{ "index" : {"\_id" : "1234" } }  
{"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}

Is the meta-line still required? If so, is "\_id" still required? Or is { "index" : {} } enough?

Is it feasible to bulk load files with millions of items or should they be divided into smaller chunks? Hundreds of MB, tens of MB or less than 1MB?

Den måndagen den 19:e november 2012 kl. 10:59:24 UTC+1 skrev David Pilato:  
You feel that you did redundant code but, in fact, no.

I mean that when you post or put a document with:  
[http://localhost:9200/sg/Location](http://localhost:9200/sg/Location)  
or  
[http://localhost:9200/sg/Location/1230](http://localhost:9200/sg/Location/1230)  
Elasticsearch find sg as \_index, Location as \_type and 1230 as \_id.

That's why you have to send it within the bulk request even if it's look redundant.

HTH

Le 19 novembre 2012 à 10:22, Bill Wang [wiie...@gmail.com](mailto:wiie...@gmail.com) a écrit :  
Thanks David a lot, you blow me away:)  
It works now.

this line looks redundant, is there a way to remove it to make it index automatically by mapping.  
{ "index" : { "\_index" : "sg" , "\_type" : "Location" , "\_id" : "1230" } }  
like the way curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "{"Id":"1230","Name":"Melbourne - Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}"

On Monday, November 19, 2012 5:06:08 PM UTC+8, David Pilato wrote:  
Have a look at [http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)  
Your json file should look like:

{ "index" : { "\_index" : "sg", "\_type" : "Location", "\_id" : "1230" } }  
{"Id":"1230","Name":"Melbourne - Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}  
{ "index" : { "\_index" : "sg", "\_type" : "Location", "\_id" : "1234" } }  
{"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}

HTH

Le 19 novembre 2012 à 10:01, Bill Wang \< [wiie...@gmail.com](mailto:wiie...@gmail.com)\> a écrit :  
Thanks Itamar and David so much.  
However, I'm not able to use \_bulk successfully.

I got error below.  
curl -XPOST [http://localhost:9200/sg/Location/\_bulk](http://localhost:9200/sg/Location/_bulk) --data-binary "@Location.json"  
{"error":"ActionRequestValidationException[Validation Failed: 1: no requests add  
ed;]","status":500}

Location.json  
{"Id":"1230","Name":"Melbourne - Frankston","CityName":"Frankston","Airport":"0","RailwayStation":"0"}  
{"Id":"1234","Name":"Geelong","CityName":"Geelong","StateCode":"VIC","Airport":"0","RailwayStation":"0"}

I mapping Id as \_id.

On Monday, November 19, 2012 4:28:37 PM UTC+8, David Pilato wrote:  
Sorry. I misread your question.

See Bulk indexing.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 19 nov. 2012 à 09:20, David Pilato \< da...@pilato.fr \> a écrit :

Welcome !

You have to send valid JSON.

Something like

{ "content" = [  
{ "Name" : "aaa","Age" : "20"},  
{ "Name" : "bbb","Age" : "30"}  
] }

See [http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 19 nov. 2012 à 09:01, Bill Wang \< [wiie...@gmail.com](mailto:wiie...@gmail.com)\> a écrit :

Hi all,

I'm a newbie here, when I post an item to elasticsearch  
curl -XPOST [http://localhost:9200/sg/Location](http://localhost:9200/sg/Location) -d "@Location.json"

Location.json  
{  
"Name" : "aaa",  
"Age" : "20"  
}

However, if I want to post more than 1 item, I tried below  
Location.json  
[  
{ "Name" : "aaa","Age" : "20"},  
{ "Name" : "bbb","Age" : "30"}  
]  
It doesn't work.

somebody could tell me how to reach this.

Thanks,  
Bill

--

--

--

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

## -- David Pilato [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/) [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/) Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d226e9c7-9a47-40a6-8fd5-be7d4a5a2b6c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d226e9c7-9a47-40a6-8fd5-be7d4a5a2b6c%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.5296ffd2.2cd89a32.3e14%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5296ffd2.2cd89a32.3e14%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:04am UTC](https://discuss.elastic.co/t/how-to-post-a-json-array-to-elasticsearch/9757/11 "2017-07-06T02:04:21Z")

</div>


