Elastic-nest.Search with analyzer不起作用。它无法检测分析仪

时间:2017-03-22 09:14:56

标签: c# elasticsearch nest

我正在使用带有嵌套的弹性用于c#。我在索引时创建分析器,但在搜索时它们不起作用。搜索查询不返回任何文档。

这是我的班级

public class Car {
   Text(Analyzer = "greek",SearchAnalyzer ="custom",Index = true,IncludeInAll = true)]
   public string SERVICE_DESC { get; set; }
}

这是我的搜索查询

var response = client.Search<Cars>(n => n
   .Index(index)
   .Type(type)
   .Size(searchSize)
   .From(0)
   .TrackScores(true)
   .Query(q => q
   .Match(qs => qs.Field(fieldsForSearchList[0]).Analyzer("custom")
   .Operator(Operator.And).Query("*"+searchWord+"*"))));

正如我所提到的,我已经创建了两个分析器(“greek”,“custom”)

var response = client.CreateIndex(index, s => s.Settings(s1 => s1.NumberOfShards(5)
  .NumberOfReplicas(5)
  .Analysis(a => a.TokenFilters(t => t
  .IcuTransform("greeklatin", it => it.Id("Greek-Latin; NFD; [:NonspacingMark:] Remove; NFC")//
  .Drection(IcuTransformDirection.Forward)) //
  .IcuTransform("latingreek", lg => lg.Id("Greek-Latin; NFD; [:Nonspacing Mark:] Remove; NFC")
  .Direction(IcuTransformDirection.Reverse))
  .EdgeNGram("greekedge", ed => ed.MaxGram(50)
  .MinGram(1)
  .Side(EdgeNGramSide.Front))
  .Stop("greekstop", sw => sw.StopWords())
  .Lowercase("greeklowercase", gl => gl.Language(Language.Greek.ToString()))
  .KeywordMarker("greekkeywords", gk => gk.Keywords("")).Stemmer("greekstemmer", gs => gs.Language(Language.Greek.ToString())))
  .CharFilters(ma => ma.Mapping("hmap", map => map.Mappings("h=>η"))).Analyzers(a1 => a1.Custom("greek", t =>t.Tokenizer("standard").Filters("greekedge",/* "greekstop",*/ "greeklowercase", "greekkeywords",/*"greekstemmer",*/ "greeklatin", "latingreek")
  .CharFilters("hmap")) .Custom("custom", cu => cu.Tokenizer("standard").Filters(/*"greekstop",*/ "greeklowercase", "greekkeywords",/* "greekstemmer" ,*/ "greeklatin", "latingreek")
  .CharFilters("hmap"))))));

1 个答案:

答案 0 :(得分:0)

我不知道为什么,但是当你用弹性来映射字段时,它往往会小写它们的第一个字符。例如,当我以前添加字段“SERVICE”时,它会自动转换为“sERVICE”等等。所以至少第一个字符必须在我们班级的映射和字段声明中小写。