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

**URL:** <https://discuss.elastic.co/t/in-the-source-code-of-elasticsearch-how-it-get-the-body-of--bulk-request/55582>\
**Category:** Elasticsearch\
**Created:** [July 15, 2016, 1:36am UTC](https://discuss.elastic.co/t/in-the-source-code-of-elasticsearch-how-it-get-the-body-of--bulk-request/55582 "2016-07-15T01:36:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rekadowney](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rekadowney/32/106313_2.png) [@rekadowney](https://discuss.elastic.co/u/rekadowney)\
**Post date:** [July 15, 2016, 1:36am UTC](https://discuss.elastic.co/t/in-the-source-code-of-elasticsearch-how-it-get-the-body-of--bulk-request/55582/1 "2016-07-15T01:36:21Z")

</div>

## 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!

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [July 15, 2016, 12:03pm UTC](https://discuss.elastic.co/t/in-the-source-code-of-elasticsearch-how-it-get-the-body-of--bulk-request/55582/2 "2016-07-15T12:03:16Z")

</div>

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())`.

---

<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 5, 2017, 10:35pm UTC](https://discuss.elastic.co/t/in-the-source-code-of-elasticsearch-how-it-get-the-body-of--bulk-request/55582/3 "2017-07-05T22:35:10Z")

</div>


