-
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.
Relates: elastic/elasticsearch#49713 This commit adds the ConstantKeyword property to the client. Value is exposed as type Object as it can be a string or numeric value.
- Loading branch information
Showing
16 changed files
with
196 additions
and
2 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
11 changes: 11 additions & 0 deletions
11
src/Nest/Mapping/Types/Specialized/ConstantKeyword/ConstantKeywordAttribute.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,11 @@ | ||
namespace Nest | ||
{ | ||
/// <inheritdoc cref="IConstantKeywordProperty"/> | ||
public class ConstantKeywordAttribute : ElasticsearchPropertyAttributeBase, IConstantKeywordProperty | ||
{ | ||
public ConstantKeywordAttribute() : base(FieldType.ConstantKeyword) { } | ||
|
||
/// <inheritdoc /> | ||
public object Value { get; set; } | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Nest/Mapping/Types/Specialized/ConstantKeyword/ConstantKeywordProperty.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,48 @@ | ||
using System.Diagnostics; | ||
using System.Runtime.Serialization; | ||
using Elasticsearch.Net.Utf8Json; | ||
|
||
namespace Nest | ||
{ | ||
/// <summary> | ||
/// Constant keyword is a specialization of the keyword field for the case that all documents in the index have the same value. | ||
/// <para /> | ||
/// Available in Elasticsearch 7.7.0+ with at least a basic license level | ||
/// </summary> | ||
[InterfaceDataContract] | ||
public interface IConstantKeywordProperty : IProperty | ||
{ | ||
/// <summary> | ||
/// The value to associate with all documents in the index. | ||
/// If this parameter is not provided, it is set based on the first document that gets indexed. | ||
/// <para /> | ||
/// Value must be a string or a numeric value | ||
/// </summary> | ||
[DataMember(Name ="value")] | ||
object Value { get; set; } | ||
} | ||
|
||
/// <inheritdoc cref="IConstantKeywordProperty" /> | ||
[DebuggerDisplay("{DebugDisplay}")] | ||
public class ConstantKeywordProperty : PropertyBase, IConstantKeywordProperty | ||
{ | ||
public ConstantKeywordProperty() : base(FieldType.ConstantKeyword) { } | ||
|
||
/// <inheritdoc cref="IConstantKeywordProperty.Value" /> | ||
public object Value { get; set; } | ||
} | ||
|
||
/// <inheritdoc cref="IConstantKeywordProperty" /> | ||
[DebuggerDisplay("{DebugDisplay}")] | ||
public class ConstantKeywordPropertyDescriptor<T> | ||
: PropertyDescriptorBase<ConstantKeywordPropertyDescriptor<T>, IConstantKeywordProperty, T>, IConstantKeywordProperty | ||
where T : class | ||
{ | ||
public ConstantKeywordPropertyDescriptor() : base(FieldType.ConstantKeyword) { } | ||
|
||
object IConstantKeywordProperty.Value { get; set; } | ||
|
||
/// <inheritdoc cref="IConstantKeywordProperty.Value" /> | ||
public ConstantKeywordPropertyDescriptor<T> Value(object value) => Assign(value, (a, v) => a.Value = 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
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
35 changes: 35 additions & 0 deletions
35
tests/Tests/Mapping/Types/Specialized/ConstantKeyword/ConstantKeywordAttributeTests.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,35 @@ | ||
using Elastic.Xunit.XunitPlumbing; | ||
using Nest; | ||
|
||
namespace Tests.Mapping.Types.Specialized.ConstantKeyword | ||
{ | ||
public class ConstantKeywordTest | ||
{ | ||
[ConstantKeyword(Value = "constant_string")] | ||
public string ConstantString { get; set; } | ||
|
||
[ConstantKeyword(Value = 42)] | ||
public int ConstantInt { get; set; } | ||
} | ||
|
||
[SkipVersion("<7.7.0", "introduced in 7.7.0")] | ||
public class ConstantKeywordAttributeTests : AttributeTestsBase<ConstantKeywordTest> | ||
{ | ||
protected override object ExpectJson => new | ||
{ | ||
properties = new | ||
{ | ||
constantString = new | ||
{ | ||
type = "constant_keyword", | ||
value = "constant_string" | ||
}, | ||
constantInt = new | ||
{ | ||
type = "constant_keyword", | ||
value = 42 | ||
} | ||
} | ||
}; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/Tests/Mapping/Types/Specialized/ConstantKeyword/ConstantKeywordPropertyTests.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,43 @@ | ||
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.ConstantKeyword | ||
{ | ||
[SkipVersion("<7.7.0", "introduced in 7.7.0")] | ||
public class ConstantKeywordPropertyTests : PropertyTestsBase | ||
{ | ||
public ConstantKeywordPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } | ||
|
||
protected override object ExpectJson => new | ||
{ | ||
properties = new | ||
{ | ||
versionControl = new | ||
{ | ||
type = "constant_keyword", | ||
value = Project.VersionControlConstant, | ||
} | ||
} | ||
}; | ||
|
||
protected override Func<PropertiesDescriptor<Project>, IPromise<IProperties>> FluentProperties => f => f | ||
.ConstantKeyword(s => s | ||
.Name(n => n.VersionControl) | ||
.Value(Project.VersionControlConstant) | ||
); | ||
|
||
protected override IProperties InitializerProperties => new Properties | ||
{ | ||
{ | ||
"versionControl", new ConstantKeywordProperty | ||
{ | ||
Value = Project.VersionControlConstant | ||
} | ||
} | ||
}; | ||
} | ||
} |