# Wildcards with query\_string query and custom analyzer

**URL:** <https://discuss.elastic.co/t/wildcards-with-query-string-query-and-custom-analyzer/303330>\
**Category:** Elasticsearch\
**Created:** [April 26, 2022, 9:19pm UTC](https://discuss.elastic.co/t/wildcards-with-query-string-query-and-custom-analyzer/303330 "2022-04-26T21:19:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mej101](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mej101/32/97686_2.png) [@mej101](https://discuss.elastic.co/u/mej101)\
**Post date:** [April 26, 2022, 9:19pm UTC](https://discuss.elastic.co/t/wildcards-with-query-string-query-and-custom-analyzer/303330/1 "2022-04-26T21:19:27Z")

</div>

I have a `query_string` query I'm using with wildcards and a custom analyzer. The query behaves as expected for some words and not for others.

Here's the query:

```auto
    "query_string": {
      "query": "Abdulla*",
      "analyze_wildcard": true,
      "allow_leading_wildcard": true,
      "analyzer": "custom_common_grams_analyzer",
      "fields": ["text"],
      "lenient": true
    }
  }

```

When I use either `?` or `*` wildcards anywhere in the query term `Abdullah`, I get the expected results. `*bdullah`, `Abd?llah`, and `Abdull*` return all documents that contain `Abdullah`.

The query term `grandfathered`, however, doesn't work the same way. I get zero results if I use any `?` wildcards in the word. If I use a `*` wildcard I also get zero results, unless the `*` is in the last two characters of the word, and the number of results that come back differ if I use `grandfather*d` or `grandfathere*`. With `grandfathere*` I get back the full, correct set of results. My custom analyzer does incorporate stemming.

---

<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:** [April 27, 2022, 5:15am UTC](https://discuss.elastic.co/t/wildcards-with-query-string-query-and-custom-analyzer/303330/2 "2022-04-27T05:15:16Z")

</div>

Can you please add setting of your custom analyzer. it will help to understand issue.

---

<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:** [May 25, 2022, 5:15am UTC](https://discuss.elastic.co/t/wildcards-with-query-string-query-and-custom-analyzer/303330/3 "2022-05-25T05:15:38Z")

</div>

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