# Creating sub-objects and nested objects in Elasticsearch plugin

**URL:** <https://discuss.elastic.co/t/creating-sub-objects-and-nested-objects-in-elasticsearch-plugin/18142>\
**Category:** Elasticsearch\
**Created:** [June 16, 2014, 9:06pm UTC](https://discuss.elastic.co/t/creating-sub-objects-and-nested-objects-in-elasticsearch-plugin/18142 "2014-06-16T21:06:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tnadeau](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tnadeau/32/26195_2.png) [@tnadeau](https://discuss.elastic.co/u/tnadeau)\
**Post date:** [June 16, 2014, 9:06pm UTC](https://discuss.elastic.co/t/creating-sub-objects-and-nested-objects-in-elasticsearch-plugin/18142/1 "2014-06-16T21:06:11Z")

</div>

Hello. I'm creating an Elasticsearch plugin that creates a new field type  
(similarly to how the elastic-mapper-attachments plugin does here  
[https://github.com/elasticsearch/elasticsearch-mapper-attachments/blob/master/src/main/java/org/elasticsearch/index/mapper/attachment/AttachmentMapper.java](https://github.com/elasticsearch/elasticsearch-mapper-attachments/blob/master/src/main/java/org/elasticsearch/index/mapper/attachment/AttachmentMapper.java)).  
However, I need to store sub-objects and several instances of a nested  
object. For instance, for a type mapping like this:

{  
"my\_elastic\_type": {  
"properties": {  
"my\_field": {  
"type": "my\_new\_field\_type",  
"stuff": {  
"reference": {  
"index": "myIndex",  
"type": "ref",  
}  
},  
"stuff2": {  
"reference": {  
"index": "myOtherIndex",  
"type": "ref",  
}  
}  
}  
}  
}  
}

and indexing a document like this:  
{  
"my\_field": "text here"  
}

I would like the store the equivalent to the following in the index:  
{  
"stuff": {  
"calcField1": "foo",  
"calcField2": "baz",  
"nestedObjs": [  
{  
"nestedField1": "info",  
"nestedField2": "data"  
},  
{  
"nestedField1": "info",  
"nestedField2": "data"  
}  
]  
},  
"stuff2": {  
"calcField1": "foo2",  
"calcField2": "baz2",  
"nestedObjs": [  
{  
"nestedField1": "info2",  
"nestedField2": "data2"  
},  
{  
"nestedField1": "info2",  
"nestedField2": "data2"  
}  
]  
},  
}

I'm having a lot of trouble figuring out how to add non-simple fields in my  
plugin. I can't find any documentation of how to develop an Elasticsearch  
plugin.

Thanks for any help.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9854898a-93ab-46f0-a52c-4dc6070aa35b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9854898a-93ab-46f0-a52c-4dc6070aa35b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:22am UTC](https://discuss.elastic.co/t/creating-sub-objects-and-nested-objects-in-elasticsearch-plugin/18142/2 "2017-07-06T01:22:00Z")

</div>


