小编yal*_*_cu的帖子

在ElasticSearch Nest客户端中创建自定义分析器

我使用nest客户端对弹性搜索非常新,我使用自定义分析器创建索引,但是当使用analyze进行测试时,它似乎不使用自定义分析器.主要没有出现edgengram标记.我有什么遗漏会使我的自定义分析器成为索引的默认值吗?当我使用elastichq检查我的映射时,它们会显示我的自定义分析器.

ConnectionSettings settings = new ConnectionSettings(new Uri("http://localhost:9200"),    defaultIndex: "forum-app");

 IndexSettings indsettings = new IndexSettings();

   var an = new CustomAnalyzer();

   an.CharFilter = new List<string>();
   an.CharFilter.Add("html_strip");
   an.Tokenizer = "edgeNGram";
   an.Filter = new List<string>();
   an.Filter.Add("standard");
   an.Filter.Add("lowercase");
   an.Filter.Add("stop");

indsettings.Analysis.Tokenizers.Add("edgeNGram", new Nest.EdgeNGramTokenizer
{
    MaxGram = 15,
    MinGram = 3
});

indsettings.Analysis.Analyzers.Add("forumanalyzer", an);

ElasticClient client = new ElasticClient(settings);

client.CreateIndex("forum-app", c => c
.NumberOfReplicas(0)
.NumberOfShards(1)
.AddMapping<Forum>(e => e.MapFromAttributes())
.Analysis(analysis => analysis
.Analyzers(a => a
.Add("forumanalyzer", an) 
)));        

//To index I just do this       
client.Index(aForum);
Run Code Online (Sandbox Code Playgroud)

elasticsearch nest

4
推荐指数
1
解决办法
6588
查看次数

标签 统计

elasticsearch ×1

nest ×1