# Sending XContentBuilder over the wire

**URL:** <https://discuss.elastic.co/t/sending-xcontentbuilder-over-the-wire/12304>\
**Category:** Elasticsearch\
**Created:** [June 6, 2013, 6:58pm UTC](https://discuss.elastic.co/t/sending-xcontentbuilder-over-the-wire/12304 "2013-06-06T18:58:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinod\_eligeti](https://avatars.discourse-cdn.com/v4/letter/v/c4cdca/32.png) [@vinod\_eligeti](https://discuss.elastic.co/u/vinod_eligeti)\
**Post date:** [June 6, 2013, 6:58pm UTC](https://discuss.elastic.co/t/sending-xcontentbuilder-over-the-wire/12304/1 "2013-06-06T18:58:44Z")

</div>

Hi,

I am trying to serialize the XContentBuilder objects over the write from  
the client and regenerate at the server side. At the server side I am  
trying  
to rebuild the XContentBuilder and bulk seed into the ES server. However I  
am not aware of any API where one can rebuild the XContentBuilder from  
InputStream.

// Client side code

sendJSONObjects()  
{  
ByteArrayOutputStream bos = new ByteArrayOutputStream();

XContentBuilder json1 = XContentFactory.jsonBuilder(bos)  
.startObject()  
.field("nodeId", 1)  
.endObject()  
.startObject() // second  
object  
.field("nodeId", 2)  
.endObject();

json1.flush();

bos.close();

byte[] bytes = compressBytes(bos.toByteArray());

```
           SeedData data = new SeedData();
           data.setObjects(bytes);
           // .... set application data on seed data

         // transfer data

```

}

// Server side

readJSONObjects(SeedData data)  
{  
bytes [] jsonObjectBytes = decompress(data.getObjects());

// bulk insert into ES server  
}

Now how do i create XContentBuilder objects from jsonObjectBytes so that i  
can do bulk insert??

thanks

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 7, 2013, 7:38am UTC](https://discuss.elastic.co/t/sending-xcontentbuilder-over-the-wire/12304/2 "2013-06-07T07:38:46Z")

</div>

Hey,

As the XContentBuilder is simply a builder pattern and not a data structure  
for serializing, I am not sure you approach works (havent peeked at the  
source though).  
Alternatively you could use the XContentParser  
Map\<String, Object\> foo =  
JsonXContent.jsonXContent.createParser(is).mapAndClose()

Hope this helps (otherwise I most likely got your question wrong),

--Alex

On Thu, Jun 6, 2013 at 8:58 PM, vinod eligeti [veligeti999@gmail.com](mailto:veligeti999@gmail.com) wrote:

> Hi,
> 
> I am trying to serialize the XContentBuilder objects over the write from  
> the client and regenerate at the server side. At the server side I am  
> trying  
> to rebuild the XContentBuilder and bulk seed into the ES server. However I  
> am not aware of any API where one can rebuild the XContentBuilder from  
> InputStream.
> 
> // Client side code
> 
> sendJSONObjects()  
> {  
> ByteArrayOutputStream bos = new ByteArrayOutputStream();
> 
> XContentBuilder json1 = XContentFactory.jsonBuilder(bos)  
> .startObject()  
> .field("nodeId", 1)  
> .endObject()  
> .startObject() // second  
> object  
> .field("nodeId", 2)  
> .endObject();
> 
> json1.flush();
> 
> bos.close();
> 
> byte bytes = compressBytes(bos.toByteArray());
> 
> ```
> SeedData data = new SeedData();
> data.setObjects(bytes);
> // .... set application data on seed data
> 
> // transfer data
> 
> ```
> 
> }
> 
> // Server side
> 
> readJSONObjects(SeedData data)  
> {  
> bytes jsonObjectBytes = decompress(data.getObjects());
> 
> // bulk insert into ES server  
> }
> 
> Now how do i create XContentBuilder objects from jsonObjectBytes so that i  
> can do bulk insert??
> 
> thanks
> 
> --  
> 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).  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [June 7, 2013, 7:50am UTC](https://discuss.elastic.co/t/sending-xcontentbuilder-over-the-wire/12304/3 "2013-06-07T07:50:29Z")

</div>

You know ES provides already an API for that with the transport client  
(I call it the Java Transport API?)

Jörg

Am 06.06.2013 20:58, schrieb vinod eligeti:

> I am trying to serialize the XContentBuilder objects over the write  
> from the client and regenerate at the server side.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![vinod\_eligeti](https://avatars.discourse-cdn.com/v4/letter/v/c4cdca/32.png) [@vinod\_eligeti](https://discuss.elastic.co/u/vinod_eligeti)\
**Post date:** [June 7, 2013, 3:37pm UTC](https://discuss.elastic.co/t/sending-xcontentbuilder-over-the-wire/12304/4 "2013-06-07T15:37:55Z")

</div>

Jorg,

Transport API directly push docs into the ES servers however, I need to do  
some business logic before I push into the ES servers.

On Fri, Jun 7, 2013 at 12:50 AM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:

> You know ES provides already an API for that with the transport client (I  
> call it the Java Transport API?)
> 
> Jörg
> 
> Am 06.06.2013 20:58, schrieb vinod eligeti:
> 
> > I am trying to serialize the XContentBuilder objects over the write from  
> > the client and regenerate at the server side.
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> topic/elasticsearch/-\*\*Yr4q3bvBeM/unsubscribe?hl=en-\*\*US[https://groups.google.com/d/topic/elasticsearch/-Yr4q3bvBeM/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/-Yr4q3bvBeM/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> elasticsearch+unsubscribe@\*\*[googlegroups.com](http://googlegroups.com)[elasticsearch%2Bunsubscribe@googlegroups.com](mailto:elasticsearch%2Bunsubscribe@googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[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).  
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:32am UTC](https://discuss.elastic.co/t/sending-xcontentbuilder-over-the-wire/12304/5 "2017-07-06T02:32:17Z")

</div>


