我试图通过Nest 5.5.0设置“ not_analyzed”索引类型,但我不知道该怎么做。
我的初始化:
var map = new CreateIndexDescriptor(INDEX_NAME) .Mappings(ms => ms.Map<Project>(m => m.AutoMap())); var connectionSettings = new ConnectionSettings().DefaultIndex(INDEX_NAME); _client = new ElasticClient(connectionSettings); _client.Index(map);
和Project类:
[ElasticsearchType(Name = "project")] public class Project { public Guid Id { get; set; } [Text(Analyzer = "not_analyzed")] public string OwnerIdCode { get; set; } }
在我通过Postman调用index / _mapping REST之后,这种初始化方式会创建某种奇怪的映射。在普通的“映射” JSON部分中,紧挨着“ createindexdescriptor”,具有几乎相同的数据。
"examinations4": { "mappings": { "project": { (...) }, "createindexdescriptor": { "properties": { "mappings": { "properties": { "project": { "properties": { "properties": { "properties": { "id": { "properties": { "type": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "ownerIdCode": { "properties": { "analyzer": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "type": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } (...)
要在Elasticsearch 5.0+中设置未分析的字符串字段,您应该使用keyword类型,并在创建索引时使用CreateIndex()或在使用将第一个文档发送到索引之前传递映射Map<T>()。就您而言,我认为您正在寻找类似的东西
keyword
CreateIndex()
Map<T>()
void Main() { var connectionSettings = new ConnectionSettings() .DefaultIndex("default-index"); var client = new ElasticClient(connectionSettings); client.CreateIndex("projects", c => c .Mappings(m => m .Map<Project>(mm => mm .AutoMap() ) ) ); } [ElasticsearchType(Name = "project")] public class Project { [Keyword] public Guid Id { get; set; } [Keyword] public string OwnerIdCode { get; set; } }
我认为该Id属性也应标记为关键字类型。
Id