protected string CreateMapFor(Type t) { var type = new TypeNameResolver().GetTypeNameFor(t); var writer = new TypeMappingWriter(t, type); return(writer.MapFromAttributes()); }
public void No_mapping_attributes_should_result_in_noop() { var sb = new StringBuilder(); Assert.False(TypeMappingWriter.WritePropertyMappingsFor <File>(sb)); Assert.False(TypeMappingWriter.WritePropertyMappingsFor <FileWithEmptyAtts>(sb)); }
protected string CreateMapFor(Type t) { var type = new TypeNameResolver().GetTypeNameFor(t); var writer = new TypeMappingWriter(t, type, TestElasticClient.Settings, 10); return(writer.MapFromAttributes()); }
public void Get_mapping_generates_correct_json() { var sb = new StringBuilder(); Assert.True(TypeMappingWriter.GetMappingFor <FileWithOneAtt>(sb, "test")); Assert.Equal(@"{""test"":{""properties"":{""file_type"":{""type"":""string""}}}}", sb.ToString()); sb.Length = 0; Assert.True(TypeMappingWriter.GetMappingFor <FileWithTwoAtts>(sb, "test")); Assert.Equal(@"{""test"":{""properties"":{""FileType"":{""type"":""string"",""index"":""not_analyzed""},""Size"":{""type"":""integer""}}}}", sb.ToString()); }
public void Mapping_attributes_generates_correct_json() { var sb = new StringBuilder(); Assert.True(TypeMappingWriter.WritePropertyMappingsFor <FileWithOneAtt>(sb)); Assert.Equal(@"{""file_type"":{""type"":""string""}}", sb.ToString()); sb.Length = 0; Assert.True(TypeMappingWriter.WritePropertyMappingsFor <FileWithTwoAtts>(sb)); Assert.Equal(@"{""FileType"":{""type"":""string"",""index"":""not_analyzed""},""Size"":{""type"":""integer""}}", sb.ToString()); }
public static async Task PutMappingFor <T>(this ElasticsearchClient client, string[] indexNames) { var typeName = TypeMappingWriter.GetMappingTypeNameFor <T>(); // We are only going to do a put mapping if there are attributes asking for it var sb = new StringBuilder(); if (TypeMappingWriter.GetMappingFor <T>(sb, typeName)) { await PutMapping(client, indexNames, typeName, sb.ToString()); } }
/// <summary> /// Convenience method to map from most of the object from the attributes/properties. /// Later calls on the fluent interface can override whatever is set is by this call. /// This helps mapping all the ints as ints, floats as floats etcetera withouth having to be overly verbose in your fluent mapping /// </summary> /// <returns></returns> public ObjectMappingDescriptor <TParent, TChild> MapFromAttributes(int maxRecursion = 0) { var writer = new TypeMappingWriter(typeof(TChild), this._TypeName, this._connectionSettings, maxRecursion); var mapping = writer.ObjectMappingFromAttributes(); if (mapping == null) { return(this); } var properties = mapping.Properties; if (this._Mapping.Properties == null) { this._Mapping.Properties = new Dictionary <PropertyNameMarker, IElasticType>(); } foreach (var p in properties) { this._Mapping.Properties[p.Key] = p.Value; } return(this); }
/// <summary> /// Convenience method to map from most of the object from the attributes/properties. /// Later calls can override whatever is set is by this call. /// This helps mapping all the ints as ints, floats as floats etcetera withouth having to be overly verbose in your fluent mapping /// </summary> /// <returns></returns> public PutMappingDescriptor <T> MapFromAttributes(int maxRecursion = 0) { //TODO no longer needed when we have an IPutMappingRequest var writer = new TypeMappingWriter(typeof(T), Self.Type, this._connectionSettings, maxRecursion); var mapping = writer.RootObjectMappingFromAttributes(); if (mapping == null) { return(this); } var properties = mapping.Properties; if (Self.Mapping.Properties == null) { Self.Mapping.Properties = new Dictionary <PropertyNameMarker, IElasticType>(); } foreach (var p in properties) { Self.Mapping.Properties[p.Key] = p.Value; } return(this); }