2017-07-25 69 views
1

我试图让nGram过滤器使用模糊搜索,但它不会。具体来说,我试图让“粗鲁”匹配“粗糙”。是否可以使用nGram模糊搜索?

我不知道这是不可能的,或者它是可能的,但我已经定义了映射错误,或者映射没问题,但是我的搜索没有正确定义。

映射:

{ 
    settings = new 
     { 
      index = new 
      { 
       number_of_shards = 1, 
       number_of_replicas = 1, 

       analysis = new 
       { 
        filter = new 
        { 
         edge_ngram_filter = new 
         { 
          type = "nGram", 
          min_gram = 3, 
          max_gram = 8 
         } 
        }, // filter 

        analyzer = new 
        { 
         analyzer_ngram = new 
         { 
          type = "custom", 
          tokenizer = "standard", 
          filter = new string[] 
          { 
           "lowercase", 
           "edge_ngram_filter" 
          } 
         } 
        } // analyzer 

       } // analysis 

      } // index 
     }, // settings 

    mappings = new 
    { 
     j_cv = new 
     { 
      properties = new 
      { 
       Text = new 
       { 
        type = "text", 
        include_in_all = false, 
        analyzer = "analyzer_ngram", 
        search_analyzer = "standard" 
       } 
      } 
     } // j_cv 
    } // mappings 
} 

文件:

{ 
    Id = Guid.NewGuid(), 
    Name = "Jimmy Riddle", 
    Keyword = new List<string>(new string[] { "Hunting", "High", "Hotel", "California" }), 
    Text = "Rough Justice was a program on BBC some years ago. It was quite interesting. Will this match?" 
} 

搜索:

{ 
    query = new 
    { 
     query_string = new 
     { 
      fields = new string[] { "Text" }, 
      fuzziness = "3", 
      query = "rugh" 
     } 
    } 
} 

顺便说一句, “哎” 确实匹配这是你所期望的东西。

感谢您的任何帮助,您可以给,

亚当。

回答

0

相同的分析仪通常应用在索引和搜索时间,所以search_analyzer=standard是错误的,它应该工作,如果你删除它。 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html

编辑: 您在您的查询忘记模糊运算符“〜”,如果你将它添加到“rugh”很有效!

+0

感谢Martin的回应,但如果我这样做,我会得到误报。例如,“xxxxrest”命中是因为我假设搜索文本被分解为ngram,其中一个或多个匹配索引中“interest”的ngrams。我想要“休息”击中“兴趣”,它与旧的配置。但是我无法使模糊搜索工作,所以“rst”不会出现。 –

+0

@AdamBenson您在查询中忘记了模糊运算符“〜”,那么它就起作用了! – MartinSchulze

+0

嗯......在文档中找不到。请问这是从哪里来的? –