Skip to content

Commit e18650f

Browse files
russcamMpdreamz
authored andcommitted
Changes to queries for 5.0 (#2046)
See https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_search_changes.html#_changes_to_queries for details. See #1997 deprecate fuzziness ratio and make setting it a noop. It looks like this was deprecated in 1.7 and should have been removed in 2.0 - https://www.elastic.co/guide/en/elasticsearch/reference/1.7/common-options.html#fuzziness
1 parent 42eae5b commit e18650f

File tree

7 files changed

+41
-33
lines changed

7 files changed

+41
-33
lines changed

Diff for: src/Nest/CommonOptions/Fuzziness/Fuzziness.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
namespace Nest
1+
using System;
2+
3+
namespace Nest
24
{
35
public class Fuzziness : IFuzziness
46
{
57
private bool _auto;
68
private int? _editDistance;
79
private double? _ratio;
8-
bool IFuzziness.Auto { get { return this._auto; } }
9-
int? IFuzziness.EditDistance { get { return this._editDistance; } }
10-
double? IFuzziness.Ratio { get { return this._ratio; } }
10+
bool IFuzziness.Auto => this._auto;
11+
12+
int? IFuzziness.EditDistance => this._editDistance;
13+
14+
[Obsolete("Deprecated. Setting this is a noop")]
15+
double? IFuzziness.Ratio => this._ratio;
1116

12-
public static Fuzziness Auto { get { return new Fuzziness() { _auto = true }; } }
17+
public static Fuzziness Auto => new Fuzziness { _auto = true };
1318

14-
public static Fuzziness EditDistance(int distance)
15-
{
16-
return new Fuzziness() { _editDistance = distance };
17-
}
19+
public static Fuzziness EditDistance(int distance) => new Fuzziness { _editDistance = distance };
1820

19-
public static Fuzziness Ratio(double ratio)
20-
{
21-
return new Fuzziness() { _ratio = ratio };
22-
}
21+
[Obsolete("Deprecated. Setting this is a noop")]
22+
public static Fuzziness Ratio(double ratio) => new Fuzziness { _ratio = ratio };
2323
}
24-
}
24+
}

Diff for: src/Nest/CommonOptions/Fuzziness/FuzzinessJsonConverter.cs

+4-10
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ internal class FuzzinessJsonConverter : JsonConverter
1212
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
1313
{
1414
var v = value as IFuzziness;
15-
if (v.Auto) writer.WriteValue("AUTO");
16-
else if (v.EditDistance.HasValue) writer.WriteValue(v.EditDistance.Value);
17-
else if (v.Ratio.HasValue) writer.WriteValue(v.Ratio.Value);
18-
else writer.WriteNull();
15+
if (v.Auto) writer.WriteValue("AUTO");
16+
else if (v.EditDistance.HasValue) writer.WriteValue(v.EditDistance.Value);
17+
else writer.WriteNull();
1918
}
2019

2120
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
@@ -27,13 +26,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
2726
var editDistance = Convert.ToInt32(reader.Value);
2827
return Fuzziness.EditDistance(editDistance);
2928
}
30-
if (reader.TokenType == JsonToken.Float)
31-
{
32-
var ratio = (reader.Value as double?).GetValueOrDefault(0);
33-
return Fuzziness.Ratio(ratio);
34-
}
3529
return null;
3630
}
3731

3832
}
39-
}
33+
}

Diff for: src/Nest/CommonOptions/Fuzziness/IFuzziness.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using System;
2+
using Newtonsoft.Json;
23

34
namespace Nest
45
{
@@ -7,6 +8,8 @@ public interface IFuzziness
78
{
89
bool Auto { get; }
910
int? EditDistance { get; }
11+
12+
[Obsolete("Deprecated. Setting this is a noop")]
1013
double? Ratio { get; }
1114
}
12-
}
15+
}

Diff for: src/Nest/QueryDsl/TermLevel/Terms/TermsQuery.cs

+8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ namespace Nest
1010
[JsonConverter(typeof(TermsQueryJsonConverter))]
1111
public interface ITermsQuery : IFieldNameQuery
1212
{
13+
[Obsolete("Will be removed in 5.0. Use bool query instead")]
1314
MinimumShouldMatch MinimumShouldMatch { get; set; }
15+
[Obsolete("Will be removed in 5.0. Use bool query instead")]
1416
bool? DisableCoord { get; set; }
1517
IEnumerable<object> Terms { get; set; }
1618
IFieldLookup TermsLookup { get; set; }
@@ -19,7 +21,9 @@ public interface ITermsQuery : IFieldNameQuery
1921
public class TermsQuery : FieldNameQueryBase, ITermsQuery
2022
{
2123
protected override bool Conditionless => IsConditionless(this);
24+
[Obsolete("Will be removed in 5.0. Use bool query instead")]
2225
public MinimumShouldMatch MinimumShouldMatch { get; set; }
26+
[Obsolete("Will be removed in 5.0. Use bool query instead")]
2327
public bool? DisableCoord { get; set; }
2428
public IEnumerable<object> Terms { get; set; }
2529
public IFieldLookup TermsLookup { get; set; }
@@ -54,16 +58,20 @@ public class TermsQueryDescriptor<T>
5458
, ITermsQuery where T : class
5559
{
5660
protected override bool Conditionless => TermsQuery.IsConditionless(this);
61+
[Obsolete("Will be removed in 5.0. Use bool query instead")]
5762
MinimumShouldMatch ITermsQuery.MinimumShouldMatch { get; set; }
63+
[Obsolete("Will be removed in 5.0. Use bool query instead")]
5864
bool? ITermsQuery.DisableCoord { get; set; }
5965
IEnumerable<object> ITermsQuery.Terms { get; set; }
6066
IFieldLookup ITermsQuery.TermsLookup { get; set; }
6167

6268
public TermsQueryDescriptor<T> TermsLookup<TOther>(Func<FieldLookupDescriptor<TOther>, IFieldLookup> selector)
6369
where TOther : class => Assign(a => a.TermsLookup = selector(new FieldLookupDescriptor<TOther>()));
6470

71+
[Obsolete("Will be removed in 5.0. Use bool query instead")]
6572
public TermsQueryDescriptor<T> MinimumShouldMatch(MinimumShouldMatch minMatch) => Assign(a => a.MinimumShouldMatch = minMatch);
6673

74+
[Obsolete("Will be removed in 5.0. Use bool query instead")]
6775
public TermsQueryDescriptor<T> DisableCoord(bool? disable = true) => Assign(a => a.DisableCoord = disable);
6876

6977
public TermsQueryDescriptor<T> Terms<TValue>(IEnumerable<TValue> terms) => Assign(a => a.Terms = terms?.Cast<object>());

Diff for: src/Nest/QueryDsl/TermLevel/Terms/TermsQueryJsonConverter.cs

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
3232
writer.WritePropertyName(field);
3333
serializer.Serialize(writer, t.TermsLookup);
3434
}
35+
#pragma warning disable 618
3536
if (t.DisableCoord.HasValue)
3637
{
3738
writer.WritePropertyName("disable_coord");
@@ -42,6 +43,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
4243
writer.WritePropertyName("minimum_should_match");
4344
serializer.Serialize(writer, t.MinimumShouldMatch);
4445
}
46+
#pragma warning restore 618
4547
if (t.Boost.HasValue)
4648
{
4749
writer.WritePropertyName("boost");
@@ -68,6 +70,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
6870
var property = reader.Value as string;
6971
switch (property)
7072
{
73+
#pragma warning disable 618
7174
case "disable_coord":
7275
reader.Read();
7376
f.DisableCoord = reader.Value as bool?;
@@ -77,6 +80,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
7780
var min = serializer.Deserialize<MinimumShouldMatch>(reader);
7881
f.MinimumShouldMatch = min;
7982
break;
83+
#pragma warning restore 618
8084
case "boost":
8185
reader.Read();
8286
f.Boost = reader.Value as double?;

Diff for: src/Tests/QueryDsl/TermLevel/Terms/TermsListQueryUsageTests.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using Tests.Framework.Integration;
88
using Tests.Framework.MockData;
99

10+
#pragma warning disable 618 // DisableCoord and MinimumShouldMatch
11+
1012
namespace Tests.QueryDsl.TermLevel.Terms
1113
{
1214
public class TermsListQueryUsageTests : QueryDslUsageTestsBase
@@ -80,7 +82,6 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
8082
.DisableCoord()
8183
.Terms(_terms)
8284
);
83-
8485
}
8586

8687
public class TermsListOfListStringAgainstNumericFieldIntegrationTests : QueryDslIntegrationTestsBase
@@ -132,7 +133,5 @@ [I] public Task AsserResponse() => AssertOnAllResponses(r =>
132133
var rootCause = rootCauses.First();
133134
rootCause.Type.Should().Be("number_format_exception");
134135
});
135-
136136
}
137-
138137
}

Diff for: src/Tests/QueryDsl/TermLevel/Terms/TermsQueryUsageTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
namespace Tests.QueryDsl.TermLevel.Terms
88
{
9-
/**
9+
#pragma warning disable 618 // DisableCoord and MinimumShouldMatch
10+
11+
/**
1012
* Filters documents that have fields that match any of the provided terms (not analyzed).
1113
*
1214
* Be sure to read the Elasticsearch documentation on {ref_current}/query-dsl-terms-query.html[Terms query] for more information.
@@ -59,7 +61,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
5961
}
6062

6163
/**[float]
62-
*== Single term Terms Query
64+
*== Single term Terms Query
6365
*/
6466
public class SingleTermTermsQueryUsageTests : TermsQueryUsageTests
6567
{
@@ -77,6 +79,4 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
7779
.Terms("term1")
7880
);
7981
}
80-
81-
8282
}

0 commit comments

Comments
 (0)