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

Just looking at the documentation for the High level Rest Client.

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 ?

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

1 Like

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