# Elasticsearch Became case sensitive after add synonym analyzer

**URL:** <https://discuss.elastic.co/t/elasticsearch-became-case-sensitive-after-add-synonym-analyzer/300283>\
**Category:** Elasticsearch\
**Created:** [March 22, 2022, 7:36am UTC](https://discuss.elastic.co/t/elasticsearch-became-case-sensitive-after-add-synonym-analyzer/300283 "2022-03-22T07:36:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Fhadli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muhammad_fhadli/32/102950_2.png) [@Muhammad\_Fhadli](https://discuss.elastic.co/u/Muhammad_Fhadli)\
**Post date:** [March 22, 2022, 7:36am UTC](https://discuss.elastic.co/t/elasticsearch-became-case-sensitive-after-add-synonym-analyzer/300283/1 "2022-03-22T07:36:13Z")

</div>

After I added synonym analyzer to my\_index, the index became case-sensitive

I have one property called `nationality` that has `synonym analyzer`. But it seems that this property become `case sensitive` because of the synonym analyzer.

Here is my `/my_index/_mappings`

```auto
{
  "my_index": {
    "mappings": {
      "items": {
        "properties": {
          .
          .
          .
          "nationality": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            },
            "analyzer": "synonym"
          },
          .
          .
          .
        }
      }
    }
  }
}

```

Inside the index, i have word `India COUNTRY`. When I try to search `India nation` using the command below, I will get the result.

```auto
POST /my_index/_search
{
  "query": {
    "match": {
      "nationality": "India nation"
    }
  }
}

```

But, when I search for `india` (notice the letter `i` is lowercase), I will get nothing.  
My assumption is, this happend because i put `uppercase` filter before the `synonym`. I did this because the synonyms are uppercased. So the query `India` will be `INDIA` after pass through this filter.

Here is my `/my_index/_settings`

```auto
{
  "my_index": {
    "settings": {
      "index": {
        "number_of_shards": "1",
        "provided_name": "my_index",
        "similarity": {
          "default": {
            "type": "BM25",
            "b": "0.9",
            "k1": "1.8"
          }
        },
        "creation_date": "1647924292297",
        "analysis": {
          "filter": {
            "synonym": {
              "type": "synonym",
              "lenient": "true",
              "synonyms": [
                "NATION, COUNTRY, FLAG"
              ]
            }
          },
          "analyzer": {
            "synonym": {
              "filter": [
                "uppercase",
                "synonym"
              ],
              "tokenizer": "whitespace"
            }
          }
        },
        "number_of_replicas": "1",
        "version": {
          "created": "6080099"
        }
      }
    }
  }
}

```

Is there a way so I can make this property still case-insensitive. All the solution i've found only shows that I should only either set all the text inside `nationality` to be lowercase or uppercase. But how if I have uppercase & lowercase letters inside the index?

---

<div class="post-metadata">

**Author:** ![sagarpatel](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@sagarpatel](https://discuss.elastic.co/u/sagarpatel)\
**Post date:** [March 22, 2022, 1:41pm UTC](https://discuss.elastic.co/t/elasticsearch-became-case-sensitive-after-add-synonym-analyzer/300283/2 "2022-03-22T13:41:33Z")

</div>

> [@Muhammad\_Fhadli](#):
>
> After I added synonym analyzer to my\_index, the index became case-sensitive

Do you mean you have updated index mapping to existing index ? if yes then did you reindex your data ?

Because i have crated same index mapping with same analyzer but not able to reproduce this issue. I think so once you reindex data, this issue will be resolved.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Fhadli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muhammad_fhadli/32/102950_2.png) [@Muhammad\_Fhadli](https://discuss.elastic.co/u/Muhammad_Fhadli)\
**Post date:** [March 23, 2022, 12:04am UTC](https://discuss.elastic.co/t/elasticsearch-became-case-sensitive-after-add-synonym-analyzer/300283/4 "2022-03-23T00:04:49Z")

</div>

Ah i'm sorry, i forget to explain that. `my_index` is not an existing index. But I created it using this command. Thank you for your response.

```auto
PUT /my_index

{
  "settings": {
    "number_of_shards": 1,
    "analysis": {
        "filter": {
          "synonym": {
            "type": "synonym",
            "lenient": "true",
            "synonyms": [
              "NATION, COUNTRY, FLAG"
            ]
          }
        },
        "analyzer": {
          "synonym": {
            "filter": [
              "uppercase"	
              "synonym"
            ],
            "tokenizer": "whitespace"
          }
        }
      }
  },
  "mappings": {
    "properties": {
      .
      .
      "nationality": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            },
            "analyzer": "synonym"
          },
      .
      .
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Muhammad\_Fhadli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muhammad_fhadli/32/102950_2.png) [@Muhammad\_Fhadli](https://discuss.elastic.co/u/Muhammad_Fhadli)\
**Post date:** [March 23, 2022, 4:42am UTC](https://discuss.elastic.co/t/elasticsearch-became-case-sensitive-after-add-synonym-analyzer/300283/5 "2022-03-23T04:42:22Z")

</div>

I have found the solution!

I didn't realize that the filter that I applied in the `settings` is applicable while updating and searching the data. At first, I did this step:

1. Create index with synonym filter
2. Insert data
3. Add `uppercase` before synonym filter

By doing that, the `uppercase` filter is not applied to my data. What I should've done are:

1. Create index with `uppercase` & `synonym` filter (pay attention to the order)
2. Insert data  
Then the filter will be applied to my data.

---

<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:** [April 20, 2022, 4:43am UTC](https://discuss.elastic.co/t/elasticsearch-became-case-sensitive-after-add-synonym-analyzer/300283/6 "2022-04-20T04:43:15Z")

</div>

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