Creating a custom analyzer in ElasticSearch Nest client

Question: Im very very new to elasticsearch using the nest client, I am creating an index with a custom analyzer, however when testing using analyze it does not seem to use the custom analyzer. Mainly no edgengram tokens appear. Is there anything I am missing that would make my custom analyser the default for the index? When I check my mappings using elastichq they show my custom analyzer.

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);

Answer

You've added your custom analyzer to your index, but now you need to apply it your fields. You can do this on a field mapping level:

client.CreateIndex("forum-app", c => c
.NumberOfReplicas(0)
.NumberOfShards(1)
.AddMapping<Forum>(e => e
.MapFromAttributes()
.Properties(p => p
.String(s => s.Name(f => f.SomeProperty).Analyzer("formanalyzer")))
)
.Analysis(analysis => analysis
.Analyzers(a => a
.Add("forumanalyzer", an)
)
)
);

Or you can apply it to all fields by default by setting it as the default analyzer of your index:

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

More info here in regards to analyzer defaults.

源文:https://stackoverflow.com/questions/25193800/creating-a-custom-analyzer-in-elasticsearch-nest-client

Creating a custom analyzer in ElasticSearch Nest client的更多相关文章

  1. Elasticsearch .net client NEST 5.x 使用总结

    目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异 Elastics ...

  2. Elasticsearch .Net Client NEST使用说明 2.x

    Elasticsearch .net client NEST使用说明 2.x Elasticsearch.Net与NEST是Elasticsearch为C#提供的一套客户端驱动,方便C#调用Elast ...

  3. Elasticsearch .Net Client NEST 多条件查询示例

    Elasticsearch .Net Client NEST 多条件查询示例 /// <summary> /// 多条件搜索例子 /// </summary> public c ...

  4. Elasticsearch .net client NEST使用说明 2.x -更新版

    Elasticsearch .net client NEST使用说明 目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_cl ...

  5. elasticsearch系列七:ES Java客户端-Elasticsearch Java client(ES Client 简介、Java REST Client、Java Client、Spring Data Elasticsearch)

    一.ES Client 简介 1. ES是一个服务,采用C/S结构 2. 回顾 ES的架构 3. ES支持的客户端连接方式 3.1 REST API ,端口 9200 这种连接方式对应于架构图中的RE ...

  6. ElasticSearch NEST笔记

    ElasticSearch NEST笔记 1. 什么是ElasticSearch? ElasticSearch is a powerful open source search and analyti ...

  7. Elasticsearch Java client(ES Client 简介、Java REST Client、Java Client、Spring Data Elasticsearch)

    elasticsearch系列七:ES Java客户端-Elasticsearch Java client(ES Client 简介.Java REST Client.Java Client.Spri ...

  8. Elasticsearch NEST – Examples for mapping between Query and C#

    Elasticsearch NEST – Examples for mapping between Query and C# During my training with Elasticsearch ...

  9. Elasticsearch Java Client连接池

    按照Elasticsearch API,在Java端使用是ES服务需要创建Java Client,但是每一次连接都实例化一个client,对系统的消耗很大,即使在使用完毕之后将client close ...

随机推荐

  1. k8s gpu 资源设置

    将所有相同型号显卡的node打上 相同的label kubectl label node ogs-gpu02 gpu_type=k20m 启动device plugin 和app 时: nodeSel ...

  2. 第七章 二叉搜索树 07B2-1 插入:算法

  3. linux shell脚本编程笔记(四): 获取字符串长度的七种方法

    获取字符串长度的七种方法 1. \${#str} 2.awk的length 备注:1) 最好用{}来放置变量2) 也可以用length($0)来统计文件中每行的长度 3.awk的NF 备注: -F为分 ...

  4. 38.Count and Say 报数

    [抄题]: The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 1 ...

  5. 利率计算v5.0--结对--软件工程

    利率计算v5.--测试--软件工程 1.任务结对同伴: 名字:王昕明 学号: 博客地址 :http://home.cnblogs.com/u/xinmingwang/ Git : https://gi ...

  6. 生物信息学——RNA的剪切过程

    生物信息学——RNA的剪切过程   外显子(exon expressed region)是真核生物基因的一部分,它在剪接(Splicing)后仍会被保存下来,并可在蛋白质生物合成过程中被表达为蛋白质. ...

  7. ORACLE DBLINK 使用

    CREATE PUBLIC DATABASE LINK MYDBLINK CONNECT TO RAMS IDENTIFIED BY RAMS USING '(DESCRIPTION =(ADDRES ...

  8. (二分搜索 )Strange fuction -- HDU -- 2899

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=2899 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  9. 3、Docker能干什么?

    简化配置   这是Docker公司宣传的Docker的主要使用场景.虚拟机的最大好处是能在你的硬件设施上运行各种配置不一样的平台(软件.系统),Docker在降低额外开销的情况下提供了同样的功能.它能 ...

  10. 咏南CS开发框架新的界面风格

    咏南CS开发框架新的界面风格 这种风格完全和WINDOWS桌面一样,符合用户的操作习惯. 我的桌面的图标和WINDOWS桌面一样分为二类:1)快捷方式  2)文件夹. 如果快捷方式较多,看得人眼花缭乱 ...