How to build bulk request body

In my project i need to making bulk requests to elasticsearch, that means
making http post requests in program instead of using curl.

I already set content-type to json, and the body is like: '{ "index" :
{"_index":"test","_type":"one","_id":"1"}}\n{"name":"test","id":"1" }\n',
and got a error: {"error":"ActionRequestValidationException[Validation
Failed: 1: no requests added;]","status":500}

In terminal using curl -XPOST localhost:9200/_bulk -d '{ "index" :
{"_index":"test","_type":"one","_id":"1"}}\n{"name":"test","id":"1" }\n'
got the same error, and that's ok:
curl -XPOST localhost:9200/_bulk -d '{ "index" :
{"_index":"test","_type":"one","_id":"1"}}
{"name":"test","id":"1" }
'
Right now i have to build request body by my own, the guide
(http://www.elasticsearch.org/guide/reference/api/bulk/) said use newline
character \n, that'sexactly what i did, and it seems wrong, i wanna know
how to describe newline character in request body.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

You need to send in Bulk a real Line return character (which we represent with \n).
You can create a file with proper line endings and then use it from curl.

$ cat requests
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
$ curl -s -XPOST localhost:9200/_bulk --data-binary @requests; echo
{"took":7,"items":[{"create":{"_index":"test","_type":"type1","_id":"1","_version":1,"ok":true}}]}

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

Le 25 juin 2013 à 05:36, mega yuhg2310@gmail.com a écrit :

In my project i need to making bulk requests to elasticsearch, that means making http post requests in program instead of using curl.

I already set content-type to json, and the body is like: '{ "index" : {"_index":"test","_type":"one","_id":"1"}}\n{"name":"test","id":"1" }\n', and got a error: {"error":"ActionRequestValidationException[Validation Failed: 1: no requests added;]","status":500}

In terminal using curl -XPOST localhost:9200/_bulk -d '{ "index" : {"_index":"test","_type":"one","_id":"1"}}\n{"name":"test","id":"1" }\n' got the same error, and that's ok:
curl -XPOST localhost:9200/_bulk -d '{ "index" : {"_index":"test","_type":"one","_id":"1"}}
{"name":"test","id":"1" }
'
Right now i have to build request body by my own, the guide (http://www.elasticsearch.org/guide/reference/api/bulk/) said use newline character \n, that'sexactly what i did, and it seems wrong, i wanna know how to describe newline character in request body.

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.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.

I forgot the final newline character in my code, that's why it's fail, and
obviously curl treat "\n" as character "" and "n", i figured out by
changing the es source code and print out the request byte[] and compare
the output.

I am misguided by curl and ignore my own mistake, waist a lot of time,
shame on me.

On Tuesday, June 25, 2013 2:00:05 PM UTC+8, David Pilato wrote:

You need to send in Bulk a real Line return character (which we represent
with \n).
You can create a file with proper line endings and then use it from curl.

$ cat requests
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
$ curl -s -XPOST localhost:9200/_bulk --data-binary @requests; echo
{"took":7,"items":[{"create":{"_index":"test","_type":"type1","_id":"1","_version":1,"ok":true}}]}

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

Le 25 juin 2013 à 05:36, mega <yuhg...@gmail.com <javascript:>> a écrit :

In my project i need to making bulk requests to elasticsearch, that means
making http post requests in program instead of using curl.

I already set content-type to json, and the body is like: '{ "index" :
{"_index":"test","_type":"one","_id":"1"}}\n{"name":"test","id":"1" }\n',
and got a error: {"error":"ActionRequestValidationException[Validation
Failed: 1: no requests added;]","status":500}

In terminal using curl -XPOST localhost:9200/_bulk -d '{ "index" :
{"_index":"test","_type":"one","_id":"1"}}\n{"name":"test","id":"1" }\n'
got the same error, and that's ok:
curl -XPOST localhost:9200/_bulk -d '{ "index" :
{"_index":"test","_type":"one","_id":"1"}}
{"name":"test","id":"1" }
'
Right now i have to build request body by my own, the guide (
http://www.elasticsearch.org/guide/reference/api/bulk/) said use newline
character \n, that'sexactly what i did, and it seems wrong, i wanna know
how to describe newline character in request body.

--
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 elasticsearc...@googlegroups.com <javascript:>.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.