Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement unsigned long numeric field #5275

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
};
}
}