# Indexing nested documents

**URL:** <https://discuss.elastic.co/t/indexing-nested-documents/11760>\
**Category:** Elasticsearch\
**Created:** [May 1, 2013, 12:14am UTC](https://discuss.elastic.co/t/indexing-nested-documents/11760 "2013-05-01T00:14:59Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [May 1, 2013, 12:14am UTC](https://discuss.elastic.co/t/indexing-nested-documents/11760/1 "2013-05-01T00:14:59Z")

</div>

Perhaps I am missing something in the Java API, but how can I index a  
nested document that is created from either another XContentBuilder or  
other JSON creator such as Jackson?

From what I can tell, the value(...) methods do not support passing in  
JSON/XContentBuilder. My current workaround is to convert the JSON into a  
Map\<String, Object). Is there a simpler solution?

Cheers,

Ivan

--  
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:** [May 2, 2013, 6:53am UTC](https://discuss.elastic.co/t/indexing-nested-documents/11760/2 "2013-05-02T06:53:20Z")

</div>

Hey Ivan,

without looking at the source and guessing wild at the early morning, what  
about using bytes() method of the content builder? I think the value()  
method can handle that...

--Alex

On Wed, May 1, 2013 at 2:14 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> Perhaps I am missing something in the Java API, but how can I index a  
> nested document that is created from either another XContentBuilder or  
> other JSON creator such as Jackson?
> 
> From what I can tell, the value(...) methods do not support passing in  
> JSON/XContentBuilder. My current workaround is to convert the JSON into a  
> Map\<String, Object). Is there a simpler solution?
> 
> Cheers,
> 
> Ivan
> 
> --  
> 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:** [May 2, 2013, 8:13am UTC](https://discuss.elastic.co/t/indexing-nested-documents/11760/3 "2013-05-02T08:13:40Z")

</div>

There are the rawField() methods for streaming an XContentBuilder into  
another.

Jörg

Am 02.05.13 08:53, schrieb Alexander Reelsen:

> Hey Ivan,
> 
> without looking at the source and guessing wild at the early morning,  
> what about using bytes() method of the content builder? I think the  
> value() method can handle that...
> 
> --Alex
> 
> On Wed, May 1, 2013 at 2:14 AM, Ivan Brusic \<[ivan@brusic.com](mailto:ivan@brusic.com)  
> [mailto:ivan@brusic.com](mailto:ivan@brusic.com)\> wrote:
> 
> ```
> Perhaps I am missing something in the Java API, but how can I
> index a nested document that is created from either another
> XContentBuilder or other JSON creator such as Jackson?
> 
> From what I can tell, the value(...) methods do not support
> passing in JSON/XContentBuilder. My current workaround is to
> convert the JSON into a Map<String, Object). Is there a simpler
> solution?
> 
> Cheers,
> 
> Ivan
> 
> ```

--  
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:** [May 2, 2013, 3:48pm UTC](https://discuss.elastic.co/t/indexing-nested-documents/11760/4 "2013-05-02T15:48:42Z")

</div>

Alexander, I thought about that, but my assumption is that it would be  
treated no differently than indexing a String.

Jörg, nested documents are not indexed under a new field, but as values  
under an array. Need a rawValue() method.

Will explore the code more next week.

Ivan

On Wed, May 1, 2013 at 11:53 PM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey Ivan,
> 
> without looking at the source and guessing wild at the early morning, what  
> about using bytes() method of the content builder? I think the value()  
> method can handle that...
> 
> --Alex
> 
> On Wed, May 1, 2013 at 2:14 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:
> 
> > Perhaps I am missing something in the Java API, but how can I index a  
> > nested document that is created from either another XContentBuilder or  
> > other JSON creator such as Jackson?
> > 
> > From what I can tell, the value(...) methods do not support passing in  
> > JSON/XContentBuilder. My current workaround is to convert the JSON into a  
> > Map\<String, Object). Is there a simpler solution?
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > --  
> > 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).

--  
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:** [May 6, 2013, 4:48pm UTC](https://discuss.elastic.co/t/indexing-nested-documents/11760/5 "2013-05-06T16:48:49Z")

</div>

Back at work after being out last week. As predicted, neither indexing as  
bytes nor rawField work with nested documents. Will continue using my  
workaround of converting to a Map.

Surely I can't be the first one to index sub-builders.

--

Ivan

On Thu, May 2, 2013 at 8:48 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> Alexander, I thought about that, but my assumption is that it would be  
> treated no differently than indexing a String.
> 
> Jörg, nested documents are not indexed under a new field, but as values  
> under an array. Need a rawValue() method.
> 
> Will explore the code more next week.
> 
> Ivan
> 
> On Wed, May 1, 2013 at 11:53 PM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de)wrote:
> 
> > Hey Ivan,
> > 
> > without looking at the source and guessing wild at the early morning,  
> > what about using bytes() method of the content builder? I think the value()  
> > method can handle that...
> > 
> > --Alex
> > 
> > On Wed, May 1, 2013 at 2:14 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:
> > 
> > > Perhaps I am missing something in the Java API, but how can I index a  
> > > nested document that is created from either another XContentBuilder or  
> > > other JSON creator such as Jackson?
> > > 
> > > From what I can tell, the value(...) methods do not support passing in  
> > > JSON/XContentBuilder. My current workaround is to convert the JSON into a  
> > > Map\<String, Object). Is there a simpler solution?
> > > 
> > > Cheers,
> > > 
> > > Ivan
> > > 
> > > --  
> > > 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).

--  
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:38am UTC](https://discuss.elastic.co/t/indexing-nested-documents/11760/6 "2017-07-06T02:38:05Z")

</div>


