2013-07-24 46 views
0

我剛從0.9.20.6更新了我的巢的NuGet到0.11.1.0的最新版本,現在我得到一個空對象裁判在創建索引之後創建索引。我的代碼沒有改變,但也許從來沒有錯。我也更新了Json.Net到v 5.0.6.2,調用堆棧表明JsonSerializer是它失敗的地方。空對象參考更新到v 0.11.1.0

調用棧是這樣的:

at Nest.Resolvers.Converters.IndexSettingsConverter.<>c__DisplayClass2.b__0(RootObjectMapping m) in c:\Work\NEST\src\Nest\Resolvers\Converters\IndexSettingsConverter.cs:line 113 
at System.Linq.Enumerable.ToDictionaryTSource,TKey,TElement 
at System.Linq.Enumerable.ToDictionaryTSource,TKey 
at Nest.Resolvers.Converters.IndexSettingsConverter.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) in c:\Work\NEST\src\Nest\Resolvers\Converters\IndexSettingsConverter.cs:line 112 
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty) 
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) 
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) 
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) 
at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType) 
at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, Formatting formatting, JsonSerializerSettings settings) 
at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings) 
at Nest.ElasticClient.Serialize(Object object) in c:\Work\NEST\src\Nest\ElasticClient-Statics.cs:line 53 
at Nest.ElasticClient.CreateIndex(String index, IndexSettings settings) in c:\Work\NEST\src\Nest\ElasticClient-CreateIndex.cs:line 18 
... 

這是失敗,因爲一個字段映射具有空TypeNameMarker屬性(參見第一行中的巢源在上面的跡線)。

我創建字段映射手動(從應用中的一些XML定義),因此:

new StringMapping() { Name = fieldname, Index = idx, Store = field.Store }; 

有誰知道爲什麼這種情況已經改變?

UPDATE

下面是我用來創建地圖的完整代碼。您可以看到我已將TypeNameMarker註釋掉,因爲這是0.11的新屬性。

IElasticType createFieldMap(Field field, bool notAnalyzed = false, string fieldname = null) 
    { 
     IElasticType att = null; 

     var idx = notAnalyzed ? FieldIndexOption.not_analyzed : (FieldIndexOption?)Enum.Parse(typeof(FieldIndexOption), field.Index); 
     var nsidx = notAnalyzed ? NonStringIndexOption.not_analyzed : (NonStringIndexOption?)Enum.Parse(typeof(NonStringIndexOption), field.Index); 
     var ft = (FieldType)Enum.Parse(typeof(FieldType), field.Type); 

     fieldname = fieldname ?? field.Name; 

     switch (ft) 
     { 
      case FieldType.string_type: 
       att = new StringMapping() 
       { 
        Name = fieldname, 
        Index = idx, 
        Store = field.Store, 
        //TypeNameMarker = "string" 
       }; 
       if (field.CodeField) 
       { 
        (att as StringMapping).SearchAnalyzer = "keyword"; 
        (att as StringMapping).IndexAnalyzer = "keyword"; 
       } 
       else 
       { 
        (att as StringMapping).SearchAnalyzer = "simple"; 
        (att as StringMapping).IndexAnalyzer = "simple"; 
       } 
       break; 
      case FieldType.binary: 
       att = new BinaryMapping() 
       { 
        Name = fieldname, 
        //TypeNameMarker = "binary" 
       }; 
       break; 
      case FieldType.boolean_type: 
       att = new BooleanMapping() 
       { 
        Name = fieldname, 
        Index = nsidx, 
        Store = field.Store, 
        //TypeNameMarker = "boolean" 
       }; 
       break; 
      case FieldType.date_type: 
       att = new DateMapping() 
       { 
        Name = fieldname, 
        Index = nsidx, 
        Store = field.Store, 
        //TypeNameMarker = "date" 
       }; 
       break; 
      case FieldType.double_type: 
      case FieldType.float_type: 
      case FieldType.integer_type: 
      case FieldType.long_type: 
       att = new NumberMapping() 
       { 
        Name = fieldname, 
        Index = nsidx, 
        Store = field.Store, 
        //TypeNameMarker = "number" 
       }; 
       break; 
     } 
     return att; 
    } 

將每個字段添加到根映射。

var props = new Dictionary<string, IElasticType>(); 

foreach (var field in doc.IndexMap.Fields) 
{ 
    if (!field.Sortable) 
    { 
     props.Add(field.Name, createFieldMap(field)); 
    } 
    else 
    { 
     var mfm = new MultiFieldMapping(); 
     mfm.Name = field.Name; 

     mfm.Fields.Add(field.Name, (IElasticCoreType)createFieldMap(field)); 
     mfm.Fields.Add("sort", (IElasticCoreType)createFieldMap(field, true, "sort")); 

     props.Add(field.Name, mfm); 
    } 
    } 
    rootMap.Properties = props; 

有一個很大的xml文件,其中包含要包含在索引中的字段列表。實際記錄是從SQL返回的,並且該同一個XML文件具有要執行的查詢和一些更改跟蹤信息(使用rowversions)。

+0

我已經恢復到0.90.20.6,它工作正常。 – Jonesie

+0

Hey Jonesie我很想解決這個問題!你可以發佈更多的代碼嗎?您的完整地圖代碼如何以及您使用的POCO究竟是什麼? –

+0

謝謝!見上面的更新。哦,POCO是Dapper從SQL查詢返回的動態對象。 – Jonesie

回答

1

我設法抓住這個bug在failing unit test

實際情況是,如果你使用的.MapFluent()方法是確保設置TypeNameMarker爲你在幕後。如果您手動新的映射對象在IndexSettingsConverter.cs:line 113代碼不降回到正常的.Name

這是現在固定的,我們把它拋出的情況下,更好的異常都.Name.TypeNameMarker失蹤。

+0

真棒,謝謝! – Jonesie