# Query with wildcard

**URL:** <https://discuss.elastic.co/t/query-with-wildcard/289372>\
**Category:** Elasticsearch\
**Created:** [November 16, 2021, 11:32pm UTC](https://discuss.elastic.co/t/query-with-wildcard/289372 "2021-11-16T23:32:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wonder\_Garance](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wonder_garance/32/91180_2.png) [@Wonder\_Garance](https://discuss.elastic.co/u/Wonder_Garance)\
**Post date:** [November 16, 2021, 11:32pm UTC](https://discuss.elastic.co/t/query-with-wildcard/289372/1 "2021-11-16T23:32:27Z")

</div>

I want to generate phrase queries with wildcard, but this query returns 0 result:

```auto
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "\"user login authen*\"",
            "fields": [
              "text"
            ],
            "phrase_slop": 5,
            "default_operator": "and",
            "analyze_wildcard": true,
            "auto_generate_synonyms_phrase_query": false
          }
        }
      ]
    }
  }

```

Does phrase query handle wildcard (?\*)? May I have an explication?

Someone proposed to use span queries for the queries with a proximity and wildcards. If we search with a long sentence, the query becomes too complexe.

I met another problem with span query, if I replace the search field "text.exact" (without stemming) by "text" (a filed with stemming) in the query below, I get 0 result. Why?

```auto
"query": {
    "span_near": {
      "clauses": [
        {
          "span_term": {"text.exact": "user"}
        },
        {
          "span_term": {"text.exact": "login"}
        },
        {
          "span_multi": {
            "match": {
              "wildcard": {"text.exact": "authen*"}
            }
          }
        }
      ],
      "slop": 5,
      "in_order": true
    }
  }

```

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [November 17, 2021, 3:29pm UTC](https://discuss.elastic.co/t/query-with-wildcard/289372/2 "2021-11-17T15:29:36Z")

</div>

Another approach that may be of interest is to use the `wildcard` field.

Check the decision flowchart at the end of this blog before using though: [Find strings within strings faster with the Elasticsearch wildcard field | Elastic Blog](https://www.elastic.co/blog/find-strings-within-strings-faster-with-the-new-elasticsearch-wildcard-field)

---

<div class="post-metadata">

**Author:** ![Wonder\_Garance](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wonder_garance/32/91180_2.png) [@Wonder\_Garance](https://discuss.elastic.co/u/Wonder_Garance)\
**Post date:** [November 17, 2021, 6:47pm UTC](https://discuss.elastic.co/t/query-with-wildcard/289372/3 "2021-11-17T18:47:53Z")

</div>

Thank you for the proposition.

I tested the wildcard field, but it's not for our use case, we want to tokenize the text field and search with a proximity.

---

<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:** [December 15, 2021, 6:47pm UTC](https://discuss.elastic.co/t/query-with-wildcard/289372/4 "2021-12-15T18:47:59Z")

</div>

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