# Cant do case insensitive search in elastic search

**URL:** <https://discuss.elastic.co/t/cant-do-case-insensitive-search-in-elastic-search/325680>\
**Category:** Elasticsearch\
**Created:** [February 16, 2023, 3:21am UTC](https://discuss.elastic.co/t/cant-do-case-insensitive-search-in-elastic-search/325680 "2023-02-16T03:21:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dang\_Hai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dang_hai/32/117332_2.png) [@Dang\_Hai](https://discuss.elastic.co/u/Dang_Hai)\
**Post date:** [February 16, 2023, 3:21am UTC](https://discuss.elastic.co/t/cant-do-case-insensitive-search-in-elastic-search/325680/1 "2023-02-16T03:21:08Z")

</div>

I'm new to Elasticsearch and trying to do this query right.  
So I'm having a document like this:

```auto
{
    "id": 1,
    "name": "Văn Hiến"
}

```

I want to get that document in 3 cases:  
1/ User input is: "v" or "h" or "i",...  
2/ User input is: "Văn" or "văn" or "hiến",...  
3/ User input is: "va" or "van" or "van hi",...

I'm currently can search for case 1 and 2, but not case 3, where the user input don't have the 'tonal' of the Vietnamese language  
This is my query, I'm using Python:

```auto
query = {
                "bool": {
                    "should": [
                        {
                            "match": { 
                                "name": name.lower()
                            }
                        },
                        {
                            "wildcard": {
                                "name": {
                                    "value": f"*{name.lower()}*"
                                }
                            }
                        }
                    ]
                }
            }

```

Can anyone help me with this? Any helps will be apperciated

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [February 16, 2023, 5:05am UTC](https://discuss.elastic.co/t/cant-do-case-insensitive-search-in-elastic-search/325680/2 "2023-02-16T05:05:21Z")

</div>

Hi @Dang_Hai

I would avoid using \* at the beginning of patterns. Elastic recommend avoiding:

> Avoid beginning patterns with `*` or `?` . This can increase the iterations needed to find matching terms and slow search performance.

I believe you can succeed using the [Edge n-gram tokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenizer.html).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 16, 2023, 12:58pm UTC](https://discuss.elastic.co/t/cant-do-case-insensitive-search-in-elastic-search/325680/3 "2023-02-16T12:58:35Z")

</div>

That's a question of analyzer. As @RabBit_BR suggested, you should not use `wildcard` query in that case but the right analyzers with a `match` query.

A wildcard query will compare what you entered with the inverted index.

If your analyzer has indexed `Văn` to `văn`, then searching for `van` won't match...

Have a look at the [ascii folding token filter](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-asciifolding-tokenfilter.html).

---

<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 16, 2023, 12:58pm UTC](https://discuss.elastic.co/t/cant-do-case-insensitive-search-in-elastic-search/325680/4 "2023-03-16T12:58:50Z")

</div>

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