Why is the boolean fuzzy query in elasticsearch not returning results


Question: Why is the boolean #fuzzy query in elastic search not returning results?


Login to See the Rest of the Answer

Answer: If you are using the #NEST #ElasticSearch library in #Asp.Net Core C# Application, the field you are trying to query using a Fuzzy boolean query should be of the type "Keyword". When you index your data into Elastic Search there are types you set to let Elastic #Search index the data and chunk it appropriately.

However, if your data was indexed using #Dynamic Indexing where Elastic Search figures out what the type of that specific data field is, then the Fuzzy #query will work if you pass in one single word as a query. Keep in mind that this word should not contain any characters like (" or, or + or % or &) otherwise it won't work. See the code below:

string query = OriginalQuery.Replace("-", " ").Replace("%", " ").Replace("?", " ").Replace("#", " ").Replace(":", "").Replace("<", "").Replace(">", "").Replace("+", "");
var response = await _elasticClient.SearchAsync<POCO>
             (s => s.Query(q => q.Fuzzy(b =>
             b.Field(k => k.MyFieldToQueryOn)
            .Value(query)
            .Fuzziness(Fuzziness.Auto)
            .MaxExpansions(1000000)

             )
        ).Sort(a => a.Descending(k => k.Score)))
                              .ConfigureAwait(false);



If this helped you leave a comment below.






© 2024 - ErnesTech - Privacy
E-Commerce Return Policy