# Reading \_source field

**URL:** <https://discuss.elastic.co/t/reading--source-field/12761>\
**Category:** Elasticsearch\
**Created:** [July 11, 2013, 5:40pm UTC](https://discuss.elastic.co/t/reading--source-field/12761 "2013-07-11T17:40:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arni\_Sumarlidason](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arni_sumarlidason/32/2229_2.png) [@Arni\_Sumarlidason](https://discuss.elastic.co/u/Arni_Sumarlidason)\
**Post date:** [July 11, 2013, 5:40pm UTC](https://discuss.elastic.co/t/reading--source-field/12761/1 "2013-07-11T17:40:30Z")

</div>

Good afternoon,

I did some searching on the boards here, and I did find someone had touched  
on this subject before[1], but maybe i am still missing something because  
my results were not good.

I am using apache's lucene api to read the documents generated by elastic  
search, I am able to iterate documents and extract the \_source field... i'm  
trying to convert this back to a string. According to documentation[2] the  
field can be compressed with LZF, I checked our config and it seems we left  
this default -\> disabled.

I am getting only junk strings. ☹ Any help would be appreciated.

BytesRef bRef = doc.getBinaryValue("\_source");  
byte[] decodedBytes = decoder.decode(bRef.bytes);  
String tmp = new String(decodedBytes, ("UTF-8");  
[1]  
[https://groups.google.com/forum/?fromgroups#!searchin/elasticsearch/\_source$20decode/elasticsearch/pWfgxKF0GWc/GgcF1\_OUEXEJ](https://groups.google.com/forum/?fromgroups#!searchin/elasticsearch/_source%2420decode/elasticsearch/pWfgxKF0GWc/GgcF1_OUEXEJ)  
[2] [http://www.elasticsearch.org/guide/reference/mapping/source-field/](http://www.elasticsearch.org/guide/reference/mapping/source-field/)

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 11, 2013, 5:59pm UTC](https://discuss.elastic.co/t/reading--source-field/12761/2 "2013-07-11T17:59:52Z")

</div>

Never looked into it, but try looking at some of the logic used in  
SourceFieldMapper and its relevant tests:

[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java)

[https://github.com/elasticsearch/elasticsearch/tree/master/src/test/java/org/elasticsearch/test/unit/index/mapper/source](https://github.com/elasticsearch/elasticsearch/tree/master/src/test/java/org/elasticsearch/test/unit/index/mapper/source)

The unit tests are often useful to figure out how the code is constructed.  
A static helper class called CompressorFactory is used. Maybe that would  
have some clue.

--  
Ivan

On Thu, Jul 11, 2013 at 10:40 AM, Arni Sumarlidason  
[sumarlidason@gmail.com](mailto:sumarlidason@gmail.com)wrote:

> Good afternoon,
> 
> I did some searching on the boards here, and I did find someone had  
> touched on this subject before[1], but maybe i am still missing something  
> because my results were not good.
> 
> I am using apache's lucene api to read the documents generated by elastic  
> search, I am able to iterate documents and extract the \_source field... i'm  
> trying to convert this back to a string. According to documentation[2] the  
> field can be compressed with LZF, I checked our config and it seems we left  
> this default -\> disabled.
> 
> I am getting only junk strings. ☹ Any help would be appreciated.
> 
> BytesRef bRef = doc.getBinaryValue("\_source");  
> byte decodedBytes = decoder.decode(bRef.bytes);  
> String tmp = new String(decodedBytes, ("UTF-8");  
> [1]  
> [Redirecting to Google Groups](https://groups.google.com/forum/?fromgroups#!searchin/elasticsearch/_source$20decode/elasticsearch/pWfgxKF0GWc/GgcF1_OUEXEJ)  
> [2] [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/source-field/)
> 
> --  
> 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:** ![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:26am UTC](https://discuss.elastic.co/t/reading--source-field/12761/3 "2017-07-06T02:26:56Z")

</div>


