In the source code of Elasticsearch, how it get the body of "_bulk request"?

In the source code of Elasticsearch, how it get the body of _bulk request?

Such as the following request:

curl -i -XPOST 'http://localhost:9200/_bulk/?pretty' -d '
{ "delete" : {"_index" : "test", "_type" : "employee", "_id" : "3" } }
{ "create" : {"_index" : "test", "_type" : "employee", "_id" : "3"} }
{ "first_name" : "Reka", "last_name" : "Downey", "age" : 22, "about" : "I like new things!", "interests" : ["sport", "read"] }
{ "index" : {"_index" : "test", "_type" : "employee"} }
{ "first_name" : "Lily", "last_name" : "Smith", "age" : 23, "about" : "I like swimming!", "interests" : ["swim"] }
{ "update" : {"_index" : "test", "_type" : "employee", "_id" : "3"} }
{ "docs" : {"age" : 24} }'

now the question is how Elasticsearch get the data in this request, which content is

{ "delete" : {"_index" : "test", "_type" : "employee", "_id" : "3" } }
{ "create" : {"_index" : "test", "_type" : "employee", "_id" : "3"} }
{ "first_name" : "Reka", "last_name" : "Downey", "age" : 22, "about" : "I like new things!", "interests" : ["sport", "read"] }
{ "index" : {"_index" : "test", "_type" : "employee"} }
{ "first_name" : "Lily", "last_name" : "Smith", "age" : 23, "about" : "I like swimming!", "interests" : ["swim"] }
{ "update" : {"_index" : "test", "_type" : "employee", "_id" : "3"} }
{ "docs" : {"age" : 24} }

the version of Elasticsearch is 2.3.1.

we know that in the org.elasticsearch.http.netty.HttpRequestHandler#messageReceived method, we got the HttpRequest object; so now I want to know how to get the content through the HttpRequest object?

Request your kind help!
Thanks!
Reka!

If you want to implement a new rest endpoint you'd register a new rest action. In a plugin you'd extend BaseRestHandler and make an onModule(RestModule) method and on your plugin and call addRestAction. You can get the body of the post with request.content(). For now the usual way to parse it is with XContentFactory.xContent(request.content()).createParser(request.content()).

1 Like