From 5c2112021d448182b4a340daee54cbc1f2b79d1d Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Mon, 11 Apr 2016 20:58:13 -0400 Subject: [PATCH] Add not_analyzed to NonStringIndexOption and make it the default option Closes #i979 --- src/Nest/Mapping/NonStringIndexOption.cs | 2 ++ .../Types/Core/Boolean/BooleanProperty.cs | 6 +++--- .../Mapping/Types/Core/Date/DateProperty.cs | 12 ++++++------ .../Types/Core/Number/NumberProperty.cs | 6 +++--- .../Types/Specialized/Ip/IpProperty.cs | 4 ++-- .../TokenCount/TokenCountProperty.cs | 2 +- .../PutMapping/PutMappingApiTest.cs | 19 +++++++++++++++---- 7 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/Nest/Mapping/NonStringIndexOption.cs b/src/Nest/Mapping/NonStringIndexOption.cs index 44b8e307463..9c08cc7fd27 100644 --- a/src/Nest/Mapping/NonStringIndexOption.cs +++ b/src/Nest/Mapping/NonStringIndexOption.cs @@ -7,6 +7,8 @@ namespace Nest [JsonConverter(typeof(StringEnumConverter))] public enum NonStringIndexOption { + [EnumMember(Value = "not_analyzed")] + NotAnalyzed, [EnumMember(Value = "no")] No } diff --git a/src/Nest/Mapping/Types/Core/Boolean/BooleanProperty.cs b/src/Nest/Mapping/Types/Core/Boolean/BooleanProperty.cs index 3a32b53cec7..18b6dc8f69c 100644 --- a/src/Nest/Mapping/Types/Core/Boolean/BooleanProperty.cs +++ b/src/Nest/Mapping/Types/Core/Boolean/BooleanProperty.cs @@ -19,7 +19,7 @@ public interface IBooleanProperty : IProperty [JsonProperty("fielddata")] INumericFielddata Fielddata { get; set; } } - + public class BooleanProperty : PropertyBase, IBooleanProperty { public BooleanProperty() : base("boolean") { } @@ -42,9 +42,9 @@ public class BooleanPropertyDescriptor public BooleanPropertyDescriptor() : base("boolean") { } public BooleanPropertyDescriptor Boost(double boost) => Assign(a => a.Boost = boost); - public BooleanPropertyDescriptor Index(NonStringIndexOption index) => Assign(a => a.Index = index); + public BooleanPropertyDescriptor Index(NonStringIndexOption index = NonStringIndexOption.NotAnalyzed) => Assign(a => a.Index = index); public BooleanPropertyDescriptor NullValue(bool nullValue) => Assign(a => a.NullValue = nullValue); public BooleanPropertyDescriptor Fielddata(Func selector) => Assign(a => a.Fielddata = selector(new NumericFielddataDescriptor())); } -} \ No newline at end of file +} diff --git a/src/Nest/Mapping/Types/Core/Date/DateProperty.cs b/src/Nest/Mapping/Types/Core/Date/DateProperty.cs index f0bdc9e0095..2cd7a377ff1 100644 --- a/src/Nest/Mapping/Types/Core/Date/DateProperty.cs +++ b/src/Nest/Mapping/Types/Core/Date/DateProperty.cs @@ -20,13 +20,13 @@ public interface IDateProperty : IProperty [JsonProperty("precision_step")] int? PrecisionStep { get; set; } - + [JsonProperty("ignore_malformed")] bool? IgnoreMalformed { get; set; } - + [JsonProperty("format")] string Format { get; set; } - + [JsonProperty("numeric_resolution")] NumericResolutionUnit? NumericResolution { get; set; } @@ -49,7 +49,7 @@ public DateProperty() : base("date") { } public INumericFielddata Fielddata { get; set; } } - public class DatePropertyDescriptor + public class DatePropertyDescriptor : PropertyDescriptorBase, IDateProperty, T>, IDateProperty where T : class { @@ -65,7 +65,7 @@ public class DatePropertyDescriptor public DatePropertyDescriptor() : base("date") { } - public DatePropertyDescriptor Index(NonStringIndexOption index = NonStringIndexOption.No) => Assign(a => a.Index = index); + public DatePropertyDescriptor Index(NonStringIndexOption index = NonStringIndexOption.NotAnalyzed) => Assign(a => a.Index = index); public DatePropertyDescriptor Boost(double boost) => Assign(a => a.Boost = boost); public DatePropertyDescriptor NullValue(DateTime nullValue) => Assign(a => a.NullValue = nullValue); public DatePropertyDescriptor IncludeInAll(bool includeInAll = true) => Assign(a => a.IncludeInAll = includeInAll); @@ -76,4 +76,4 @@ public DatePropertyDescriptor() : base("date") { } public DatePropertyDescriptor Fielddata(Func selector) => Assign(a => a.Fielddata = selector(new NumericFielddataDescriptor())); } -} \ No newline at end of file +} diff --git a/src/Nest/Mapping/Types/Core/Number/NumberProperty.cs b/src/Nest/Mapping/Types/Core/Number/NumberProperty.cs index bcea6bcc4e8..702f29caed2 100644 --- a/src/Nest/Mapping/Types/Core/Number/NumberProperty.cs +++ b/src/Nest/Mapping/Types/Core/Number/NumberProperty.cs @@ -68,7 +68,7 @@ protected NumberPropertyDescriptorBase(string type) : base(type) { } public TDescriptor Type(NumberType type) => Assign(a => a.Type = type.GetStringValue()); - public TDescriptor Index(NonStringIndexOption index = NonStringIndexOption.No) => Assign(a => a.Index = index); + public TDescriptor Index(NonStringIndexOption index = NonStringIndexOption.NotAnalyzed) => Assign(a => a.Index = index); public TDescriptor Boost(double boost) => Assign(a => a.Boost = boost); @@ -86,9 +86,9 @@ public TDescriptor Fielddata(Func Assign(a => a.Fielddata = selector(new NumericFielddataDescriptor())); } - public class NumberPropertyDescriptor + public class NumberPropertyDescriptor : NumberPropertyDescriptorBase, INumberProperty, T>, INumberProperty where T : class { } -} \ No newline at end of file +} diff --git a/src/Nest/Mapping/Types/Specialized/Ip/IpProperty.cs b/src/Nest/Mapping/Types/Specialized/Ip/IpProperty.cs index 1e4b60faeab..ec7a1e165d0 100644 --- a/src/Nest/Mapping/Types/Specialized/Ip/IpProperty.cs +++ b/src/Nest/Mapping/Types/Specialized/Ip/IpProperty.cs @@ -44,7 +44,7 @@ public class IpPropertyDescriptor public IpPropertyDescriptor() : base("ip") { } - public IpPropertyDescriptor Index(NonStringIndexOption? index) => Assign(a => a.Index = index); + public IpPropertyDescriptor Index(NonStringIndexOption? index = NonStringIndexOption.NotAnalyzed) => Assign(a => a.Index = index); public IpPropertyDescriptor Boost(double boost) => Assign(a => a.Boost = boost); @@ -54,4 +54,4 @@ public IpPropertyDescriptor() : base("ip") { } public IpPropertyDescriptor IncludeInAll(bool includeInAll = true) => Assign(a => a.IncludeInAll = includeInAll); } -} \ No newline at end of file +} diff --git a/src/Nest/Mapping/Types/Specialized/TokenCount/TokenCountProperty.cs b/src/Nest/Mapping/Types/Specialized/TokenCount/TokenCountProperty.cs index 35d11383b2e..e74a958cc3f 100644 --- a/src/Nest/Mapping/Types/Specialized/TokenCount/TokenCountProperty.cs +++ b/src/Nest/Mapping/Types/Specialized/TokenCount/TokenCountProperty.cs @@ -16,7 +16,7 @@ public TokenCountProperty() : base("token_count") { } public string Analyzer { get; set; } } - public class TokenCountPropertyDescriptor + public class TokenCountPropertyDescriptor : NumberPropertyDescriptorBase, ITokenCountProperty, T>, ITokenCountProperty where T : class { diff --git a/src/Tests/Indices/MappingManagement/PutMapping/PutMappingApiTest.cs b/src/Tests/Indices/MappingManagement/PutMapping/PutMappingApiTest.cs index 340e69de265..727cd854320 100644 --- a/src/Tests/Indices/MappingManagement/PutMapping/PutMappingApiTest.cs +++ b/src/Tests/Indices/MappingManagement/PutMapping/PutMappingApiTest.cs @@ -123,11 +123,13 @@ protected override LazyResponses ClientUsage() => Calls( }, numberOfCommits = new { - type = "integer" + type = "integer", + index = "not_analyzed" }, startedOn = new { - type = "date" + type = "date", + index = "no" }, state = new { @@ -160,6 +162,15 @@ protected override LazyResponses ClientUsage() => Calls( .Index(CallIsolatedValue) .AutoMap() .Properties(prop => prop + .Number(n => n + .Name(p => p.NumberOfCommits) + .Type(NumberType.Integer) + .Index() + ) + .Date(dt => dt + .Name(p => p.StartedOn) + .Index(NonStringIndexOption.No) + ) .String(s => s .Name(p => p.Name) .NotAnalyzed() @@ -211,8 +222,8 @@ protected override LazyResponses ClientUsage() => Calls( }, { p => p.Metadata, new ObjectProperty() }, { p => p.Name, new StringProperty { Index = FieldIndexOption.NotAnalyzed } }, - { p => p.NumberOfCommits, new NumberProperty(NumberType.Integer) }, - { p => p.StartedOn, new DateProperty() }, + { p => p.NumberOfCommits, new NumberProperty(NumberType.Integer) { Index = NonStringIndexOption.NotAnalyzed } }, + { p => p.StartedOn, new DateProperty { Index = NonStringIndexOption.No } }, { p => p.State, new NumberProperty(NumberType.Integer) }, { p => p.Suggest, new CompletionProperty() }, { p => p.Tags, new ObjectProperty