Home > Back-end >  How to make a field to have lowercase analyzer after field creation?
How to make a field to have lowercase analyzer after field creation?

Time:12-11

I run

PUT /vehicles/_doc/123
{
  "make" : "Honda civic", 
  "color" : "Blue", 
  "from": "Japan",
  "size": "Big",
  "HP" : 250, 
  "milage" : 24000, 
  "price": 19300.97
}

at the start

and after that I run

PUT /vehicles
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_lowercase_analyzer": {
          "tokenizer": "standard",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "make": {
        "type": "text",
        "analyzer": "my_lowercase_analyzer"
      }
    }
  }
}

It gives exception

{
  "error": {
    "root_cause": [
      {
        "type": "resource_already_exists_exception",
        "reason": "index [vehicles/o66DtxmERa2lmo2WiiZ65w] already exists",
        "index_uuid": "o66DtxmERa2lmo2WiiZ65w",
        "index": "vehicles"
      }
    ],
    "type": "resource_already_exists_exception",
    "reason": "index [vehicles/o66DtxmERa2lmo2WiiZ65w] already exists",
    "index_uuid": "o66DtxmERa2lmo2WiiZ65w",
    "index": "vehicles"
  },
  "status": 400
}

Is there away to update analyzer after creation?

CodePudding user response:

Updating the analyzer of an existing field is a breaking change, you can't update it on the same index, you now have below. options

  1. Add another field, on which you can define the new analyzer (of-course this is not recommended as you will loose the old data, but in some cases it may be useful).

  2. Create a new index using same field and updated analyzer definition and after that you can use reindex API to update the data from old to new index.

  • Related