Can I add normalizer in runtime?

Hey guys!

I want to add a new field into my existing mapping (using dynamic templates as well). As far as I understand the best way to do it is to use update mapping API (Update mapping API | Elasticsearch Guide [8.5] | Elastic).

My problem is that my current field mapping looks like this:

"my_field": {
                    "type": "text",
                    "fields": {
                        "raw": {
                            "type": "keyword"
                        }
                    },
                    "copy_to": [
                        "all_search_fields"
                    ],
                    "norms": false
                }

and I want it to look like this

"my_field": {
                    "type": "text",
                    "fields": {
                                "lowercase": {
                                    "normalizer": "lowercase_normalizer",
                                    "type": "keyword"
                                },
                        "raw": {
                            "type": "keyword"
                        }
                    },
                    "copy_to": [
                        "all_search_fields"
                    ],
                    "norms": false
                }

so I'm basically adding a new field called lowercase that is a keyword with custom normalizer. Correct me if I'm wrong, but I can achieve that by sending PUT request on https://my_url/my_mapping/_mapping.

Now my problem is that elastic tells me "Failed to parse mapping [_doc]: normalizer [lowercase_normalizer] not found for field [lowercase]"

QUESTION: Is there a way I can add a normalizer in runtime before updating my mapping so I can conclude this operation succesfully? If not, then am I right that I should do it through creating a new index? (which basically mean using re-index API)

It should be possible but you need to add the normalizer to your index settings first.

Note that adding this will only apply to new documents or to updated documents. It won't compute anything on existing documents.

Reindexing in that case is the best option. Otherwise, you can try runtime fields.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.