-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the histogram datatype to the client. The histogram datatype is available in Elasticsearch 7.6.0+ with at least a basic license level Closes #4358
- Loading branch information
Showing
13 changed files
with
179 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Nest/Mapping/Types/Specialized/Histogram/HistogramAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Nest | ||
{ | ||
public class HistogramAttribute : ElasticsearchPropertyAttributeBase, IHistogramProperty | ||
{ | ||
public HistogramAttribute() : base(FieldType.Histogram) { } | ||
|
||
/// <inheritdoc cref="IHistogramProperty.IgnoreMalformed"/> | ||
public bool IgnoreMalformed | ||
{ | ||
get => Self.IgnoreMalformed.GetValueOrDefault(); | ||
set => Self.IgnoreMalformed = value; | ||
} | ||
|
||
bool? IHistogramProperty.IgnoreMalformed { get; set; } | ||
|
||
private IHistogramProperty Self => this; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Nest/Mapping/Types/Specialized/Histogram/HistogramProperty.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Diagnostics; | ||
using System.Runtime.Serialization; | ||
using Elasticsearch.Net.Utf8Json; | ||
|
||
namespace Nest | ||
{ | ||
/// <summary> | ||
/// A field to store pre-aggregated numerical data representing a histogram. | ||
/// <para /> | ||
/// Available in Elasticsearch 7.6.0+ with at least basic license level | ||
/// </summary> | ||
[InterfaceDataContract] | ||
public interface IHistogramProperty : IProperty | ||
{ | ||
/// <summary> | ||
/// Whether to ignore malformed input values. | ||
/// </summary> | ||
[DataMember(Name = "ignore_malformed")] | ||
bool? IgnoreMalformed { get; set; } | ||
} | ||
|
||
/// <inheritdoc cref="IHistogramProperty"/> | ||
[DebuggerDisplay("{DebugDisplay}")] | ||
public class HistogramProperty : PropertyBase, IHistogramProperty | ||
{ | ||
public HistogramProperty() : base(FieldType.Histogram) { } | ||
|
||
/// <inheritdoc /> | ||
public bool? IgnoreMalformed { get; set; } | ||
} | ||
|
||
/// <inheritdoc cref="IHistogramProperty"/> | ||
[DebuggerDisplay("{DebugDisplay}")] | ||
public class HistogramPropertyDescriptor<T> | ||
: PropertyDescriptorBase<HistogramPropertyDescriptor<T>, IHistogramProperty, T>, IHistogramProperty | ||
where T : class | ||
{ | ||
bool? IHistogramProperty.IgnoreMalformed { get; set; } | ||
|
||
public HistogramPropertyDescriptor() : base(FieldType.Histogram) { } | ||
|
||
/// <inheritdoc cref="IHistogramProperty.IgnoreMalformed"/> | ||
public HistogramPropertyDescriptor<T> IgnoreMalformed(bool? ignoreMalformed = true) => | ||
Assign(ignoreMalformed, (a, v) => a.IgnoreMalformed = v); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/Tests/Mapping/Types/Specialized/Histogram/HistogramAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Nest; | ||
|
||
namespace Tests.Mapping.Types.Specialized.Histogram | ||
{ | ||
public class HistogramTest | ||
{ | ||
[Histogram(IgnoreMalformed = true)] | ||
public string Full { get; set; } | ||
|
||
[Histogram] | ||
public string Minimal { get; set; } | ||
} | ||
|
||
public class HistogramAttributeTests : AttributeTestsBase<HistogramTest> | ||
{ | ||
protected override object ExpectJson => new | ||
{ | ||
properties = new | ||
{ | ||
full = new | ||
{ | ||
type = "histogram", | ||
ignore_malformed = true | ||
}, | ||
minimal = new | ||
{ | ||
type = "histogram" | ||
} | ||
} | ||
}; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/Tests/Mapping/Types/Specialized/Histogram/HistogramPropertyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using Elastic.Xunit.XunitPlumbing; | ||
using Nest; | ||
using Tests.Core.ManagedElasticsearch.Clusters; | ||
using Tests.Domain; | ||
using Tests.Framework.EndpointTests.TestState; | ||
|
||
namespace Tests.Mapping.Types.Specialized.Histogram | ||
{ | ||
[SkipVersion("<7.6.0", "Introduced in 7.6.0")] | ||
public class HistogramPropertyTests : PropertyTestsBase | ||
{ | ||
public HistogramPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } | ||
|
||
protected override object ExpectJson => new | ||
{ | ||
properties = new | ||
{ | ||
name = new | ||
{ | ||
type = "histogram", | ||
ignore_malformed = true, | ||
} | ||
} | ||
}; | ||
|
||
protected override Func<PropertiesDescriptor<Project>, IPromise<IProperties>> FluentProperties => f => f | ||
.Histogram(s => s | ||
.Name(p => p.Name) | ||
.IgnoreMalformed() | ||
); | ||
|
||
|
||
protected override IProperties InitializerProperties => new Properties | ||
{ | ||
{ | ||
"name", new HistogramProperty | ||
{ | ||
IgnoreMalformed = true, | ||
} | ||
} | ||
}; | ||
} | ||
} |