ElasticsearchCRUD使用(十二)【Elasticsearch的German分析器】
2017-05-11 22:44
405 查看
本文介绍如何使用Elasticsearch的默认德语分析器。 创建使用ElasticsearchCRUD的索引,它使用德语分析器对搜索和索引进行映射。
可以通过在ElasticsearchString属性中定义
然后使用映射创建索引:
现在可以将一些数据添加到索引中。
如果将查询搜索发送到此索引和类型,则使用德语分析器中的词条,并找到所有不同的
这可以检查如下:
查询搜索发送如下:
搜索返回4个不同的结果,这与我们添加的数据相匹配。 这就是我们的期望:
使用ElasticsearchCRUD在Elasticsearch中使用内置语言分析器非常简单。 存在不同的博客,解释如何使用不同配置的不同
可以通过在ElasticsearchString属性中定义
Analyzer属性来使用德语分析器。 此属性为搜索和索引添加分析器。 该属性可以使用任何字符串,因此也可以定义自定义分析器。
Fields属性也被设置。 这被使用,以便原始字符串也可以用于搜索。
Fields属性使用
Type,该类可以定义该字段的子映射。
public class GermanData { public long Id { get; set; } public string Name { get; set; } public string FamilyName { get; set; } [ElasticsearchString(Fields = typeof(FieldDataDefinition), Analyzer=LanguageAnalyzers.German)] public string Info { get; set; } } public class FieldDataDefinition { [ElasticsearchString(Index=StringIndex.not_analyzed)] public string Raw { get; set; } }
然后使用映射创建索引:
_context.IndexCreate<GermanData>(indexDefinition);
现在可以将一些数据添加到索引中。
public void CreateSomeMembers() { var jm = new GermanData {Id = 1, FamilyName = "Moore", Info = "Muenich", Name = "John"}; _context.AddUpdateDocument(jm, jm.Id); var jj = new GermanData { Id = 2, FamilyName = "Jones", Info = "Münich", Name = "Johny" }; _context.AddUpdateDocument(jj, jj.Id); var pm = new GermanData { Id = 3, FamilyName = "Murphy", Info = "Munich", Name = "Paul" }; _context.AddUpdateDocument(pm, pm.Id); var sm = new GermanData { Id = 4, FamilyName = "McGurk", Info = "munich", Name = "Séan" }; _context.AddUpdateDocument(sm, sm.Id); var sob = new GermanData { Id = 5, FamilyName = "O'Brien", Info = "Not a much use, bit of a problem", Name = "Sean" }; _context.AddUpdateDocument(sob, sob.Id); var tmc = new GermanData { Id = 6, FamilyName = "McCauley", Info = "Couldn't a ask for anyone better", Name = "Tadhg" }; _context.AddUpdateDocument(tmc, tmc.Id); _context.SaveChanges(); }
如果将查询搜索发送到此索引和类型,则使用德语分析器中的词条,并找到所有不同的
Munich类型。
Munich, Münich, Muenich和
munich都被索引,这些被保存为
munich词条。
这可以检查如下:
http://localhost:9200/germandatas/_analyze?&analyzer=german&text=Muenich munich Münich Munich
查询搜索发送如下:
POST http://localhost:9200/germandatas/germandata/_search HTTP/1.1 Content-Type: application/json Host: localhost:9200 Content-Length: 46 Expect: 100-continue { "query": { "match": {"info": "Muenich"} } }
搜索返回4个不同的结果,这与我们添加的数据相匹配。 这就是我们的期望:
HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Content-Length: 703 { "took":1,"timed_out":false,"_shards":{ "total":5,"successful":5,"failed":0},"hits":{ "total":4,"max_score":1.0,"hits":[ {"_index":"germandatas","_type":"germandata","_id":"1","_score":1.0,"_source":{"id":1,"name":"John","familyname":"Moore","info":"Muenich"}}, {"_index":"germandatas","_type":"germandata","_id":"4","_score":0.30685282,"_source":{"id":4,"name":"Séan","familyname":"McGurk","info":"munich"}}, {"_index":"germandatas","_type":"germandata","_id":"2","_score":0.30685282,"_source":{"id":2,"name":"Johny","familyname":"Jones","info":"Münich"}}, {"_index":"germandatas","_type":"germandata","_id":"3","_score":0.30685282,"_source":{"id":3,"name":"Paul","familyname":"Murphy","info":"Munich"}} ] } }
使用ElasticsearchCRUD在Elasticsearch中使用内置语言分析器非常简单。 存在不同的博客,解释如何使用不同配置的不同
German分析仪。 这些也可以在ElasticsearchCRUD中配置为自定义分析器。 我没有对所有不同分析仪进行系统比较,以说哪一种更适合用于不同类型的数据。
相关文章推荐
- ElasticsearchCRUD使用(九)【Elasticsearch父子,孙子节点文件和路由】
- ElasticsearchCRUD使用(十四)【ElasticsearchCRUD搜索查询和过滤】
- Elasticsearch(二)【Elasticsearch.Net基本使用】
- ElasticSearch ik,elasticsearch-jdbc 使用 和 yii2 实例
- SpringBoot项目通过 spring data elasticsearch使用elasticsearch
- ElasticSearch学习13_ElasticSearch RESTful搜索引擎_Java Jest使用入门
- ElasticsearchCRUD使用(十五)【批量插入数据】
- [增删改查] SpringBoot 整合 ElasticSearch 之 ElasticsearchRepository 的 CRUD、分页接口
- ElasticsearchCRUD使用(十一)【Elasticsearch同义词分析器】
- 使用elasticsearch,Elasticsearch Scripts disabled
- Elasticsearch——使用_cat查看Elasticsearch状态
- elasticsearch-1.5.2生产环境配置文件(Elasticsearch.xml)集群配置
- 使用logstash+elasticsearch+kibana快速搭建日志平台
- 使用ELK(Elasticsearch + Logstash + Kibana) 搭建日志集中分析平台实践
- elasticsearch的研究与使用(二)Search API
- 【转载】使用logstash+elasticsearch+kibana快速搭建日志平台
- Centos7下使用ELK(Elasticsearch + Logstash + Kibana)搭建日志集中分析平台
- 使用 ElasticSearch + LogStash + Kibana 来可视化网络流量
- 使用Logstash + Elasticsearch作为大数据索引、分析工具
- ELK学习3_使用redis+logstash+elasticsearch+kibana快速搭建日志平台