Create a dynamic ElasticSearch template so that all fields are set to not_analyzed
I have an ElasticSearch type for which I want the mapping to be set dynamically. There are several select fields of this type that I want to analyze, but everything else should be set to "not_analyzed".
I got the following snippet. This states that all string fields are not parsed, but does not cover all other data types. I tried to use the "generic" field mentioned in the documentation, but it didn't help. Can anyone tell me how I can do this?
{
"TypeName": {
"dynamic_templates": [
{
"template_name": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"index": "no",
"type": "string"
}
}
}
],
"dynamic": true,
"properties": {
"url": {
"index": "analyzed",
"type": "string"
},
"resourceUrl": {
"index": "analyzed",
"type": "string"
}
}
}
}
+3
source to share
1 answer
{
"mappings": {
"TypeName": {
"dynamic_templates": [
{
"base": {
"mapping": {
"index": "not_analyzed"
},
"match": "*",
"match_mapping_type": "*"
}
}
],
"dynamic": true,
"properties": {
"url": {
"index": "analyzed",
"type": "string"
},
"resourceUrl": {
"index": "analyzed",
"type": "string"
}
}
}
}
}
In general, the index level pattern is:
{
"mappings": {
"_default_": {
"dynamic_templates": [
{
"base": {
"mapping": {
"index": "not_analyzed"
},
"match": "*",
"match_mapping_type": "*"
}
}
]
}
}
}
+3
source to share