Creating a custom analyzer in ElasticSearch Nest client
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的更多相关文章
- Elasticsearch .net client NEST 5.x 使用总结
目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异 Elastics ...
- Elasticsearch .Net Client NEST使用说明 2.x
Elasticsearch .net client NEST使用说明 2.x Elasticsearch.Net与NEST是Elasticsearch为C#提供的一套客户端驱动,方便C#调用Elast ...
- Elasticsearch .Net Client NEST 多条件查询示例
Elasticsearch .Net Client NEST 多条件查询示例 /// <summary> /// 多条件搜索例子 /// </summary> public c ...
- Elasticsearch .net client NEST使用说明 2.x -更新版
Elasticsearch .net client NEST使用说明 目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_cl ...
- 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 ...
- ElasticSearch NEST笔记
ElasticSearch NEST笔记 1. 什么是ElasticSearch? ElasticSearch is a powerful open source search and analyti ...
- 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 ...
- Elasticsearch NEST – Examples for mapping between Query and C#
Elasticsearch NEST – Examples for mapping between Query and C# During my training with Elasticsearch ...
- Elasticsearch Java Client连接池
按照Elasticsearch API,在Java端使用是ES服务需要创建Java Client,但是每一次连接都实例化一个client,对系统的消耗很大,即使在使用完毕之后将client close ...
随机推荐
- linux 同步IO: sync、fsync与fdatasync
[linux 同步IO: sync.fsync与fdatasync] 传统的UNIX实现在内核中设有缓冲区高速缓存或页面高速缓存,大多数磁盘I/O都通过缓冲进行.当将数据写入文件时,内核通常先将该数据 ...
- 138. Copy List with Random Pointer (Graph, Map; DFS)
A linked list is given such that each node contains an additional random pointer which could point t ...
- 使screen支持滚动
在Linux中,常用的串口工具有minicom和screen,minicom可能使用得比较多,但是我比较喜欢screen,因为它的输出是彩色的,更舒服.更能突出重点. 使用screen来打开串口也非常 ...
- python在windows环境安装MySQLdb
一.环境 系统:win7,64位 python版本:2.7.15 pip版本:10.0.1 二.安装 1. 用pip安装 pip install MySQLdb 报错: Could not find ...
- ubuntu开机执行指令或脚本
vi /etc/rc.d/rc.localz 将指令添加到exit 0之前,保存.
- [Training Video - 2] [Groovy Introduction]
Building test suites, Test cases and Test steps in SOAP UI Levels : test step level test case level ...
- 为什么都说UX / UI设计师是最佳工作?
以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具. 你将成为永远热爱自己工作的人,做着自己喜欢的工作还能得到相应的成果和报酬,就好似在度带薪年假一般,何 ...
- Java线程死锁查看分析方法
如何查看是否有Java线程死锁?下面介绍两种方法. 一.Jconsole Jconsole是JDK自带的图形化界面工具,使用JDK给我们的的工具JConsole,可以通过打开cmd然后输 ...
- 安装wampserver后,在www文件夹下面写php文件,而在网页里输入localhost而无法打开php文件时解决办法汇总
wampserver安装后,在www文件夹下面写入xx.PHP文件,然后在网页里输入localhost:xx.PHP. 你可能会遇到如下三种情况: 情形一:网页上显示空白,按F12,出现404的错误. ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'easylabdb.userInfo' doesn't exist
这个问题主要是说,你查找的表不存在,但是,事实上我这个表示存在的,会产生这个问题的原因是,我这个表的大小写拼写方式跟sql语句中的大小写不一样,这时就要设置数据库不区分大小写 找到mysql的配置文件 ...