@@ -85,6 +85,7 @@ internal RootObjectMapping RootObjectMappingFromAttributes()
8585 using ( var ms = new MemoryStream ( nestedJson . Utf8Bytes ( ) ) )
8686 return this . _elasticSerializer . Deserialize < RootObjectMapping > ( ms ) ;
8787 }
88+
8889 internal ObjectMapping ObjectMappingFromAttributes ( )
8990 {
9091 var json = JObject . Parse ( this . MapFromAttributes ( ) ) ;
@@ -93,6 +94,7 @@ internal ObjectMapping ObjectMappingFromAttributes()
9394 using ( var ms = new MemoryStream ( nestedJson . Utf8Bytes ( ) ) )
9495 return this . _elasticSerializer . Deserialize < ObjectMapping > ( ms ) ;
9596 }
97+
9698 internal NestedObjectMapping NestedObjectMappingFromAttributes ( )
9799 {
98100 var json = JObject . Parse ( this . MapFromAttributes ( ) ) ;
@@ -101,6 +103,7 @@ internal NestedObjectMapping NestedObjectMappingFromAttributes()
101103 using ( var ms = new MemoryStream ( nestedJson . Utf8Bytes ( ) ) )
102104 return this . _elasticSerializer . Deserialize < NestedObjectMapping > ( ms ) ;
103105 }
106+
104107 public string MapFromAttributes ( )
105108 {
106109 var sb = new StringBuilder ( ) ;
@@ -139,7 +142,7 @@ internal void WriteProperties(JsonWriter jsonWriter)
139142 continue ;
140143
141144 var propertyName = this . Infer . PropertyName ( p ) ;
142- var type = GetElasticSearchType ( att , p ) ;
145+ var type = GetElasticsearchTypeName ( att , p ) ;
143146
144147 if ( type == null ) //could not get type from attribute or infer from CLR type.
145148 continue ;
@@ -182,38 +185,37 @@ private void WritePropertiesFromAttribute(JsonWriter jsonWriter, IElasticPropert
182185 }
183186
184187 /// <summary>
185- /// Get the Elastic Search Field Type Related .
188+ /// Gets the Elasticsearch type name for a given ElasticPropertyAttribute .
186189 /// </summary>
187- /// <param name="att ">ElasticPropertyAttribute</param>
188- /// <param name="p ">Property Field </param>
189- /// <returns>String with the type name or null if can not be inferres </returns>
190- private string GetElasticSearchType ( IElasticPropertyAttribute att , PropertyInfo p )
190+ /// <param name="attribute ">ElasticPropertyAttribute</param>
191+ /// <param name="propertyInfo ">Property field </param>
192+ /// <returns>String containing the type name, or null if can not be inferred. </returns>
193+ private string GetElasticsearchTypeName ( IElasticPropertyAttribute attribute , PropertyInfo propertyInfo )
191194 {
192195 FieldType ? fieldType = null ;
193- if ( att != null )
194- {
195- fieldType = att . Type ;
196- }
196+
197+ if ( attribute != null )
198+ fieldType = attribute . Type ;
197199
198200 if ( fieldType == null || fieldType == FieldType . None )
199201 {
200- fieldType = this . GetFieldTypeFromType ( p . PropertyType ) ;
201- if ( fieldType == null && att != null )
202+ fieldType = this . GetFieldType ( propertyInfo . PropertyType ) ;
203+ if ( fieldType == null && attribute != null )
202204 {
203- var message = _noFieldTypeMessage . F ( p . Name , this . _type . Name ) ;
205+ var message = _noFieldTypeMessage . F ( propertyInfo . Name , this . _type . Name ) ;
204206 throw new DslException ( message ) ;
205207 }
206208 }
207209
208- return this . GetElasticSearchTypeFromFieldType ( fieldType ) ;
210+ return this . GetElasticsearchType ( fieldType ) ;
209211 }
210212
211213 /// <summary>
212- /// Get the Elastic Search Field from a FieldType.
214+ /// Gets the Elasticsearch type name for a given FieldType.
213215 /// </summary>
214216 /// <param name="fieldType">FieldType</param>
215- /// <returns>String with the type name or null if can not be inferres </returns>
216- private string GetElasticSearchTypeFromFieldType ( FieldType ? fieldType )
217+ /// <returns>String containing the type name, or null if can not be inferred. </returns>
218+ private string GetElasticsearchType ( FieldType ? fieldType )
217219 {
218220 switch ( fieldType )
219221 {
@@ -231,6 +233,10 @@ private string GetElasticSearchTypeFromFieldType(FieldType? fieldType)
231233 return "string" ;
232234 case FieldType . Integer :
233235 return "integer" ;
236+ case FieldType . Short :
237+ return "short" ;
238+ case FieldType . Byte :
239+ return "byte" ;
234240 case FieldType . Long :
235241 return "long" ;
236242 case FieldType . Float :
@@ -255,11 +261,11 @@ private string GetElasticSearchTypeFromFieldType(FieldType? fieldType)
255261 }
256262
257263 /// <summary>
258- /// Inferes the FieldType from the type of the property .
264+ /// Gets the FieldType for a given CLR type .
259265 /// </summary>
260- /// <param name="propertyType">Type of the property</param>
261- /// <returns>FieldType or null if can not be inferred</returns>
262- private FieldType ? GetFieldTypeFromType ( Type propertyType )
266+ /// <param name="propertyType">CLR type of the property</param>
267+ /// <returns>The FieldType, or null if can not be inferred. </returns>
268+ private FieldType ? GetFieldType ( Type propertyType )
263269 {
264270 propertyType = GetUnderlyingType ( propertyType ) ;
265271
@@ -274,8 +280,16 @@ private string GetElasticSearchTypeFromFieldType(FieldType? fieldType)
274280 switch ( propertyType . Name )
275281 {
276282 case "Int32" :
283+ case "UInt32" :
277284 return FieldType . Integer ;
285+ case "Int16" :
286+ case "UInt16" :
287+ return FieldType . Short ;
288+ case "Byte" :
289+ case "SByte" :
290+ return FieldType . Byte ;
278291 case "Int64" :
292+ case "UInt64" :
279293 return FieldType . Long ;
280294 case "Single" :
281295 return FieldType . Float ;
0 commit comments