bastimm
bastimm

Reputation: 343

Elasticsearch autosuggest

a newbie to ES needs helping hands for the Suggester.... I made a simple index with some titles like "Manufacturer product name mpn":

My current Mapping:

'suggest'=> [
'=> 'completion'
'=> 'simple'
' => false
]

my current Query:

'body' => [
'suggest' => [
'text' => $this->query
, 'completion' => [
'field' => 'suggest'
]]]

Now if I try to Suggest it works, but results are very ugly.... Perhaps somebody can help me to find the right settings:

e.g. a title is: "Xoar Electric Beechwood Precision"

Now i want this results for Queries:

"X" => "Xoar"
"Yoar E" => "Xoar", "Xoar Electric"
"El" => "Electric"
"Elektric " => "Electric", "Electric Beechwood"

At the moment it only returns the full title if I type "X...."

Is this possible? And if yes, how can i try to get this results?

THANKS in advance!

Upvotes: 0

Views: 144

Answers (2)

Rajat Chaudhary
Rajat Chaudhary

Reputation: 180

You should use ngrams approach i.e. tokenize your words by splitting them with space character or what suits your use case the most. Then index each token with the suggest analyzer.

For ex:

Split "Xoar Electric Beechwood Precision" like this

  • "Xoar Electric Beechwood Precision"
  • "Electric Beechwood Precision"
  • "Beechwood Precision"
  • "Precision"

And then use the prefix query. For auto-correcting, you may use fuzziness parameter.

Hope this helps.

Upvotes: 0

maximus ツ
maximus ツ

Reputation: 8065

You need to change default tokenizer and analyzer to fetch related documents from elasticsearch.

Check below links for more details which talks about how to handle human language and typo corrections,

Human Languages with elasticsearch

Fuzzy matching with elasticsearch

Upvotes: 0

Related Questions