# Wildcard search does not work

**URL:** <https://discuss.elastic.co/t/wildcard-search-does-not-work/233016>\
**Category:** Elasticsearch\
**Created:** [May 17, 2020, 10:44pm UTC](https://discuss.elastic.co/t/wildcard-search-does-not-work/233016 "2020-05-17T22:44:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![debasisc](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@debasisc](https://discuss.elastic.co/u/debasisc)\
**Post date:** [May 17, 2020, 10:44pm UTC](https://discuss.elastic.co/t/wildcard-search-does-not-work/233016/1 "2020-05-17T22:44:34Z")

</div>

V7.3.2 in Windows

The following command works. Note "name" is text field.

```auto
GET /myindex/_search
{
    "query": {
         "match" : {
             "name": {
                 "query" : "ABCD"
             }
         }
     }
 }

```

================

But when I try using wildcard, it does not bring any result.  
Syntax is from here  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html)

```auto
 GET /myindex/_search
 {
     "query": {
         "wildcard": {
             "name": {
                 "value": "AB*D",
                 "boost": 1.0,
                 "rewrite": "constant_score"
             }
         }
     }
 }

```

=================  
If this is caused by wrong setting of search.allow\_expensive\_queries, how do I check what is current value and where do I set this to true?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [May 18, 2020, 5:02pm UTC](https://discuss.elastic.co/t/wildcard-search-does-not-work/233016/2 "2020-05-18T17:02:26Z")

</div>

Could you paste the mapping of the `name` text field and if it is using any custom analyzers? Also a sample document?

I suspect this is an analysis issue. The `match` query will pass the query text through the same analyzer that was used to index the document, which means input and output likely match. The `wildcard` query is a non-analyzed query, meaning it searches the index for _exactly_ the text that you provide.

In practice, most text fields have some kind of analyzer that lowercases, removes punctuation, tokenizes on white space, etc etc. That means a document might have the text `ABCD`, but after analysis it is stored as `abcd`.

- The match query will perform this same analysis, and `"ABCD" -> "abcd"` which matches.
- In contrast, the wildcard query does no analysis, so it is looking for `"AB"`, any number of characters, followed by `"D"`. This doesn't exist in the index because the document was stored as `"abcd"`, so the query fails to match

I'm not sure that is what's happening, but something along that lines is most likely.

---

<div class="post-metadata">

**Author:** ![debasisc](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@debasisc](https://discuss.elastic.co/u/debasisc)\
**Post date:** [May 18, 2020, 10:13pm UTC](https://discuss.elastic.co/t/wildcard-search-does-not-work/233016/3 "2020-05-18T22:13:50Z")

</div>

@polyfractal -

Resolved. Thanks for your explanation. I changed value as lowercase in query and then query brings back results as expected.

Checked mapping -

```auto
"name" : {
          "type" : "text",
          "index_options" : "offsets"
        },

```

Also found these settings from Mapping

```auto
"settings" : {
      "index" : {
        "number_of_shards" : "5",
        "provided_name" : "XXXXXXX",
        "gc_deletes" : "24h",
        "creation_date" : "1578423989207",
        "analysis" : {
          "analyzer" : {
            "keyword_lowercase" : {
              "filter" : [
                "lowercase"
              ],
              "type" : "custom",
              "tokenizer" : "keyword"
            }
          }
        },

```

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [May 21, 2020, 3:21pm UTC](https://discuss.elastic.co/t/wildcard-search-does-not-work/233016/4 "2020-05-21T15:21:50Z")

</div>

Awesome, glad you sorted it out! 🙂

Analyzed vs non-analyzed is a tricky thing that catches a lot of people up. In the docs, anything that is a [Fulltext query](https://www.elastic.co/guide/en/elasticsearch/reference/current/full-text-queries.html) will be analyzed with the configured analyzer (which tends to make them more "user-friendly" for query bars and end-users, etc)... while pretty much all the other queries are non-analyzed and looking at byte-for-byte matches in the index.

---

<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:** [June 18, 2020, 3:21pm UTC](https://discuss.elastic.co/t/wildcard-search-does-not-work/233016/5 "2020-06-18T15:21:52Z")

</div>

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