# rawField in XContentBuilder

**URL:** <https://discuss.elastic.co/t/rawfield-in-xcontentbuilder/10233>\
**Category:** Elasticsearch\
**Created:** [January 5, 2013, 6:56am UTC](https://discuss.elastic.co/t/rawfield-in-xcontentbuilder/10233 "2013-01-05T06:56:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene\_Strokin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugene_strokin/32/1238_2.png) [@Eugene\_Strokin](https://discuss.elastic.co/u/Eugene_Strokin)\
**Post date:** [January 5, 2013, 6:56am UTC](https://discuss.elastic.co/t/rawfield-in-xcontentbuilder/10233/1 "2013-01-05T06:56:37Z")

</div>

I have a string which is data in JSON format, but not in fixed structure. I  
want to index it as a part of my document.  
So, I'd have such structure:  
{  
"data":{ **HERE is the CONTENT from the STRING with DYNAMIC STRUCTURE** },  
"mySecondProp":"Some Value, etc.."  
}  
I'm building XContentBuilder for indexing such document. I suspect that I  
could use:

rawField\<[http://www.thelastcitadel.com/lab/elasticsearch/javadoc/org/elasticsearch/common/xcontent/builder/XContentBuilder.html#rawField](http://www.thelastcitadel.com/lab/elasticsearch/javadoc/org/elasticsearch/common/xcontent/builder/XContentBuilder.html#rawField)(java.lang.String,  
byte[])\>(java.lang.String fieldName, byte[] content)

First of all, I need a confirmation that I'm in the right direction, since  
I couldn't find description of that method.  
And another question, should this work Ok?

rawField\<[http://www.thelastcitadel.com/lab/elasticsearch/javadoc/org/elasticsearch/common/xcontent/builder/XContentBuilder.html#rawField](http://www.thelastcitadel.com/lab/elasticsearch/javadoc/org/elasticsearch/common/xcontent/builder/XContentBuilder.html#rawField)(java.lang.String,  
byte[])\>("data", myJsonString.getBytes());

Thank you,  
Eugene

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 8, 2013, 2:41am UTC](https://discuss.elastic.co/t/rawfield-in-xcontentbuilder/10233/2 "2013-01-08T02:41:38Z")

</div>

I think you are on the right track. As long as your XContentBuilder is  
building JSON and your string is has correct JSON format it should work.

On Saturday, January 5, 2013 1:56:37 AM UTC-5, Eugene Strokin wrote:

> I have a string which is data in JSON format, but not in fixed structure.  
> I want to index it as a part of my document.  
> So, I'd have such structure:  
> {  
> "data":{ **HERE is the CONTENT from the STRING with DYNAMIC STRUCTURE** },  
> "mySecondProp":"Some Value, etc.."  
> }  
> I'm building XContentBuilder for indexing such document. I suspect that I  
> could use:
> 
> rawField[http://www.thelastcitadel.com/lab/elasticsearch/javadoc/org/elasticsearch/common/xcontent/builder/XContentBuilder.html#rawField(java.lang.String,+byte[])](http://www.thelastcitadel.com/lab/elasticsearch/javadoc/org/elasticsearch/common/xcontent/builder/XContentBuilder.html#rawField(java.lang.String,+byte%5B%5D))(java.lang.String  
> fieldName, byte content)
> 
> First of all, I need a confirmation that I'm in the right direction, since  
> I couldn't find description of that method.  
> And another question, should this work Ok?
> 
> rawField[http://www.thelastcitadel.com/lab/elasticsearch/javadoc/org/elasticsearch/common/xcontent/builder/XContentBuilder.html#rawField(java.lang.String,+byte[])](http://www.thelastcitadel.com/lab/elasticsearch/javadoc/org/elasticsearch/common/xcontent/builder/XContentBuilder.html#rawField(java.lang.String,+byte%5B%5D))("data",  
> myJsonString.getBytes());
> 
> Thank you,  
> Eugene

--

---

<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:57am UTC](https://discuss.elastic.co/t/rawfield-in-xcontentbuilder/10233/3 "2017-07-06T02:57:29Z")

</div>


