-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement ConstantKeyword property #4593
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
} | ||
} | ||
}; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.