/// <summary> /// Add a new mapping using the first rootObjectMapping parameter as the base to construct the new mapping. /// Handy if you wish to reuse a mapping. /// </summary> public CreateIndexDescriptor AddMapping <T>(RootObjectMapping rootObjectMapping, Func <PutMappingDescriptor <T>, PutMappingDescriptor <T> > typeMappingDescriptor) where T : class { typeMappingDescriptor.ThrowIfNull("typeMappingDescriptor"); var selectorIn = new PutMappingDescriptor <T>(this._connectionSettings); IPutMappingRequest selectorInRequest = selectorIn; selectorInRequest.Mapping = rootObjectMapping; var d = typeMappingDescriptor(selectorIn); IPutMappingRequest request = d; var typeMapping = request.Mapping; if (request.Type != null) { typeMapping.Name = request.Type.Name != null ? (PropertyNameMarker)request.Type.Name : request.Type.Type; } else { typeMapping.Name = typeof(T); } this._indexSettings.Mappings.Add(typeMapping); return(this); }
private void Setup() { if (_elasticClient.IndexExists(Indexes.POINTS_OF_INTEREST).Exists) _elasticClient.DeleteIndex(Indexes.POINTS_OF_INTEREST); _elasticClient.CreateIndex(Indexes.POINTS_OF_INTEREST); var notAnalyzed = new StringMapping { Index = FieldIndexOption.NotAnalyzed }; var indexDefinition = new RootObjectMapping { Name = new PropertyNameMarker { Name = Indexes.POINTS_OF_INTEREST }, Properties = new Dictionary<PropertyNameMarker, IElasticType>() }; indexDefinition.Properties.Add("id", notAnalyzed); _elasticClient.Map<PointOfInterest>(m => { return m .InitializeUsing(indexDefinition) .IdField(id => id.Path("id")) .SourceField(s => s .Includes(new[] { "*" }) ) .Properties(props => props.GeoPoint(s => s .Name(p => p.Coordinates) ) ); }); }
public PutMappingDescriptor <T> InitializeUsing(RootObjectMapping rootObjectMapping) { if (rootObjectMapping == null) { return(this); } this._Mapping = rootObjectMapping; return(this); }
/// <summary> /// Add a new mapping using the first rootObjectMapping parameter as the base to construct the new mapping. /// Handy if you wish to reuse a mapping. /// </summary> public CreateIndexDescriptor AddMapping <T>(RootObjectMapping rootObjectMapping, Func <RootObjectMappingDescriptor <T>, RootObjectMappingDescriptor <T> > typeMappingDescriptor) where T : class { typeMappingDescriptor.ThrowIfNull("typeMappingDescriptor"); var d = typeMappingDescriptor(new RootObjectMappingDescriptor <T>() { _Mapping = rootObjectMapping }); var typeMapping = d._Mapping; this._IndexSettings.Mappings.Add(typeMapping); return(this); }
/// <summary> /// Add a new mapping using the first rootObjectMapping parameter as the base to construct the new mapping. /// Handy if you wish to reuse a mapping. /// </summary> public CreateIndexDescriptor AddMapping <T>(RootObjectMapping rootObjectMapping, Func <PutMappingDescriptor <T>, PutMappingDescriptor <T> > typeMappingDescriptor) where T : class { typeMappingDescriptor.ThrowIfNull("typeMappingDescriptor"); var d = typeMappingDescriptor(new PutMappingDescriptor <T>(this._connectionSettings) { _Mapping = rootObjectMapping, }); var typeMapping = d._Mapping; typeMapping.Name = typeof(T); this._IndexSettings.Mappings.Add(typeMapping); return(this); }
/// <summary> /// Verbosely and explicitly map an object using a TypeMapping object, this gives you exact control over the mapping. /// </summary> public IIndicesResponse Map(RootObjectMapping typeMapping, string index, string typeName = null, bool ignoreConflicts = false) { if (typeName.IsNullOrEmpty()) { typeName = this.ResolveTypeName(typeMapping.TypeNameMarker); } var mapping = new Dictionary <string, RootObjectMapping>(); mapping.Add(this.ResolveTypeName(typeMapping.TypeNameMarker), typeMapping); string map = JsonConvert.SerializeObject(mapping, Formatting.None, SerializationSettings); return(MapRaw(typeName, map, index, ignoreConflicts)); }
public void Configure() { if (!_elasticClient.IndexExists(Indexes.PILAROMETRO).Exists) { _elasticClient.CreateIndex(Indexes.PILAROMETRO); var indexDefinition = new RootObjectMapping { Name = new PropertyNameMarker { Name = Indexes.POINTS_OF_INTEREST }, Properties = new Dictionary<PropertyNameMarker, IElasticType>() }; _elasticClient.Map<User>(m => { return m .InitializeUsing(indexDefinition) .IdField(id => id.Path("id")) .SourceField(s => s .Includes(new[] { "*" }) ); }); } }
/// <summary> /// Add a new mapping using the first rootObjectMapping parameter as the base to construct the new mapping. /// Handy if you wish to reuse a mapping. /// </summary> public CreateIndexDescriptor AddMapping <T>(RootObjectMapping rootObjectMapping, Func <PutMappingDescriptor <T>, PutMappingDescriptor <T> > typeMappingDescriptor) where T : class { typeMappingDescriptor.ThrowIfNull("typeMappingDescriptor"); var d = typeMappingDescriptor(new PutMappingDescriptor <T>(this._connectionSettings) { _Mapping = rootObjectMapping, }); var typeMapping = d._Mapping; if (d._Type != null) { typeMapping.Name = d._Type.Name != null ? (PropertyNameMarker)d._Type.Name : d._Type.Type; } else { typeMapping.Name = typeof(T); } this._IndexSettings.Mappings.Add(typeMapping); return(this); }
/// <summary> /// Verbosely and explicitly map an object using a TypeMapping object, this gives you exact control over the mapping. /// </summary> public IIndicesResponse Map(RootObjectMapping typeMapping, string index, string typeName = null, bool ignoreConflicts = false) { if (typeName.IsNullOrEmpty()) { typeName = this.ResolveTypeName(typeMapping.TypeNameMarker); } var mapping = new Dictionary <string, RootObjectMapping>(); mapping.Add(this.ResolveTypeName(typeMapping.TypeNameMarker), typeMapping); string map = this.Serializer.Serialize(mapping, Formatting.None); string path = this.PathResolver.CreateIndexTypePath(index, typeName, "_mapping"); if (ignoreConflicts) { path += "?ignore_conflicts=true"; } ConnectionStatus status = this.Connection.PutSync(path, map); var r = this.Deserialize <IndicesResponse>(status); return(r); }
private void CreateMappings(string indexName) { var indexDefinition = new RootObjectMapping { Properties = _configuration.MappingProperties, Name = indexName, SourceFieldMappingDescriptor = new SourceFieldMapping() {Compress = true}, TtlFieldMappingDescriptor = new TtlFieldMapping() {Enabled = true, Default = _configuration.Ttl} }; var result = _client.Map<object>(x => x.InitializeUsing(indexDefinition).Type("_default_")); if (!result.ConnectionStatus.Success) { throw new ApplicationException(string.Format("Failed to update mapping for index: '{0}'. Result: '{1}'", indexName, result.ConnectionStatus.ResponseRaw)); } }
/// <summary> /// Verbosely and explicitly map an object using a TypeMapping object, this gives you exact control over the mapping. Index is the inferred default index /// </summary> public IIndicesResponse Map(RootObjectMapping typeMapping) { return(this.Map(typeMapping, this.Settings.DefaultIndex)); }