Modeling Objects That Have Many Properties

Hello,

I have a situation where I want to understand the best way to model this data in ES. I have the following data

Object -> Has Many -> Properties

where a

Property -> is a -> Name (String), and a Value( one of -> Boolean, Integer, Double, String, Long)

and the Object is the container of the properties via the "the-properties" field below. It also has a simple name field "the-name" as a general object identifier.

So essentially I have an object that has many properties where each property can have a name, and a value but the value can be one of many types as noted above. So this is a bit dynamic in nature as it relates to the properties value "type".

One way to establish a mapping is as follows, but it seems a bit hacky. Is there a better way?

curl -XPUT 'http://localhost:9200/bo-objects/_mapping/bo' -d '{
"bo": {
"properties": {
"the-name" : {
"type" : "string",
"store" : true
},
"the-properties": {
"type" : "nested",
"properties" : {
"name" : {
"type" : "string",
"store" : true
},
"value" : {
"type" : "object",
"properties" : {
"as_double" : { "type": "double", "store": true} ,
"as_int" : { "type": "integer", "store": true} ,
"as_string" : { "type": "string", "store": true} ,
"as_bool" : { "type": "boolean", "store": true}
}
}
}
}
}
}
}'

which results in an ES data structure like this..

"_source": {
"name": "My Object",
"properties": [
{
"name": "foo",
"value": {
"as_double": 23.56
}
}
,
{
"name": "bar",
"value": {
"as_bool": false
}
}
,
{
"name": "bla",
"value": {
"as_double": 22.56
}
}
,
{
"name": "junk",
"value": {
"as_double": 8.56
}
}
,
{
"name": "fee",
"value": {
"as_string": "D6677"
}
}
]
}
}

Thanks

You probably want to leverage parent/child so that an update doesn't require the entire document to be reindexed.