public TypeFieldMappingDescriptor Index(NonStringIndexOption index = NonStringIndexOption.Analyzed) { Self.Index = index; return(this); }
public BooleanMappingDescriptor <T> Index(NonStringIndexOption index = NonStringIndexOption.analyzed) { this._Mapping.Index = index; return(this); }
/// <summary> /// Creates the index. /// </summary> /// <param name="documentType">Type of the document.</param> /// <param name="deleteIfExists">if set to <c>true</c> [delete if exists].</param> public override void CreateIndex(Type documentType, bool deleteIfExists = true) { var indexName = documentType.Name.ToLower(); object instance = Activator.CreateInstance(documentType); // check if index already exists var existsResponse = _client.IndexExists(indexName); if (existsResponse.Exists) { if (deleteIfExists) { this.DeleteIndex(documentType); } else { return; } } // make sure this is an index document if (instance is IndexModelBase) { // create a new index request var createIndexRequest = new CreateIndexRequest(indexName); createIndexRequest.Mappings = new Mappings(); createIndexRequest.Settings = new IndexSettings(); createIndexRequest.Settings.NumberOfShards = GetAttributeValue("ShardCount").AsInteger(); var typeMapping = new TypeMapping(); typeMapping.Dynamic = DynamicMapping.Allow; typeMapping.Properties = new Properties(); createIndexRequest.Mappings.Add(indexName, typeMapping); var model = (IndexModelBase)instance; // get properties from the model and add them to the index (hint: attributes will be added dynamically as the documents are loaded) var modelProperties = documentType.GetProperties(); foreach (var property in modelProperties) { var indexAttributes = property.GetCustomAttributes(false); var indexAttribute = property.GetCustomAttributes(typeof(RockIndexField), false); if (indexAttribute.Length > 0) { var attribute = (RockIndexField)indexAttribute[0]; var propertyName = Char.ToLowerInvariant(property.Name[0]) + property.Name.Substring(1); // rewrite non-string index option (would be nice if they made the enums match up...) NonStringIndexOption nsIndexOption = NonStringIndexOption.NotAnalyzed; if (attribute.Type != IndexFieldType.String) { if (attribute.Index == IndexType.NotIndexed) { nsIndexOption = NonStringIndexOption.No; } } switch (attribute.Type) { case IndexFieldType.Boolean: { typeMapping.Properties.Add(propertyName, new BooleanProperty() { Name = propertyName, Boost = attribute.Boost, Index = nsIndexOption }); break; } case IndexFieldType.Date: { typeMapping.Properties.Add(propertyName, new DateProperty() { Name = propertyName, Boost = attribute.Boost, Index = nsIndexOption }); break; } case IndexFieldType.Number: { typeMapping.Properties.Add(propertyName, new NumberProperty() { Name = propertyName, Boost = attribute.Boost, Index = nsIndexOption }); break; } default: { var stringProperty = new StringProperty(); stringProperty.Name = propertyName; stringProperty.Boost = attribute.Boost; stringProperty.Index = (FieldIndexOption)attribute.Index; if (!string.IsNullOrWhiteSpace(attribute.Analyzer)) { stringProperty.Analyzer = attribute.Analyzer; } typeMapping.Properties.Add(propertyName, stringProperty); break; } } } } var response = _client.CreateIndex(createIndexRequest); } }
public NumberMappingDescriptor <T> Index(NonStringIndexOption index = NonStringIndexOption.Analyzed) { this._Mapping.Index = index; return(this); }
public TypeFieldMappingDescriptor Index(NonStringIndexOption index = NonStringIndexOption.Analyzed) { Self.Index = index; return this; }
public TDescriptor Index(NonStringIndexOption index = NonStringIndexOption.No) => Assign(a => a.Index = index);
public DatePropertyDescriptor <T> Index(NonStringIndexOption index = NonStringIndexOption.No) => Assign(a => a.Index = index);
public BooleanPropertyDescriptor <T> Index(NonStringIndexOption index) => Assign(a => a.Index = index);
public TypeFieldMapping SetIndexed(NonStringIndexOption index = NonStringIndexOption.analyzed) { this.Index = index; return this; }
public TypeFieldMapping SetIndexed(NonStringIndexOption index = NonStringIndexOption.analyzed) { this.Index = index; return(this); }