# Is there a best way to provide the document source in the High Level Rest Client?

**URL:** <https://discuss.elastic.co/t/is-there-a-best-way-to-provide-the-document-source-in-the-high-level-rest-client/104529>\
**Category:** Elasticsearch\
**Created:** [October 19, 2017, 9:31am UTC](https://discuss.elastic.co/t/is-there-a-best-way-to-provide-the-document-source-in-the-high-level-rest-client/104529 "2017-10-19T09:31:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gringogordo](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gringogordo](https://discuss.elastic.co/u/gringogordo)\
**Post date:** [October 19, 2017, 9:31am UTC](https://discuss.elastic.co/t/is-there-a-best-way-to-provide-the-document-source-in-the-high-level-rest-client/104529/1 "2017-10-19T09:31:31Z")

</div>

Just looking at the documentation for the High level [Rest Client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-index.html).

Probably a trivial question (as I assume all 3 methods are doing largely the same thing), but the document offers 3 different ways to build documents to add to an index

1. Document source provided as a Map which gets automatically converted to JSON format
2. Document source provided as an XContentBuilder object, the Elasticsearch built-in helpers to generate JSON content
3. Document source provided as Object key-pairs, which gets converted to JSON format

Aesthetically I like the look of XContentBuilder but as I'm starting from scratch I just wondered if there were any benchmarks comparing the 3 methods or recommendations ?

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [October 27, 2017, 8:00am UTC](https://discuss.elastic.co/t/is-there-a-best-way-to-provide-the-document-source-in-the-high-level-rest-client/104529/2 "2017-10-27T08:00:00Z")

</div>

Hi,  
good question. The internal representation of the source in the IndexRequest is a byte array, meaning that whatever you provide we will convert it to a json byte array. I would say that XContentBuilder is the most performant way, as you are effectively already writing JSON using jackson (under the hood), while Map or pair of objects (which goes through a map anyway) require conversion to json first. We do not have benchmarks on this though.

Cheers  
Luca

---

<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:** [November 24, 2017, 8:10am UTC](https://discuss.elastic.co/t/is-there-a-best-way-to-provide-the-document-source-in-the-high-level-rest-client/104529/3 "2017-11-24T08:10:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
