Reputation: 694
I want to use case insensitive sorting in the elasticsearch. But ES uses ASCII sorting default. So to make case-insensitive searching. I have to use normalizer.
{
"analysis": {
"normalizer": {
"custom_sort_normalizer": {
"type": "custom",
"char_filter": [],
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
}
I want to apply this custom_sort_normalizer to all text or keyword based fields. As I am using AWS elasticsearch, I can not simply close the index and apply this normalizer. Either I have to reindex and create index from start, I want to avoid both this option for future.
Right now, I am adding manually in the mapping to tell elasticsearch use the normalizer. Is there anyway I can make it as default ?
Update : I am maintaining mapping using yaml file. Below is a sample mapping.
properties:
studetName:
type: text
fields:
keyword:
type: keyword
ignore_above: 256
studentGender:
type: text
fields:
keyword:
type: keyword
ignore_above: 256
studentGroup:
type: text
fields:
keyword:
type: keyword
normalizer: custom_sort_normalizer
ignore_above: 256
My main objective is that every new text fields we add in this mapping.yaml (every new text/keyword file in that index) should by default use normalizer.
Upvotes: 0
Views: 1525
Reputation: 381
you can utilize dynamic templates to achieve what you want. create your index template with mapping as follows:
PUT my-index
{
"settings": {
"index": {
"analysis": {
"normalizer": {
"my_normalizer": {
"type": "custom",
"char_filter": [],
"filter": [
"lowercase"
]
}
}
}
}
},
"mappings": {
"dynamic_templates": [
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "keyword",
"ignore_above": 256,
"normalizer": "my_normalizer"
}
}
}
]
}
}
Upvotes: 1
Reputation: 32376
If I understand correctly, you want to have your custom custom_sort_normalizer
applied to all the fields in your future elasticsearch indices. if yes, then you can simply use the index template, which will allow you to define this setting in the template, and later on this template, you can apply to your future indices.
From the docs
Index templates allow you to define templates that will automatically be applied when new indices are created. The templates include both settings and mappings and a simple pattern template that controls whether the template should be applied to the new index.
Upvotes: 0