Currently I am using dynamic template as follows, Here I am applying n-gram analyzer to all the "String" fields. However to improve efficiency I would like to apply n-gram only on specific fields only and not on all String fields.
{
"template": "*",
"settings": {
"analysis": {
"filter": {
"ngram_filter": {
"type": "ngram",
"min_gram": 1,
"max_gram": 25
}
},
"analyzer": {
"case_insensitive": {
"tokenizer": "whitespace",
"filter": [
"ngram_filter",
"lowercase"
]
},
"search_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": "lowercase"
}
}
}
},
"mappings": {
"my_type": {
"dynamic_templates": [
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "string",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "case_insensitive",
"search_analyzer": "search_analyzer"
}
}
}
]
}
}
}
I have a payload like this:
{
"userId":"abc123-pqr180-xyz124-njd212",
"email" : "[email protected]",
"name" : "somename",
.
.
20 more fields
}
Now I want to apply n-gram only for "email" and "userid". How can we do this ?
emailandnamefields?matchin which you can give a name pattern to which the template should be applied, but it doesn't take an array andemailandnamehave no prefix/suffix in common.dynamic_templatesand use the proper mapping for each of your fields. Another way to do this is to duplicate the dynamic template for the two fieldsemailandname