How to create an index with combination of fields and dynamic template?


(Reddaiah nethi) #1

I have to create an index, with 20 fields as known type and fixed fields, so I can specify the properties of those fields and , there is an object called dimensions, with unknown field names. So, I have to create a dynamic template, just for inner fields in the dimensions object with type string and as not_analyzed field. Please help me here

here is the one, I tried to create , but not successful.

PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"status_code": {
"type": "string",
"index": "not_analyzed"
},
"session_id": {
"type": "long",
"Dimensions":
{
"dynamic_templates": [
{
"testname": {
"match": "*",
"mapping": {
"type": "string",
"index": "not_analyzed",
"doc_values": true
}
}
}]
}
}
}
}
}
}


(Reddaiah nethi) #2

I can create like this, but properties are not being applied for the new fields added under customdimensions object.

PUT testindex
{
"mappings": {
"test_type":{
"dynamic_templates": [
{
"name_template": {
"match": "customdimension.*",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
],
"properties": {
"cloudRoleName": {
"type": "string",
"index": "not_analyzed"
},
"componentName": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}


(Reddaiah nethi) #3

This can be achieved by dynamic template for nested fields. See the example below

"error": {
"settings": {
"index": {
"number_of_shards": 20,
"number_of_replicas": 2
}
},
"mappings": {
"dailyaggregate": {
"dynamic_templates": [
{
"string_template": {
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
},
{
"customDim_template": {
"match": "custom*",
"mapping": {
"type": "nested"
}
}
},
{
"nested_template": {
"path_match": "custom*.*",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
],
"properties": {
"@timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
}


(system) #4