E lastic搜索搜索词以" s"结尾没有给出任何结果

时间:2017-01-04 10:31:07

标签: c#-4.0 elasticsearch nest

我现在正在使用Elastic很长一段时间,我第一次面对这个问题,这里的问题我有一个特定的关键字,以" s"这不会返回确切的结果,如果我正在搜索

 Case1 :
 Search Term :  "domino" - > getting results
                results : {"dominos","Food","Snacks"}

 Case2: 
 Search Term :  "dominos" - >
                results : { "Food","Snacks"}

               Expected results: {"dominos","Food","Snacks"}

 this is the raw query that I am using to get the results 

  {
      "size": 1000,
      "query": {
                 "query_string": {
                        "query": "*dominos*",
                       "fields": [
                                 "categoryName^6",
                                 "alterNames",
                                 "categoryDescription",
                                 "categoryNameNotAnalyzed^4"
                                 ]
                                }
                },"explain": true
   }


 below are my index settings

           var createIndexResult = elasticClient.CreateIndex(indexName, c => c
                                                 .AddMapping<T>(tmd => tmd.MapFromAttributes())
                                                 .Analysis(an => an.TokenFilters(tf => tf.Add("stopfilter", stopFilter))
                                                 .Analyzers(a => a.Add("query_analyser", query_analyser)))
                                                 .Settings(s => s.Add("analysis.analyzer", "str_index_analyser")
                                                                 .Add("analysis.analyzer.str_index_analyser.type", "custom")
                                                                 .Add("analysis.analyzer.str_index_analyser.tokenizer", "whitespace")
                                                                 .Add("analysis.analyzer.str_index_analyser.filter.0", "lowercase")
                                                                 .Add("analysis.analyzer.str_index_analyser.filter.1", "kstem")
                                                                 .Add("analysis.analyzer.str_index_analyser.filter.2", "stopfilter")
                                                                 .Add("analysis.filter.substring.type", "edgeNGram")
                                                                 .Add("analysis.filter.substring.min_gram", "3")
                                                                 .Add("analysis.filter.substring.max_gram", "25")
                                                                 .Add("analysis.filter.substring.token_chars.0", "letter")
                                                                 .Add("analysis.filter.substring.token_chars.1", "digit")
                                                                 .Add("merge.policy.merge_factor", "25")
                                                                 .Add("search.slowlog.threshold.fetch.warn", "1s")
                                                             ));

请允许任何人帮助我

1 个答案:

答案 0 :(得分:0)

您是否尝试明确指定分析器:

{
      "size": 1000,
      "query": {
                 "query_string": {
                       "analyzer":"str_index_analyser",
                       "query": "*dominos*",
                       "fields": [
                                 "categoryName^6",
                                 "alterNames",
                                 "categoryDescription",
                                 "categoryNameNotAnalyzed^4"
                                 ]
                                }
                },
"explain": true
   }