# Nested documents

**URL:** <https://discuss.elastic.co/t/nested-documents/11272>\
**Category:** Elasticsearch\
**Created:** [March 23, 2013, 2:36am UTC](https://discuss.elastic.co/t/nested-documents/11272 "2013-03-23T02:36:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![troy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/troy/32/2547_2.png) [@troy](https://discuss.elastic.co/u/troy)\
**Post date:** [March 23, 2013, 2:36am UTC](https://discuss.elastic.co/t/nested-documents/11272/1 "2013-03-23T02:36:52Z")

</div>

I'm writing an asset management application. It lets users store arbitrary  
asset attributes by adding an html control such as a text field, select  
menu, etc. to the asset. A JSON representation of the attribute then  
becomes part of the asset JSON document stored in couchdb. An asset has the  
following structure in couchdb:

{  
"\_id": "9399fb27448b1e5dfdca0181620418d4",  
"\_rev": "12-fa50eae8b50f745f9852e9fab30ef5d9",  
"type": "asset",  
"attributes": [  
{  
"id": "9399fb27448b1e5dfdca01816203d609",  
"type": "text",  
"heading": "Brand",  
"data": "",  
"requiredBySystem": true  
},  
{  
"id": "9399fb27448b1e5dfdca01816203e68e",  
"type": "userSelectMenu",  
"heading": "Assigned To",  
"data": "",  
"requiredBySystem": true  
},  
{  
"id": "9399fb27448b1e5dfdca01816203e9c9",  
"type": "categories",  
"heading": "Categories",  
"data": [  
"0d7e6233e5f48b4f55c5376bf00b1be5",  
"0d7e6233e5f48b4f55c5376bf00d94cf"  
],  
"requiredBySystem": true  
},  
{  
"id": "9399fb27448b1e5dfdca01816207uy5a",  
"type": "radio",  
"heading": "Radio Buttons",  
"data": [  
{  
"text": "Button 1",  
"checked": false  
},  
{  
"text": "Button 2",  
"checked": true  
}  
],  
"requiredBySystem": true  
},  
{  
"id": "9399fb27448b1e5dfdca01816205tgh6",  
"type": "checkboxes",  
"heading": "Checkboxes",  
"data": [  
{  
"text": "Box 1",  
"checked": false  
},  
{  
"text": "Box 2",  
"checked": true  
}  
],  
"requiredBySystem": true  
},  
{  
"id": "9399fb27448b1e5dfdca0181620k81gt",  
"type": "select",  
"heading": "Select Menu",  
"data": [  
{  
"text": "Option 1",  
"checked": false  
},  
{  
"text": "Option 2",  
"checked": true  
}  
],  
"requiredBySystem": true  
}  
]  
}

I'm not sure if putting attributes in an array is the best way to allow  
searching for an asset based on an attribute value. Would it be better to  
attach the attribute directly to the asset as a property? I'm experimenting  
now in elasticsearch. If I try and store the document as is, elasticsearch  
returns an error:

"error" : "MapperParsingException[Failed to parse [attributes.data]];  
nested: ElasticSearchIllegalArgumentException[unknown property [text]]; "

I"m using the following mapping:

{  
"settings" : {  
"analysis" : {  
"analyzer" : {  
"str\_filtered\_search\_analyzer" : {  
"tokenizer" : "keyword",  
"filter" : ["lowercase"]  
},  
"str\_prefix\_analyzer" : {  
"tokenizer" : "keyword",  
"filter" : ["lowercase", "prefix"]  
},  
"str\_substring\_analyzer" : {  
"tokenizer" : "keyword",  
"filter" : ["lowercase", "substring"]  
}  
},  
"filter" : {  
"prefix" : {  
"type" : "edgeNGram",  
"min\_gram" : 2,  
"max\_gram" : 24,  
"side": "front"  
},  
"substring" : {  
"type" : "nGram",  
"min\_gram" : 2,  
"max\_gram" : 24  
}  
}  
}  
},  
"mappings" : {  
"asset" : {  
"properties" : {  
"\_id": {  
"type" : "string",  
"index" : "not\_analyzed"  
},  
"\_rev": {  
"type" : "string",  
"index" : "not\_analyzed"  
},  
"type": {  
"type" : "string",  
"index" : "not\_analyzed"  
},  
"attributes": {  
"type" : "nested"  
}  
}  
}  
}  
}

Any idea what I'm doing wrong here?

Thanks,

Troy

--  
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:45am UTC](https://discuss.elastic.co/t/nested-documents/11272/2 "2017-07-06T02:45:01Z")

</div>


