コード例 #1
0
 public TypeFieldMappingDescriptor Index(NonStringIndexOption index = NonStringIndexOption.Analyzed)
 {
     Self.Index = index;
     return(this);
 }
コード例 #2
0
 public BooleanMappingDescriptor <T> Index(NonStringIndexOption index = NonStringIndexOption.analyzed)
 {
     this._Mapping.Index = index;
     return(this);
 }
コード例 #3
0
ファイル: ElasticSearch.cs プロジェクト: ewin66/rockrms
        /// <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);
            }
        }
コード例 #4
0
 public NumberMappingDescriptor <T> Index(NonStringIndexOption index = NonStringIndexOption.Analyzed)
 {
     this._Mapping.Index = index;
     return(this);
 }
コード例 #5
0
		public TypeFieldMappingDescriptor Index(NonStringIndexOption index = NonStringIndexOption.Analyzed)
		{
			Self.Index = index;
			return this;
		}
コード例 #6
0
ファイル: NumberProperty.cs プロジェクト: lukapor/NEST
 public TDescriptor Index(NonStringIndexOption index = NonStringIndexOption.No) => Assign(a => a.Index = index);
コード例 #7
0
ファイル: DateProperty.cs プロジェクト: lukapor/NEST
 public DatePropertyDescriptor <T> Index(NonStringIndexOption index = NonStringIndexOption.No) => Assign(a => a.Index = index);
コード例 #8
0
 public BooleanPropertyDescriptor <T> Index(NonStringIndexOption index) => Assign(a => a.Index = index);
コード例 #9
0
 public TypeFieldMapping SetIndexed(NonStringIndexOption index = NonStringIndexOption.analyzed)
 {
     this.Index = index;
     return this;
 }
コード例 #10
0
 public TypeFieldMapping SetIndexed(NonStringIndexOption index = NonStringIndexOption.analyzed)
 {
     this.Index = index;
     return(this);
 }