2017-07-27 55 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