Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type">The type of the number. Can be float, double, integer, long. Required.</param>
        /// <param name="indexName">The name of the field that will be stored in the index. Defaults to the property/field name.</param>
        /// <param name="index">Set to no if the value should not be indexed. In this case, store should be set to yes, since if its not indexed and not stored, there is nothing to do with it.</param>
        /// <param name="store">Set to yes the store actual field in the index, no to not store it. Defaults to no (note, the JSON document itself is stored, and it can be retrieved from it).</param>
        /// <param name="precisionStep">The precision step (number of terms generated for each number value). Defaults to 4.</param>
        /// <param name="boost">The boost value. Defaults to 1.0.</param>
        /// <param name="nullValue">When there is a (JSON) null value for the field, use the null_value as the field value. Defaults to not adding the field at all.</param>
        /// <param name="includeInAll">Should the field be included in the _all field (if enabled). Defaults to true or to the parent object type setting.</param>
        public NumberFieldSetting AddNumField(string name, NumType type = NumType.Integer,
                                              string indexName          = null,
                                              IndexType index           = IndexType.analyzed,
                                              Store store       = Store.no,
                                              int precisionStep = 4,
                                              double boost      = 1.0,
                                              string nullValue  = null,
                                              bool includeInAll = true)
        {
            Contract.Assert(_fieldSettings != null);

            var field = new NumberFieldSetting();

            field.Name = name;

            var numType = "integer";

            switch (type)
            {
            case NumType.Long:
                numType = "long";
                break;

            case NumType.Double:
                numType = "double";
                break;

            case NumType.Float:
                numType = "float";
                break;
            }

            field.Type          = numType;
            field.IndexName     = indexName;
            field.Store         = store;
            field.PrecisionStep = precisionStep;
            field.Boost         = boost;
            field.NullValue     = nullValue;
            field.IncludeInAll  = includeInAll;

            _fieldSettings[name] = field;
            return(field);
        }
        public void TestCreatingMapping()
        {
            var index = "index_operate" + Guid.NewGuid();
            var stringFieldSetting = new StringFieldSetting { Analyzer = "standard", Type = "string", NullValue = "mystr" };

            var typeSetting = new TypeSetting("custom_type");
            typeSetting.AddFieldSetting("medcl", stringFieldSetting);

            var typeSetting2 = new TypeSetting("hell_type1");
            var numfield = new NumberFieldSetting { Store = Store.yes, NullValue = 0.00 };
            typeSetting2.AddFieldSetting("name", numfield);

            client.CreateIndex(index);
            var result = client.PutMapping(index, typeSetting);
            Assert.AreEqual(true, result.Success);

            result = client.PutMapping(index, typeSetting2);
            Assert.AreEqual(true, result.Success);

            var result2 = client.DeleteIndex(index);
            Assert.AreEqual(true, result2.Success);
        }
Пример #3
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="type">The type of the number. Can be float, double, integer, long. Required.</param>
		/// <param name="indexName">The name of the field that will be stored in the index. Defaults to the property/field name.</param>
		/// <param name="index">Set to no if the value should not be indexed. In this case, store should be set to yes, since if its not indexed and not stored, there is nothing to do with it.</param>
		/// <param name="store">Set to yes the store actual field in the index, no to not store it. Defaults to no (note, the JSON document itself is stored, and it can be retrieved from it).</param>
		/// <param name="precisionStep">The precision step (number of terms generated for each number value). Defaults to 4.</param>
		/// <param name="boost">The boost value. Defaults to 1.0.</param>
		/// <param name="nullValue">When there is a (JSON) null value for the field, use the null_value as the field value. Defaults to not adding the field at all.</param>
		/// <param name="includeInAll">Should the field be included in the _all field (if enabled). Defaults to true or to the parent object type setting.</param>
        public NumberFieldSetting AddNumField(string name, NumType type = NumType.Integer,
								   string indexName = null,
								   IndexType index = IndexType.analyzed,
								   Store store = Store.no,
								   int precisionStep = 4,
								   double boost = 1.0,
								   string nullValue = null,
								   bool includeInAll = true)
		{
			Contract.Assert(_fieldSettings != null);

			var field = new NumberFieldSetting();
			field.Name = name;

			var numType = "integer";
			switch (type)
			{
				case NumType.Long:
					numType = "long";
					break;
				case NumType.Double:
					numType = "double";
					break;
				case NumType.Float:
					numType = "float";
					break;
			}

			field.Type = numType;
			field.IndexName = indexName;
			field.Store = store;
			field.PrecisionStep = precisionStep;
			field.Boost = boost;
			field.NullValue = nullValue;
			field.IncludeInAll = includeInAll;

			_fieldSettings[name] = field;
		    return field;
		}