2017-07-27 63 views
0

我试图通过Nest 5.5.0设置“not_analyzed”索引类型,我不知道如何去做。为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); 

和项目类:

[ElasticsearchType(Name = "project")] 
public class Project 
{ 
    public Guid Id { get; set; } 
    [Text(Analyzer = "not_analyzed")] 
    public string OwnerIdCode { get; set; } 
} 

的init这种方式产生了一些很怪的映射后,我通过邮差调用索引/ _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 
                 } 
(...) 

回答

1

要设置不分析字符串字段内Elasticsearch 5.0+,你应该使用keyword type,并通过映射或者在创建索引的时间与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财产也应标明。

+0

非常感谢!我只是无法弄清楚如何通过使用“入门”文档来应对初始化。 ;) – mikes