I am trying to to create a mapping that will allow me to have a document looking like this:
{
"created_at" : "2014-11-13T07:51:17+0000",
"updated_at" : "2014-11-14T12:31:17+0000",
"account_id" : 42,
"attributes" : [
{
"name" : "firstname",
"value" : "Morten",
"field_type" : "string"
},
{
"name" : "lastname",
"value" : "Hauberg",
"field_type" : "string"
},
{
"name" : "dob",
"value" : "1987-02-17T00:00:00+0000",
"field_type" : "datetime"
}
]
}
And the attributes
array must be of type nested, and dynamic, so i can add more objects to the array and index it by the field_type
value.
Is this even possible?
I have been looking at the dynamic_templates. Can i use that?
No - you cannot have different datatypes for the same field within the same type.
e.g. the field
index/type/value
can not be both a string and a date.A dynamic template can be used to set the datatype and analyzer based on the format of the field name
For example: set all fields with field names ending in "_dt" to type
datetime
.But this won't help in your scenario, once the datatype is set you can't change it.