Search multiple words using wildcard query

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

[{ "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 -

new WildCardQuery
     "Field" : "firstname", 
     "Value": enteredTextByUserInSearchBar + "*"
new WildCardQuery
     "Field" : "lastname", 
     "Value": enteredTextByUserInSearchBar + "*"

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.

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:

This might give you an idea.

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

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 -

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

@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

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 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.

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

You have some examples available in the documentation.

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.

I'd not use Analyzer here.

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