2014-01-07 80 views
0

我需要得到下面的結果與NEST(彈性搜索.NET客戶端)如何設置IndexOption =文檔

"detailVal": { 
    "name": "detailVal", 
    "type": "multi_field", 
    "fields": { 
     "detailVal": { 
      "type": "string" 
     }, 
     "untouched": {    // <== FOCUS 2 
      "type": "string", 
      "index": "not_analyzed", 
      "omit_norms": true, 
      "include_in_all": false, 
      "index_options": "docs" // <== FOCUS 1 
     } 
    } 
} 

我已經做了迄今爲止

[ElasticProperty(OmitNorms = true, Index = FieldIndexOption.not_analyzed, IncludeInAll = false, AddSortField = true)] 
    public string DetailVal { get; set; } 

這讓我

"detailVal": { 
    "name": "detailVal", 
    "type": "multi_field", 
    "fields": { 
     "detailVal": { 
      "type": "string", 
      "index": "not_analyzed", 
      "omit_norms": true, 
      "include_in_all": false 
     }, 
     "sort": {     // <== FOCUS 2 
      "type": "string", 
      "index": "not_analyzed" 
     } 
    } 
} 

所以,任何想法如何

  1. 添加「index_options」: 「文檔」(我發現IndexOptions.docs,但它並不像屬性有效)
  2. 變化排序不變

回答

0

基於屬性映射只讓你如此遙遠。如果您只需要更改名稱並設置簡單的屬性就足夠了。

建議的方法是使用client.MapFluent()

https://github.com/Mpdreamz/NEST/blob/master/src/Nest.Tests.Unit/Core/Map/FluentMappingFullExampleTests.cs#L129

舉一個例子如何設置index_options

和線路208: https://github.com/Mpdreamz/NEST/blob/master/src/Nest.Tests.Unit/Core/Map/FluentMappingFullExampleTests.cs#L208

要了解如何創建自己的多場映射。

你甚至可以結合這兩種方法:

client.MapFluent<MyType>(m=>m 
    .MapFromAttributes() 
    //Map what you can't with attributes here 
); 

client.Map()client.MapFromAttributes()將最有可能在某個時候被移除。

+0

@ martjin-laaman謝謝!我已經意識到流暢的語法,但我不想爲這兩個問題放棄屬性方法。再次感謝您的時間! – cilerler

+1

您可以同時執行這兩個操作,在MapFluent()內調用MapFromAttributes(),然後僅映射其他方法。 –