# Search multiple words using wildcard query

**URL:** <https://discuss.elastic.co/t/search-multiple-words-using-wildcard-query/272648>\
**Category:** Elasticsearch\
**Created:** [May 11, 2021, 8:18am UTC](https://discuss.elastic.co/t/search-multiple-words-using-wildcard-query/272648 "2021-05-11T08:18:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![schawla](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@schawla](https://discuss.elastic.co/u/schawla)\
**Post date:** [May 11, 2021, 8:18am UTC](https://discuss.elastic.co/t/search-multiple-words-using-wildcard-query/272648/1 "2021-05-11T08:18:04Z")

</div>

I have documents indexed to elastic search in the following structure -

```auto
[{ "firstname" : "john", "lastname" : "cena" } , { "firstname" : "peter", "lastname" : "parker" }]

```

I am trying to use a bool query that contains two should clauses - both are wildcard queries to search for people with their firstname/lastname -

```auto
new WildCardQuery
{
     "Field" : "firstname", 
     "Value": enteredTextByUserInSearchBar + "*"
},
new WildCardQuery
{
     "Field" : "lastname", 
     "Value": enteredTextByUserInSearchBar + "*"
}

```

**Issue**  
When i try and search - `pete`, my query uses `pete*` as the value part of the wildcard query and returns me the result peter parker. Same is the case when i search `park` and i get peter parker as result.

but when the user entered text contains multiple words like - `peter parker`, i dont get any search results. Maybe because the query that gets executed on es uses the value - `peter parker*` (as per how i have defined the value part in the wildcard query above)

Any suggestions how to solve this or any alternatives to using wildcard query here ? I want to be able to search people on the basis of their firstnames/lastnames and also have a partial match such that if i enter peter park or pet parker or pet park, i should get the results peter parker.

---

<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:** [May 11, 2021, 8:33am UTC](https://discuss.elastic.co/t/search-multiple-words-using-wildcard-query/272648/2 "2021-05-11T08:33:14Z")

</div>

Wildcard queries can be slow.

I'd recommend using another way.

You can combine different kind of techniques to propose to your user the most relevant documents first. Have a look at:

> <https://gist.github.com/dadoonet/5179ee72ecbf08f12f53d4bda1b76bab#file-search_kibana_console-txt-L374-L469>

This might give you an idea.

BTW for partial matching, you can use a edge ngram based analyzer.

---

<div class="post-metadata">

**Author:** ![schawla](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@schawla](https://discuss.elastic.co/u/schawla)\
**Post date:** [May 11, 2021, 9:18am UTC](https://discuss.elastic.co/t/search-multiple-words-using-wildcard-query/272648/3 "2021-05-11T09:18:12Z")

</div>

In order to use the edge ngram based analyzer, my match query takes in a property called analyzer but since it accepts a string value, are you aware of what is the identifier for edge ngram analyzer that i should supply here -

```auto
new MatchQuery()
{
   Field = "firstname",
   Query = "Pete Park",
   Boot = 2.0,
  Analyzer = "" ???????
}

```

---

<div class="post-metadata">

**Author:** ![schawla](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@schawla](https://discuss.elastic.co/u/schawla)\
**Post date:** [May 11, 2021, 12:06pm UTC](https://discuss.elastic.co/t/search-multiple-words-using-wildcard-query/272648/4 "2021-05-11T12:06:22Z")

</div>

@dadoonet Can you please help me with how to specify edge ngram based analyzer in a match query as asked in the previous reply.  
I am unable to find the identifier for edge ngram based analyzer that i can assign to the analyser property of match query

---

<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:** [May 11, 2021, 3:28pm UTC](https://discuss.elastic.co/t/search-multiple-words-using-wildcard-query/272648/5 "2021-05-11T15:28:21Z")

</div>

Please be patient in waiting for responses to your question and refrain from pinging multiple times asking for a response or opening multiple topics for the same question. This is a community forum, it may take time for someone to reply to your question. For more information please refer to the [Community Code of Conduct](https://www.elastic.co/community/codeofconduct) specifically the section "Be patient". Also, please refrain from pinging folks directly, this is a forum and anyone that participates might be able to assist you.

If you are in need of a service with an SLA that covers response times for questions then you may want to consider talking to us about a [subscription](https://www.elastic.co/subscriptions).

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an 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:** [May 11, 2021, 3:32pm UTC](https://discuss.elastic.co/t/search-multiple-words-using-wildcard-query/272648/6 "2021-05-11T15:32:59Z")

</div>

You have some examples available in the documentation.

> **[Edge n-gram token filter | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenfilter.html)**

Basically you need to build your own analyzer with a edge ngram token filter and use this custom analyzer at index time (in the mapping as the `analyzer` for your field). I'd recommend setting a `search_analyzer` in the mapping as well for the same field and set it to `simple`.

I'd also recommend that you use the `_analyze` API to understand what elasticsearch is going to do at index time and at search time.

> [@schawla](#):
>
> ```auto
> new MatchQuery()
> {
> Field = "firstname",
> Query = "Pete Park",
> Boot = 2.0,
> Analyzer = "" ???????
> }
> 
> ```

I'd not use `Analyzer` here.

---

<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 8, 2021, 3:33pm UTC](https://discuss.elastic.co/t/search-multiple-words-using-wildcard-query/272648/7 "2021-06-08T15:33:19Z")

</div>

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