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:
"mappings" : {
"asset" : {
"properties" : {
"_id": {
"type" : "string",
"index" : "not_analyzed"
},
"_rev": {
"type" : "string",
"index" : "not_analyzed"
},
"type": {
"type" : "string",
"index" : "not_analyzed"
},
"attributes": {
"properties" : {
"id" : {
"type" : "string"
},
"type" : {
"type" : "string",
"index" : "not_analyzed"
},
"heading" : {
"type" : "string"
},
"data" : {
"type" : "string"
}
}
}
}
}
}
Not sure where I'm going wrong here. Thanks for your help!
Troy