-
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.
Add support for wildcard property (#4890)
Relates: elastic/elasticsearch#49993
- Loading branch information
1 parent
7c11fa5
commit 10948f9
Showing
8 changed files
with
188 additions
and
1 deletion.
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
26 changes: 26 additions & 0 deletions
26
src/Nest/Mapping/Types/Specialized/Wildcard/WildcardAttribute.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,26 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
namespace Nest | ||
{ | ||
/// <inheritdoc cref="IWildcardProperty"/> | ||
public class WildcardAttribute : ElasticsearchPropertyAttributeBase, IWildcardProperty | ||
{ | ||
public WildcardAttribute() : base(FieldType.Wildcard) { } | ||
|
||
int? IWildcardProperty.IgnoreAbove { get; set; } | ||
|
||
private IWildcardProperty Self => this; | ||
|
||
/// <inheritdoc cref="IWildcardProperty.IgnoreAbove" /> | ||
public int IgnoreAbove | ||
{ | ||
get => Self.IgnoreAbove.GetValueOrDefault(2147483647); | ||
set => Self.IgnoreAbove = value; | ||
} | ||
|
||
/// <inheritdoc cref="IWildcardProperty.NullValue" /> | ||
public string NullValue { get; set; } | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/Nest/Mapping/Types/Specialized/Wildcard/WildcardProperty.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,62 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Diagnostics; | ||
using System.Runtime.Serialization; | ||
using Elasticsearch.Net.Utf8Json; | ||
|
||
namespace Nest | ||
{ | ||
/// <summary> | ||
/// A wildcard field stores values optimised for wildcard grep-like queries. | ||
/// <para /> | ||
/// Available in Elasticsearch 7.9.0+ with at least a basic license level | ||
/// </summary> | ||
[InterfaceDataContract] | ||
public interface IWildcardProperty : IProperty | ||
{ | ||
/// <summary> | ||
/// Do not index any string longer than this value. Defaults to 2147483647 so that all values would be accepted. | ||
/// </summary> | ||
[DataMember(Name = "ignore_above")] | ||
int? IgnoreAbove { get; set; } | ||
|
||
/// <summary> | ||
/// Accepts a string value which is substituted for any explicit null values. Defaults to null, which means the field is treated as missing. | ||
/// </summary> | ||
[DataMember(Name ="null_value")] | ||
string NullValue { get; set; } | ||
} | ||
|
||
/// <inheritdoc cref="IWildcardProperty" /> | ||
[DebuggerDisplay("{DebugDisplay}")] | ||
public class WildcardProperty : PropertyBase, IWildcardProperty | ||
{ | ||
public WildcardProperty() : base(FieldType.Wildcard) { } | ||
|
||
/// <inheritdoc cref="IWildcardProperty.IgnoreAbove" /> | ||
public int? IgnoreAbove { get; set; } | ||
|
||
/// <inheritdoc cref="IWildcardProperty.NullValue" /> | ||
public string NullValue { get; set; } | ||
} | ||
|
||
/// <inheritdoc cref="IWildcardProperty" /> | ||
[DebuggerDisplay("{DebugDisplay}")] | ||
public class WildcardPropertyDescriptor<T> | ||
: PropertyDescriptorBase<WildcardPropertyDescriptor<T>, IWildcardProperty, T>, IWildcardProperty | ||
where T : class | ||
{ | ||
public WildcardPropertyDescriptor() : base(FieldType.Wildcard) { } | ||
|
||
int? IWildcardProperty.IgnoreAbove { get; set; } | ||
string IWildcardProperty.NullValue { get; set; } | ||
|
||
/// <inheritdoc cref="IWildcardProperty.IgnoreAbove" /> | ||
public WildcardPropertyDescriptor<T> IgnoreAbove(int? ignoreAbove) => Assign(ignoreAbove, (a, v) => a.IgnoreAbove = v); | ||
|
||
/// <inheritdoc cref="IWildcardProperty.NullValue" /> | ||
public WildcardPropertyDescriptor<T> NullValue(string nullValue) => Assign(nullValue, (a, v) => a.NullValue = v); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Tests/Mapping/Types/Specialized/Wildcard/WildcardAttributeTests.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,39 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using Elastic.Elasticsearch.Xunit.XunitPlumbing; | ||
using Nest; | ||
|
||
namespace Tests.Mapping.Types.Specialized.Wildcard | ||
{ | ||
public class WildcardTest | ||
{ | ||
[Wildcard(IgnoreAbove = 512, NullValue = "foo")] | ||
public string Full { get; set; } | ||
|
||
[Wildcard] | ||
public string Simple { get; set; } | ||
} | ||
|
||
[SkipVersion("<7.9.0", "introduced in 7.9.0")] | ||
public class WildcardAttributeTests : AttributeTestsBase<WildcardTest> | ||
{ | ||
protected override object ExpectJson => new | ||
{ | ||
properties = new | ||
{ | ||
full = new | ||
{ | ||
type = "wildcard", | ||
ignore_above = 512, | ||
null_value = "foo" | ||
}, | ||
simple = new | ||
{ | ||
type = "wildcard" | ||
} | ||
} | ||
}; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/Tests/Mapping/Types/Specialized/Wildcard/WildcardPropertyTests.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,42 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// 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; | ||
using Tests.Framework.EndpointTests.TestState; | ||
|
||
namespace Tests.Mapping.Types.Specialized.Wildcard | ||
{ | ||
[SkipVersion("<7.9.0", "introduced in 7.9.0")] | ||
public class WildcardPropertyTests : PropertyTestsBase | ||
{ | ||
public WildcardPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } | ||
|
||
protected override object ExpectJson => new | ||
{ | ||
properties = new | ||
{ | ||
description = new | ||
{ | ||
type = "wildcard" | ||
} | ||
} | ||
}; | ||
|
||
protected override Func<PropertiesDescriptor<Project>, IPromise<IProperties>> FluentProperties => f => f | ||
.Wildcard(s => s | ||
.Name(n => n.Description) | ||
); | ||
|
||
protected override IProperties InitializerProperties => new Properties | ||
{ | ||
{ | ||
"description", new WildcardProperty() | ||
} | ||
}; | ||
} | ||
} |