# Sending index requests via the rabbitmq river

**URL:** <https://discuss.elastic.co/t/sending-index-requests-via-the-rabbitmq-river/7425>\
**Category:** Elasticsearch\
**Created:** [April 20, 2012, 8:46pm UTC](https://discuss.elastic.co/t/sending-index-requests-via-the-rabbitmq-river/7425 "2012-04-20T20:46:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![benny\_sadeh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benny_sadeh/32/2797_2.png) [@benny\_sadeh](https://discuss.elastic.co/u/benny_sadeh)\
**Post date:** [April 20, 2012, 8:46pm UTC](https://discuss.elastic.co/t/sending-index-requests-via-the-rabbitmq-river/7425/1 "2012-04-20T20:46:47Z")

</div>

hi group,

I have a problem understanding how to transform an IndexRequest to the Bulk  
API format.  
I would expect to find a method on IndexRequest or IndexRequestBuilder to  
perform such transformation for me, but haven't found such.

alas, looking at the explanation, it says it expects the following JSON  
structure:

action\_and\_meta\_data\n  
optional\_source\n  
....

and the example given is:

{ "index" : { "\_index" : "test", "\_type" : "type1", "\_id" : "1" } }  
{ "field1" : "value1" }  
{ "delete" : { "\_index" : "test", "\_type" : "type1", "\_id" : "2" } }  
{ "create" : { "\_index" : "test", "\_type" : "type1", "\_id" : "3" } }  
{ "field1" : "value3" }

which I understand to correspond to:

[index] action\_and\_meta\_data  
source  
[delete] action\_and\_meta\_data  
[create] action\_and\_meta\_data  
source

if that's so, than I kind of get it, but kind of not knowing how  
to programmatically convert an IndexRequest to such form.

any hints at how to go about would be much appreciated ...  
thanks in advance,  
Benny

---

<div class="post-metadata">

**Author:** ![drewr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drewr/32/7803_2.png) [@drewr](https://discuss.elastic.co/u/drewr)\
**Post date:** [April 21, 2012, 3:26am UTC](https://discuss.elastic.co/t/sending-index-requests-via-the-rabbitmq-river/7425/2 "2012-04-21T03:26:56Z")

</div>

Benny Sadeh wrote:

> hi group,
> 
> I have a problem understanding how to transform an IndexRequest to the  
> Bulk API format.  
> I would expect to find a method on IndexRequest or IndexRequestBuilder  
> to perform such transformation for me, but haven't found such.

[...]

> if that's so, than I kind of get it, but kind of not knowing how  
> to programmatically convert an IndexRequest to such form.
> 
> any hints at how to go about would be much appreciated ...

Logically a bulk request is a collection of other types of requests.  
There are add() methods on BulkRequest that reflect this.

[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java#L63](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java#L63)

-Drew

---

<div class="post-metadata">

**Author:** ![drewr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drewr/32/7803_2.png) [@drewr](https://discuss.elastic.co/u/drewr)\
**Post date:** [April 21, 2012, 3:40am UTC](https://discuss.elastic.co/t/sending-index-requests-via-the-rabbitmq-river/7425/3 "2012-04-21T03:40:52Z")

</div>

Drew Raines wrote:

> Benny Sadeh wrote:
> 
> > hi group,
> > 
> > I have a problem understanding how to transform an IndexRequest to the  
> > Bulk API format.  
> > I would expect to find a method on IndexRequest or IndexRequestBuilder  
> > to perform such transformation for me, but haven't found such.
> 
> [...]
> 
> > if that's so, than I kind of get it, but kind of not knowing how  
> > to programmatically convert an IndexRequest to such form.
> > 
> > any hints at how to go about would be much appreciated ...
> 
> Logically a bulk request is a collection of other types of requests.  
> There are add() methods on BulkRequest that reflect this.
> 
> [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java#L63](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java#L63)

I think I read your message too quickly. IIUC, you're asking if  
IndexRequest can output a string of text suitable for injection into  
a rabbit queue. It cannot. You should create lines of json using  
whatever mechanism you like and then use those to form the payload of  
your rabbit msg. If you'd like to use the ES lib to do that, take a  
look at XContentFactory.jsonBuilder().

-Drew

---

<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, 3:31am UTC](https://discuss.elastic.co/t/sending-index-requests-via-the-rabbitmq-river/7425/4 "2017-07-06T03:31:37Z")

</div>


