Skip to content

Commit

Permalink
Implement unsigned long (#5275) (#5277)
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Gordon <sgordon@hotmail.co.uk>
  • Loading branch information
github-actions[bot] and stevejgordon authored Jan 20, 2021
1 parent c1316d3 commit 61a0b39
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Nest/Mapping/Types/Core/Number/NumberType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public enum NumberType
Short,

[EnumMember(Value = "byte")]
Byte
Byte,

[EnumMember(Value = "unsigned_long")]
UnsignedLong
}

internal static class NumberTypeExtensions
Expand All @@ -51,6 +54,7 @@ public static FieldType ToFieldType(this NumberType numberType)
case NumberType.Long: return FieldType.Long;
case NumberType.Short: return FieldType.Short;
case NumberType.Byte: return FieldType.Byte;
case NumberType.UnsignedLong: return FieldType.UnsignedLong;
default:
throw new ArgumentOutOfRangeException(nameof(numberType), numberType, null);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Nest/Mapping/Types/FieldType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public enum FieldType
[EnumMember(Value = "long")]
Long,

[EnumMember(Value = "unsigned_long")]
UnsignedLong,

[EnumMember(Value = "short")]
Short,

Expand Down
1 change: 1 addition & 0 deletions src/Nest/Mapping/Types/PropertyFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public IProperty Deserialize(ref JsonReader reader, IJsonFormatterResolver forma
case FieldType.Long:
case FieldType.ScaledFloat:
case FieldType.HalfFloat:
case FieldType.UnsignedLong:
var numberProperty = Deserialize<NumberProperty>(ref segmentReader, formatterResolver);
((IProperty)numberProperty).Type = typeString;
return numberProperty;
Expand Down
48 changes: 48 additions & 0 deletions tests/Tests/Mapping/Types/Core/Number/NumberPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information

using System;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using Nest;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Domain;
Expand Down Expand Up @@ -118,4 +119,51 @@ public ScaledFloatNumberPropertyTests(WritableCluster cluster, EndpointUsage usa
}
};
}

[SkipVersion("<7.10.0", "Introduced in 7.10.0")]
public class UnsignedLongNumberPropertyTests : PropertyTestsBase
{
public UnsignedLongNumberPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

protected override object ExpectJson => new
{
properties = new
{
numberOfCommits = new
{
type = "unsigned_long",
doc_values = true,
similarity = "BM25",
store = true,
index = false,
ignore_malformed = true
}
}
};

protected override Func<PropertiesDescriptor<Project>, IPromise<IProperties>> FluentProperties => f => f
.Number(n => n
.Name(p => p.NumberOfCommits)
.Type(NumberType.UnsignedLong)
.DocValues()
.Similarity("BM25")
.Store()
.Index(false)
.IgnoreMalformed()
);

protected override IProperties InitializerProperties => new Properties
{
{
"numberOfCommits", new NumberProperty(NumberType.UnsignedLong)
{
DocValues = true,
Similarity = "BM25",
Store = true,
Index = false,
IgnoreMalformed = true
}
}
};
}
}

0 comments on commit 61a0b39

Please sign in to comment.