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

-- 
Please update your bookmarks! We have moved to https://discuss.elastic.co/
--- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/6fdbfe26-4032-4664-91ce-582a0d832bf4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to