# Wildcard search with space in the text

**URL:** <https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797>\
**Category:** Elasticsearch\
**Created:** [January 20, 2020, 9:09pm UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797 "2020-01-20T21:09:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwlee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jwlee/32/61090_2.png) [@jwlee](https://discuss.elastic.co/u/jwlee)\
**Post date:** [January 20, 2020, 9:09pm UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/1 "2020-01-20T21:09:30Z")

</div>

Wildcard search seems not working if a value contains space.  
For example, if a value is " **hello world**" and if you do search **hel** \* it does not return anything.

Below is the query that I used:

```
 {
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "hel*"
          }
        }
      ]
    }
  }
}

```

It works if I do hello\* but anything that is partial string of hello is not working. Is there a way that can make it work if I search a substring of hello such as he\*, hel\*, hell\*?

---

<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:** [January 20, 2020, 9:28pm UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/2 "2020-01-20T21:28:18Z")

</div>

It's because you are using a match query I guess.  
Try with a wildcard query.

---

<div class="post-metadata">

**Author:** ![jwlee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jwlee/32/61090_2.png) [@jwlee](https://discuss.elastic.co/u/jwlee)\
**Post date:** [January 20, 2020, 9:37pm UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/3 "2020-01-20T21:37:28Z")

</div>

I tried with wildcard search but it's same result

---

<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:** [January 21, 2020, 5:03am UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/4 "2020-01-21T05:03:58Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![jwlee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jwlee/32/61090_2.png) [@jwlee](https://discuss.elastic.co/u/jwlee)\
**Post date:** [January 21, 2020, 5:00pm UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/5 "2020-01-21T17:00:59Z")

</div>

I updated the script.

---

<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:** [January 21, 2020, 5:59pm UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/6 "2020-01-21T17:59:17Z")

</div>

Where?

---

<div class="post-metadata">

**Author:** ![jwlee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jwlee/32/61090_2.png) [@jwlee](https://discuss.elastic.co/u/jwlee)\
**Post date:** [January 21, 2020, 8:46pm UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/7 "2020-01-21T20:46:59Z")

</div>

```
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "hel*"
          }
        }
      ]
    }
  }
}

```

I updated in the post but I pasted here as well. Basically what I am looking for with this script is that it should be able to search any value that contains **hel** \*. If value contains a space such as hello world, it should return the value but currently it is not returning anything.

What should be the analyzer in order to search partial substring of a value that may or may not contain spaces?

---

<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:** [January 22, 2020, 1:21am UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/8 "2020-01-22T01:21:31Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<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:** [January 22, 2020, 6:02am UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/10 "2020-01-22T06:02:19Z")

</div>

If I execute your script in Kibana it gives that the index does not exist or it returns no data as no data have been indexed.

So I can not reproduce your problem.

---

<div class="post-metadata">

**Author:** ![DeeeFOX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deeefox/32/49566_2.png) [@DeeeFOX](https://discuss.elastic.co/u/DeeeFOX)\
**Post date:** [January 22, 2020, 9:15am UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/11 "2020-01-22T09:15:47Z")

</div>

> `*` , which can match zero or more characters, including an empty one [(from es reference)](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html#wildcard-query-field-params)

"space" is not kinds of characters or "empty one", i guess...

---

<div class="post-metadata">

**Author:** ![DeeeFOX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deeefox/32/49566_2.png) [@DeeeFOX](https://discuss.elastic.co/u/DeeeFOX)\
**Post date:** [January 23, 2020, 4:56am UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/14 "2020-01-23T04:56:34Z")

</div>

May be u can try this: [regexp-query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html) in ur query body

---

<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:** [February 20, 2020, 4:56am UTC](https://discuss.elastic.co/t/wildcard-search-with-space-in-the-text/215797/15 "2020-02-20T04:56:40Z")

</div>

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