Skip to content

fix #3326 Add index_prefixes to Text property mapping #3362

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 1 commit into from
Aug 14, 2018
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
1 change: 1 addition & 0 deletions src/Nest/Mapping/Types/Core/Text/TextAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public TextAttribute() : base(FieldType.Text) { }
bool? ITextProperty.EagerGlobalOrdinals { get; set; }
bool? ITextProperty.Fielddata { get; set; }
IFielddataFrequencyFilter ITextProperty.FielddataFrequencyFilter { get; set; }
ITextIndexPrefixes ITextProperty.IndexPrefixes { get; set; }
bool? ITextProperty.Index { get; set; }
IndexOptions? ITextProperty.IndexOptions { get; set; }
bool? ITextProperty.Norms { get; set; }
Expand Down
32 changes: 32 additions & 0 deletions src/Nest/Mapping/Types/Core/Text/TextIndexPrefixes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Newtonsoft.Json;

namespace Nest
{
[JsonObject(MemberSerialization.OptIn)]
[JsonConverter(typeof(ReadAsTypeJsonConverter<TextIndexPrefixes>))]
public interface ITextIndexPrefixes
{
[JsonProperty("min_chars")]
int? MinCharacters { get; set; }

[JsonProperty("max_chars")]
int? MaxCharacters { get; set; }
}

public class TextIndexPrefixes : ITextIndexPrefixes
{
public int? MinCharacters { get; set; }
public int? MaxCharacters { get; set; }
}

public class TextIndexPrefixesDescriptor
: DescriptorBase<TextIndexPrefixesDescriptor, ITextIndexPrefixes>, ITextIndexPrefixes
{
int? ITextIndexPrefixes.MinCharacters { get; set; }
int? ITextIndexPrefixes.MaxCharacters { get; set; }

public TextIndexPrefixesDescriptor MinCharacters(int? min) => Assign(a => a.MinCharacters = min);

public TextIndexPrefixesDescriptor MaxCharacters(int? max) => Assign(a => a.MaxCharacters = max);
}
}
7 changes: 7 additions & 0 deletions src/Nest/Mapping/Types/Core/Text/TextProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public interface ITextProperty : ICoreProperty
[JsonProperty("fielddata_frequency_filter")]
IFielddataFrequencyFilter FielddataFrequencyFilter { get; set; }

[JsonProperty("index_prefixes")]
ITextIndexPrefixes IndexPrefixes { get; set; }

[JsonProperty("index")]
bool? Index { get; set; }

Expand All @@ -53,6 +56,7 @@ public TextProperty() : base(FieldType.Text) { }
public bool? EagerGlobalOrdinals { get; set; }
public bool? Fielddata { get; set; }
public IFielddataFrequencyFilter FielddataFrequencyFilter { get; set; }
public ITextIndexPrefixes IndexPrefixes { get; set; }
public bool? Index { get; set; }
public IndexOptions? IndexOptions { get; set; }
public bool? Norms { get; set; }
Expand All @@ -72,6 +76,7 @@ public class TextPropertyDescriptor<T>
bool? ITextProperty.EagerGlobalOrdinals { get; set; }
bool? ITextProperty.Fielddata { get; set; }
IFielddataFrequencyFilter ITextProperty.FielddataFrequencyFilter { get; set; }
ITextIndexPrefixes ITextProperty.IndexPrefixes { get; set; }
bool? ITextProperty.Index { get; set; }
IndexOptions? ITextProperty.IndexOptions { get; set; }
bool? ITextProperty.Norms { get; set; }
Expand All @@ -88,6 +93,8 @@ public TextPropertyDescriptor() : base(FieldType.Text) { }
public TextPropertyDescriptor<T> Fielddata(bool? fielddata = true) => Assign(a => a.Fielddata = fielddata);
public TextPropertyDescriptor<T> FielddataFrequencyFilter(Func<FielddataFrequencyFilterDescriptor, IFielddataFrequencyFilter> selector) =>
Assign(a => a.FielddataFrequencyFilter = selector?.Invoke(new FielddataFrequencyFilterDescriptor()));
public TextPropertyDescriptor<T> IndexPrefixes(Func<TextIndexPrefixesDescriptor, ITextIndexPrefixes> selector) =>
Assign(a => a.IndexPrefixes = selector?.Invoke(new TextIndexPrefixesDescriptor()));
public TextPropertyDescriptor<T> Index(bool? index = true) => Assign(a => a.Index = index);
public TextPropertyDescriptor<T> IndexOptions(IndexOptions? indexOptions) => Assign(a => a.IndexOptions = indexOptions);
public TextPropertyDescriptor<T> Norms(bool? enabled = true) => Assign(a => a.Norms = enabled);
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Tests.Configuration/tests.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# tracked by git).

# mode either u (unit test), i (integration test) or m (mixed mode)
mode: i
mode: u
# the elasticsearch version that should be started
# Can be a snapshot version of sonatype or "latest" to get the latest snapshot of sonatype
elasticsearch_version: 6.3.0
Expand Down
14 changes: 14 additions & 0 deletions src/Tests/Tests/Mapping/Types/Core/Text/TextPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public TextPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cl
max = 100.00,
min_segment_size = 2
},
index_prefixes = new
{
min_chars = 1,
max_chars = 10
},
fields = new
{
raw = new
Expand Down Expand Up @@ -68,6 +73,10 @@ public TextPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cl
.Max(100)
.MinSegmentSize(2)
)
.IndexPrefixes(i => i
.MinCharacters(1)
.MaxCharacters(10)
)
.Fields(fd => fd
.Keyword(k => k
.Name("raw")
Expand Down Expand Up @@ -101,6 +110,11 @@ public TextPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cl
Max = 100,
MinSegmentSize = 2
},
IndexPrefixes = new TextIndexPrefixes
{
MinCharacters = 1,
MaxCharacters = 10
},
Fields = new Properties
{
{ "raw", new KeywordProperty
Expand Down