Reputation: 403
I am new to elastic. I am trying to search with the following code, but when I want to get back the word "house", if I type "hou" I can find it , but if I type "ouse" it doesn't work.Also, the analyzer doesn't work.Is this the right place to add it?
var response = client.Search<Homes>(n => n
.Index(index)
.Type(type)
.Size(searchSize)
.From(0)
//.Analyzer(analyzername)
.TrackScores(true)
.Query(q=>q.QueryString(qs=>qs.Query("*"+searchWord+"*")
.Fields(f=>f.Field(fieldsForSearchList[0]))
.Analyzer(analyzername)))
);
Upvotes: 1
Views: 135
Reputation: 403
On index time, it needs Ngram filter, not only EdgeNGram because we need to create sub words not only from the left edge but from different positions of the word.For example the word house will be cutted to [ho,ou,us,se,hou,ous,use,hous,ouse,house]. Allthough it gets much more time on indexing because it creates many more words than the EdgeNGram. With EdgeNGram we get [ho,hou,hous,house].
Upvotes: 0
Reputation: 125538
We don't know if the analyzer works or not as you haven't provided the name of it nor shown what it the analyzer is composed of. Without this information, it's impossible to answer your question :)
There's a couple of points that may help you move in the right direction
.AnalyzeWildcard()
inside the body of .QueryString()
, but I expect you are already analyzing this field at index time with an analyzer that incorporates an edgengram token filter, because you get results back for the partial term "hou"
.reverse
token filter, then an edgengram
filter, followed by another reverse
token filter. You probably want to apply this analyzer and index into a separate multi-field
sub field (maybe call it "reverse"
?) then when searching, search across both the field and sub field, applying a boost to the "forward" field (since people tend to prefix search, but this may be different in your domain).Upvotes: 1