# Change analyzer into an existing index

**URL:** <https://discuss.elastic.co/t/change-analyzer-into-an-existing-index/264746>\
**Category:** Elasticsearch\
**Created:** [February 18, 2021, 5:50pm UTC](https://discuss.elastic.co/t/change-analyzer-into-an-existing-index/264746 "2021-02-18T17:50:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rschirin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rschirin/32/45283_2.png) [@rschirin](https://discuss.elastic.co/u/rschirin)\
**Post date:** [February 18, 2021, 5:50pm UTC](https://discuss.elastic.co/t/change-analyzer-into-an-existing-index/264746/1 "2021-02-18T17:50:17Z")

</div>

Hey there,  
I have an existing index without any custom setting or mapping for any field, so everything is by default.  
Into the docs I have a field named _category_ which contains words like Women's or Womens.

```
POST my_index/_doc/
{
  "message": "This is the first document",
  "category": "Womens"
}

POST my_index/_doc/
{
  "message": "This is the second document",
  "category": "Women's"
}

```

I would like to get both type of docs with a _\_search_ operation.  
So, I was trying to change index \_settings with a custom _char\_filter_ to remove the single quote character:

```
PUT my_index/_settings
{
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "char_filter": [
            "my_char_filter"
          ]
        }
      },
      "char_filter": {
        "my_char_filter": {
          "type": "mapping",
          "mappings": [
            "' => "
          ]
        }
      }
  }
}

```

When I tried a \_search I got only one type of document:

```
GET my_index/_search
{
  "query": {
    "match": {
      "text": {
        "category": "Womens"
      }
    }
  }
}

```

In another scenario, if I start from scratch creating a custom index as follow:

```
PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "char_filter": [
            "my_char_filter"
          ]
        }
      },
      "char_filter": {
        "my_char_filter": {
          "type": "mapping",
          "mappings": [
            "' => "
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "text": {
        "type": "text",
        "analyzer": "my_analyzer"
      }
    }
  }
}

```

my search query will work.  
What is wrong?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 18, 2021, 9:31pm UTC](https://discuss.elastic.co/t/change-analyzer-into-an-existing-index/264746/2 "2021-02-18T21:31:20Z")

</div>

You cannot change analysers on existing indices like that, you will need to reindex.

---

<div class="post-metadata">

**Author:** ![rschirin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rschirin/32/45283_2.png) [@rschirin](https://discuss.elastic.co/u/rschirin)\
**Post date:** [February 19, 2021, 7:44am UTC](https://discuss.elastic.co/t/change-analyzer-into-an-existing-index/264746/3 "2021-02-19T07:44:56Z")

</div>

so, probably it means that I understood the theory 🙂  
from your perspective, is there another posh way to get that result starting from the beginning?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 21, 2021, 9:15pm UTC](https://discuss.elastic.co/t/change-analyzer-into-an-existing-index/264746/4 "2021-02-21T21:15:05Z")

</div>

There are search time analysers, but you are better off changing the indexing time analyser and reindexing.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 21, 2021, 9:15pm UTC](https://discuss.elastic.co/t/change-analyzer-into-an-existing-index/264746/5 "2021-03-21T21:15:35Z")

</div>

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