Skip to content

Commit fd6f4dc

Browse files
Mpdreamzrusscam
authored andcommitted
add split_queries_on_whitespace to keyword property mappings (#3431)
(cherry picked from commit 8a57b8f)
1 parent ab52371 commit fd6f4dc

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

src/Nest/Mapping/Types/Core/Keyword/KeywordAttribute.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,25 @@ public KeywordAttribute() : base(FieldType.Keyword) { }
1818
bool? IKeywordProperty.Index { get; set; }
1919
IndexOptions? IKeywordProperty.IndexOptions { get; set; }
2020
bool? IKeywordProperty.Norms { get; set; }
21+
bool? IKeywordProperty.SplitQueriesOnWhitespace { get; set; }
2122
string IKeywordProperty.NullValue { get; set; }
2223
string IKeywordProperty.Normalizer { get; set; }
2324

25+
// ReSharper disable ArrangeThisQualifier
2426
public double Boost { get => Self.Boost.GetValueOrDefault(); set => Self.Boost = value; }
2527
public bool EagerGlobalOrdinals { get => Self.EagerGlobalOrdinals.GetValueOrDefault(); set => Self.EagerGlobalOrdinals = value; }
2628
public int IgnoreAbove { get => Self.IgnoreAbove.GetValueOrDefault(); set => Self.IgnoreAbove = value; }
2729
public bool Index { get => Self.Index.GetValueOrDefault(); set => Self.Index = value; }
2830
public IndexOptions IndexOptions { get => Self.IndexOptions.GetValueOrDefault(); set => Self.IndexOptions = value; }
2931
public string NullValue { get => Self.NullValue; set => Self.NullValue = value; }
3032
public bool Norms { get => Self.Norms.GetValueOrDefault(true); set => Self.Norms = value; }
33+
public bool SplitQueriesOnWhitespace
34+
{
35+
get => Self.SplitQueriesOnWhitespace.GetValueOrDefault(false);
36+
set => Self.SplitQueriesOnWhitespace = value;
37+
}
3138
public string Normalizer { get => Self.Normalizer; set => Self.Normalizer = value; }
39+
// ReSharper restore ArrangeThisQualifier
3240

3341
}
3442
}

src/Nest/Mapping/Types/Core/Keyword/KeywordProperty.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public interface IKeywordProperty : IDocValuesProperty
2929
[JsonProperty("norms")]
3030
bool? Norms { get; set; }
3131

32+
/// <summary> Whether full text queries should split the input on whitespace when building a query for this field. </summary>
33+
[JsonProperty("split_queries_on_whitespace")]
34+
bool? SplitQueriesOnWhitespace { get; set; }
35+
3236
[JsonProperty("null_value")]
3337
string NullValue { get; set; }
3438

@@ -47,6 +51,8 @@ public KeywordProperty() : base(FieldType.Keyword) { }
4751
public bool? Index { get; set; }
4852
public IndexOptions? IndexOptions { get; set; }
4953
public bool? Norms { get; set; }
54+
/// <inheritdoc cref="IKeywordProperty.SplitQueriesOnWhitespace"/>
55+
public bool? SplitQueriesOnWhitespace { get; set; }
5056
public string NullValue { get; set; }
5157
public string Normalizer { get; set; }
5258
}
@@ -62,6 +68,7 @@ public class KeywordPropertyDescriptor<T>
6268
bool? IKeywordProperty.Index{ get; set; }
6369
IndexOptions? IKeywordProperty.IndexOptions{ get; set; }
6470
bool? IKeywordProperty.Norms{ get; set; }
71+
bool? IKeywordProperty.SplitQueriesOnWhitespace { get; set; }
6572
string IKeywordProperty.NullValue{ get; set; }
6673
string IKeywordProperty.Normalizer{ get; set; }
6774

@@ -73,6 +80,8 @@ public KeywordPropertyDescriptor() : base(FieldType.Keyword) { }
7380
public KeywordPropertyDescriptor<T> Index(bool? index = true) => Assign(a => a.Index = index);
7481
public KeywordPropertyDescriptor<T> IndexOptions(IndexOptions? indexOptions) => Assign(a => a.IndexOptions = indexOptions);
7582
public KeywordPropertyDescriptor<T> Norms(bool? enabled = true) => Assign(a => a.Norms = enabled);
83+
/// <inheritdoc cref="IKeywordProperty.SplitQueriesOnWhitespace"/>
84+
public KeywordPropertyDescriptor<T> SplitQueriesOnWhitespace(bool? split = true) => Assign(a => a.SplitQueriesOnWhitespace = split);
7685
public KeywordPropertyDescriptor<T> NullValue(string nullValue) => Assign(a => a.NullValue = nullValue);
7786
public KeywordPropertyDescriptor<T> Normalizer(string normalizer) => Assign(a => a.Normalizer = normalizer);
7887
}

src/Tests/Tests.Configuration/tests.default.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# tracked by git).
66

77
# mode either u (unit test), i (integration test) or m (mixed mode)
8-
mode: u
8+
mode: m
99
# the elasticsearch version that should be started
1010
# Can be a snapshot version of sonatype or "latest" to get the latest snapshot of sonatype
1111
elasticsearch_version: 6.4.1

src/Tests/Tests/Mapping/Types/Core/Keyword/KeywordPropertyTests.cs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
using System;
22
using Elastic.Xunit.XunitPlumbing;
3-
using Elasticsearch.Net;
43
using Nest;
54
using Tests.Analysis;
65
using Tests.Analysis.Tokenizers;
76
using Tests.Core.ManagedElasticsearch.Clusters;
87
using Tests.Domain;
9-
using Tests.Framework;
108
using Tests.Framework.Integration;
11-
using Tests.Framework.ManagedElasticsearch.Clusters;
129
using static Tests.Framework.Promisify;
1310

1411
namespace Tests.Mapping.Types.Core.Keyword
1512
{
1613
[SkipVersion("<5.2.0", "This uses the normalizer feature introduced in 5.2.0")]
1714
public class KeywordPropertyTests : PropertyTestsBase
1815
{
19-
public KeywordPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
16+
public KeywordPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage)
17+
{
18+
}
2019

2120
protected override ICreateIndexRequest CreateIndexSettings(CreateIndexDescriptor create) => create
2221
.Settings(s => s
@@ -82,7 +81,8 @@ protected override ICreateIndexRequest CreateIndexSettings(CreateIndexDescriptor
8281

8382
protected override IProperties InitializerProperties => new Properties
8483
{
85-
{ "state", new KeywordProperty
84+
{
85+
"state", new KeywordProperty
8686
{
8787
DocValues = false,
8888
Boost = 1.2,
@@ -97,10 +97,50 @@ protected override ICreateIndexRequest CreateIndexSettings(CreateIndexDescriptor
9797
Store = true,
9898
Fields = new Properties
9999
{
100-
{ "foo", new KeywordProperty { IgnoreAbove = 10 } }
100+
{"foo", new KeywordProperty {IgnoreAbove = 10}}
101101
}
102102
}
103103
}
104104
};
105+
106+
[SkipVersion("<6.4.0", "split_queries_on_whitespace is a new option https://github.com/elastic/elasticsearch/pull/30691")]
107+
public class KeywordPropertySplitQueriesOnWhitespaceTests : PropertyTestsBase
108+
{
109+
public KeywordPropertySplitQueriesOnWhitespaceTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
110+
111+
protected override ICreateIndexRequest CreateIndexSettings(CreateIndexDescriptor create) => create
112+
.Settings(s => s
113+
.Analysis(a => a
114+
.CharFilters(t => Promise(Analysis.CharFilters.CharFilterUsageTests.FluentExample(s).Value.Analysis.CharFilters))
115+
.TokenFilters(
116+
t => Promise(Analysis.TokenFilters.TokenFilterUsageTests.FluentExample(s).Value.Analysis.TokenFilters))
117+
.Normalizers(t => Promise(Analysis.Normalizers.NormalizerUsageTests.FluentExample(s).Value.Analysis.Normalizers))
118+
)
119+
);
120+
121+
protected override object ExpectJson => new
122+
{
123+
properties = new
124+
{
125+
state = new
126+
{
127+
type = "keyword",
128+
split_queries_on_whitespace = true
129+
}
130+
}
131+
};
132+
133+
protected override Func<PropertiesDescriptor<Project>, IPromise<IProperties>> FluentProperties => f => f
134+
.Keyword(b => b
135+
.Name(p => p.State)
136+
.SplitQueriesOnWhitespace()
137+
);
138+
139+
140+
protected override IProperties InitializerProperties => new Properties
141+
{
142+
{ "state", new KeywordProperty { SplitQueriesOnWhitespace = true } }
143+
};
144+
}
105145
}
106146
}

0 commit comments

Comments
 (0)