mik*_*kes 5 c# mapping elasticsearch nest elasticsearch-analyzers
我试图通过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);
Run Code Online (Sandbox Code Playgroud)
而Project类:
[ElasticsearchType(Name = "project")]
public class Project
{
public Guid Id { get; set; }
[Text(Analyzer = "not_analyzed")]
public string OwnerIdCode { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在通过Postman调用索引/ _mapping REST之后,这种init方式会创建某种奇怪的映射.有正常的"映射"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
}
(...)
Run Code Online (Sandbox Code Playgroud)
要在Elasticsearch 5.0+中设置未分析的字符串字段,您应该使用该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; }
}
Run Code Online (Sandbox Code Playgroud)
我认为该Id
属性也应该被标记为关键字类型.