Skip to content

Commit a84e56f

Browse files
committed
Changes to queries for 5.0
See https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_search_changes.html#_changes_to_queries for details. Remove NestedScoreMode.Total and add NestedScoreMode.Min and NestedScoreMode.Sum Mark CollectPayloads as deprecated Remove MinimumShouldMatch and DisableCoord from TermsQuery Fixes #1997
1 parent 3ea0390 commit a84e56f

File tree

9 files changed

+58
-68
lines changed

9 files changed

+58
-68
lines changed

Diff for: src/Nest/Document/Single/TermVectors/TermVectorsRequest.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public partial interface ITermVectorsRequest<TDocument>
99
where TDocument : class
1010
{
1111
/// <summary>
12-
/// An optional document to get termvectors for instead of using an already indexed document
12+
/// An optional document to get term vectors for instead of using an already indexed document
1313
/// </summary>
1414
[JsonProperty("doc")]
1515
TDocument Document { get; set; }
@@ -26,6 +26,9 @@ public partial class TermVectorsRequest<TDocument>
2626
{
2727
HttpMethod IRequest.HttpMethod => (this.Document != null || this.Filter != null) ? HttpMethod.POST : HttpMethod.GET;
2828

29+
/// <summary>
30+
/// An optional document to get term vectors for instead of using an already indexed document
31+
/// </summary>
2932
public TDocument Document { get; set; }
3033

3134
public IPerFieldAnalyzer PerFieldAnalyzer { get; set; }
@@ -45,12 +48,18 @@ public partial class TermVectorsDescriptor<TDocument> where TDocument : class
4548
{
4649
HttpMethod IRequest.HttpMethod => (Self.Document != null || Self.Filter != null) ? HttpMethod.POST : HttpMethod.GET;
4750

51+
/// <summary>
52+
/// An optional document to get term vectors for instead of using an already indexed document
53+
/// </summary>
4854
TDocument ITermVectorsRequest<TDocument>.Document { get; set; }
4955

5056
IPerFieldAnalyzer ITermVectorsRequest<TDocument>.PerFieldAnalyzer { get; set; }
5157

5258
ITermVectorFilter ITermVectorsRequest<TDocument>.Filter { get; set; }
5359

60+
/// <summary>
61+
/// An optional document to get term vectors for instead of using an already indexed document
62+
/// </summary>
5463
public TermVectorsDescriptor<TDocument> Document(TDocument document) => Assign(a => a.Document = document);
5564

5665
public TermVectorsDescriptor<TDocument> PerFieldAnalyzer(Func<PerFieldAnalyzerDescriptor<TDocument>, IPromise<IPerFieldAnalyzer>> analyzerSelector) =>

Diff for: src/Nest/QueryDsl/Joining/HasChild/HasChildQuery.cs

+17-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public interface IHasChildQuery : IQuery
1616
[JsonProperty("min_children")]
1717
int? MinChildren { get; set; }
1818

19+
/// <summary>
20+
/// Specify how many child documents are allowed to match.
21+
/// </summary>
1922
[JsonProperty("max_children")]
2023
int? MaxChildren { get; set; }
2124

@@ -25,13 +28,17 @@ public interface IHasChildQuery : IQuery
2528
[JsonProperty("inner_hits")]
2629
IInnerHits InnerHits { get; set; }
2730
}
28-
31+
2932
public class HasChildQuery : QueryBase, IHasChildQuery
3033
{
3134
protected override bool Conditionless => IsConditionless(this);
3235
public TypeName Type { get; set; }
3336
public ChildScoreMode? ScoreMode { get; set; }
3437
public int? MinChildren { get; set; }
38+
39+
/// <summary>
40+
/// Specify how many child documents are allowed to match.
41+
/// </summary>
3542
public int? MaxChildren { get; set; }
3643
public QueryContainer Query { get; set; }
3744
public IInnerHits InnerHits { get; set; }
@@ -40,14 +47,18 @@ public class HasChildQuery : QueryBase, IHasChildQuery
4047
internal static bool IsConditionless(IHasChildQuery q) => q.Query == null || q.Query.IsConditionless || q.Type == null;
4148
}
4249

43-
public class HasChildQueryDescriptor<T>
50+
public class HasChildQueryDescriptor<T>
4451
: QueryDescriptorBase<HasChildQueryDescriptor<T>, IHasChildQuery>
4552
, IHasChildQuery where T : class
4653
{
4754
protected override bool Conditionless => HasChildQuery.IsConditionless(this);
4855
TypeName IHasChildQuery.Type { get; set; }
4956
ChildScoreMode? IHasChildQuery.ScoreMode { get; set; }
5057
int? IHasChildQuery.MinChildren { get; set; }
58+
59+
/// <summary>
60+
/// Specify how many child documents are allowed to match.
61+
/// </summary>
5162
int? IHasChildQuery.MaxChildren { get; set; }
5263
QueryContainer IHasChildQuery.Query { get; set; }
5364
IInnerHits IHasChildQuery.InnerHits { get; set; }
@@ -57,7 +68,7 @@ public HasChildQueryDescriptor()
5768
((IHasChildQuery)this).Type = TypeName.Create<T>();
5869
}
5970

60-
public HasChildQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryContainer> selector) =>
71+
public HasChildQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryContainer> selector) =>
6172
Assign(a => a.Query = selector?.InvokeQuery(new QueryContainerDescriptor<T>()));
6273

6374
public HasChildQueryDescriptor<T> Type(string type) => Assign(a => a.Type = type);
@@ -66,6 +77,9 @@ public HasChildQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryC
6677

6778
public HasChildQueryDescriptor<T> MinChildren(int? minChildren) => Assign(a => a.MinChildren = minChildren);
6879

80+
/// <summary>
81+
/// Specify how many child documents are allowed to match.
82+
/// </summary>
6983
public HasChildQueryDescriptor<T> MaxChildren(int? maxChildren) => Assign(a => a.MaxChildren = maxChildren);
7084

7185
public HasChildQueryDescriptor<T> InnerHits(Func<InnerHitsDescriptor<T>, IInnerHits> selector = null) =>

Diff for: src/Nest/QueryDsl/Joining/Nested/NestedScoreMode.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ public enum NestedScoreMode
99
{
1010
[EnumMember(Value = "avg")]
1111
Average,
12-
[EnumMember(Value = "total")]
13-
Total,
12+
[EnumMember(Value = "sum")]
13+
Sum,
14+
[EnumMember(Value = "min")]
15+
Min,
1416
[EnumMember(Value = "max")]
1517
Max,
1618
[EnumMember(Value = "none")]

Diff for: src/Nest/QueryDsl/Span/Near/SpanNearQuery.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ public interface ISpanNearQuery : ISpanSubQuery
1818
[JsonProperty(PropertyName = "in_order")]
1919
bool? InOrder { get; set; }
2020

21+
#pragma warning disable 618
2122
[JsonProperty(PropertyName = "collect_payloads")]
23+
[Obsolete("Payloads will be loaded when needed")]
2224
bool? CollectPayloads { get; set; }
25+
#pragma warning restore 618
2326
}
2427

2528
public class SpanNearQuery : QueryBase, ISpanNearQuery
@@ -28,21 +31,29 @@ public class SpanNearQuery : QueryBase, ISpanNearQuery
2831
public IEnumerable<ISpanQuery> Clauses { get; set; }
2932
public int? Slop { get; set; }
3033
public bool? InOrder { get; set; }
34+
35+
#pragma warning disable 618
36+
[Obsolete("Payloads will be loaded when needed")]
3137
public bool? CollectPayloads { get; set; }
38+
#pragma warning restore 618
3239

3340
internal override void WrapInContainer(IQueryContainer c) => c.SpanNear = this;
3441
internal static bool IsConditionless(ISpanNearQuery q) => !q.Clauses.HasAny() || q.Clauses.Cast<IQuery>().All(qq => qq.Conditionless);
3542
}
3643

37-
public class SpanNearQueryDescriptor<T>
44+
public class SpanNearQueryDescriptor<T>
3845
: QueryDescriptorBase<SpanNearQueryDescriptor<T>, ISpanNearQuery>
3946
, ISpanNearQuery where T : class
4047
{
4148
protected override bool Conditionless => SpanNearQuery.IsConditionless(this);
4249
IEnumerable<ISpanQuery> ISpanNearQuery.Clauses { get; set; }
4350
int? ISpanNearQuery.Slop { get; set; }
4451
bool? ISpanNearQuery.InOrder { get; set; }
52+
53+
#pragma warning disable 618
54+
[Obsolete("Payloads will be loaded when needed")]
4555
bool? ISpanNearQuery.CollectPayloads { get; set; }
56+
#pragma warning restore 618
4657

4758
public SpanNearQueryDescriptor<T> Clauses(params Func<SpanQueryDescriptor<T>, SpanQueryDescriptor<T>>[] selectors) => Clauses(selectors.ToList());
4859

@@ -56,6 +67,9 @@ public SpanNearQueryDescriptor<T> Clauses(IEnumerable<Func<SpanQueryDescriptor<T
5667

5768
public SpanNearQueryDescriptor<T> InOrder(bool? inOrder) => Assign(a => a.InOrder = inOrder);
5869

70+
#pragma warning disable 618
71+
[Obsolete("Payloads will be loaded when needed")]
5972
public SpanNearQueryDescriptor<T> CollectPayloads(bool? collectPayloads) => Assign(a => a.CollectPayloads = collectPayloads);
73+
#pragma warning restore 618
6074
}
6175
}

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

-10
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ namespace Nest
1010
[JsonConverter(typeof(TermsQueryJsonConverter))]
1111
public interface ITermsQuery : IFieldNameQuery
1212
{
13-
MinimumShouldMatch MinimumShouldMatch { get; set; }
14-
bool? DisableCoord { get; set; }
1513
IEnumerable<object> Terms { get; set; }
1614
IFieldLookup TermsLookup { get; set; }
1715
}
1816

1917
public class TermsQuery : FieldNameQueryBase, ITermsQuery
2018
{
2119
protected override bool Conditionless => IsConditionless(this);
22-
public MinimumShouldMatch MinimumShouldMatch { get; set; }
23-
public bool? DisableCoord { get; set; }
2420
public IEnumerable<object> Terms { get; set; }
2521
public IFieldLookup TermsLookup { get; set; }
2622

@@ -54,18 +50,12 @@ public class TermsQueryDescriptor<T>
5450
, ITermsQuery where T : class
5551
{
5652
protected override bool Conditionless => TermsQuery.IsConditionless(this);
57-
MinimumShouldMatch ITermsQuery.MinimumShouldMatch { get; set; }
58-
bool? ITermsQuery.DisableCoord { get; set; }
5953
IEnumerable<object> ITermsQuery.Terms { get; set; }
6054
IFieldLookup ITermsQuery.TermsLookup { get; set; }
6155

6256
public TermsQueryDescriptor<T> TermsLookup<TOther>(Func<FieldLookupDescriptor<TOther>, IFieldLookup> selector)
6357
where TOther : class => Assign(a => a.TermsLookup = selector(new FieldLookupDescriptor<TOther>()));
6458

65-
public TermsQueryDescriptor<T> MinimumShouldMatch(MinimumShouldMatch minMatch) => Assign(a => a.MinimumShouldMatch = minMatch);
66-
67-
public TermsQueryDescriptor<T> DisableCoord(bool? disable = true) => Assign(a => a.DisableCoord = disable);
68-
6959
public TermsQueryDescriptor<T> Terms<TValue>(IEnumerable<TValue> terms) => Assign(a => a.Terms = terms?.Cast<object>());
7060

7161
public TermsQueryDescriptor<T> Terms<TValue>(params TValue[] terms) => Assign(a => {

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

-19
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
3232
writer.WritePropertyName(field);
3333
serializer.Serialize(writer, t.TermsLookup);
3434
}
35-
if (t.DisableCoord.HasValue)
36-
{
37-
writer.WritePropertyName("disable_coord");
38-
writer.WriteValue(t.DisableCoord.Value);
39-
}
40-
if (t.MinimumShouldMatch != null)
41-
{
42-
writer.WritePropertyName("minimum_should_match");
43-
serializer.Serialize(writer, t.MinimumShouldMatch);
44-
}
4535
if (t.Boost.HasValue)
4636
{
4737
writer.WritePropertyName("boost");
@@ -68,15 +58,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
6858
var property = reader.Value as string;
6959
switch (property)
7060
{
71-
case "disable_coord":
72-
reader.Read();
73-
f.DisableCoord = reader.Value as bool?;
74-
break;
75-
case "minimum_should_match":
76-
reader.Read();
77-
var min = serializer.Deserialize<MinimumShouldMatch>(reader);
78-
f.MinimumShouldMatch = min;
79-
break;
8061
case "boost":
8162
reader.Read();
8263
f.Boost = reader.Value as double?;

Diff for: src/Nest/Search/Search/InnerHits/InnerHits.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,19 @@ public InnerHitsDescriptor<T> FielddataFields(params Expression<Func<T, object>>
9393

9494
public InnerHitsDescriptor<T> Version(bool? version = true) => Assign(a => a.Version = version);
9595

96-
public InnerHitsDescriptor<T> Sort(Func<SortDescriptor<T>, IPromise<IList<ISort>>> sortSelector) => Assign(a => a.Sort = sortSelector?.Invoke(new SortDescriptor<T>())?.Value);
96+
public InnerHitsDescriptor<T> Sort(Func<SortDescriptor<T>, IPromise<IList<ISort>>> selector) => Assign(a => a.Sort = selector?.Invoke(new SortDescriptor<T>())?.Value);
9797

9898
/// <summary>
9999
/// Allow to highlight search results on one or more fields. The implementation uses the either lucene fast-vector-highlighter or highlighter.
100100
/// </summary>
101-
public InnerHitsDescriptor<T> Highlight(Func<HighlightDescriptor<T>, IHighlight> highlightSelector) =>
102-
Assign(a => a.Highlight = highlightSelector?.Invoke(new HighlightDescriptor<T>()));
101+
public InnerHitsDescriptor<T> Highlight(Func<HighlightDescriptor<T>, IHighlight> selector) =>
102+
Assign(a => a.Highlight = selector?.Invoke(new HighlightDescriptor<T>()));
103103

104104
//TODO map source of union bool/SourceFileter
105105
public InnerHitsDescriptor<T> Source(bool include = true) => Assign(a => a.Source = !include ? SourceFilter.ExcludeAll : null);
106106

107-
public InnerHitsDescriptor<T> Source(Func<SourceFilterDescriptor<T>, ISourceFilter> sourceSelector) =>
108-
Assign(a => a.Source = sourceSelector?.Invoke(new SourceFilterDescriptor<T>()));
107+
public InnerHitsDescriptor<T> Source(Func<SourceFilterDescriptor<T>, ISourceFilter> selector) =>
108+
Assign(a => a.Source = selector?.Invoke(new SourceFilterDescriptor<T>()));
109109

110110
public InnerHitsDescriptor<T> ScriptFields(Func<ScriptFieldsDescriptor, IPromise<IScriptFields>> selector) =>
111111
Assign(a => a.ScriptFields = selector?.Invoke(new ScriptFieldsDescriptor())?.Value);

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

+4-16
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ public TermsListQueryUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) :
1919
{
2020
_name = "named_query",
2121
boost = 1.1,
22-
description = new[] { "term1", "term2" },
23-
disable_coord = true,
24-
minimum_should_match = 2
22+
description = new[] { "term1", "term2" }
2523
}
2624
};
2725

@@ -30,18 +28,14 @@ public TermsListQueryUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) :
3028
Name = "named_query",
3129
Boost = 1.1,
3230
Field = "description",
33-
Terms = new List<string> { "term1", "term2" },
34-
DisableCoord = true,
35-
MinimumShouldMatch = 2
31+
Terms = new List<string> { "term1", "term2" }
3632
};
3733

3834
protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project> q) => q
3935
.Terms(c => c
4036
.Name("named_query")
4137
.Boost(1.1)
4238
.Field(p => p.Description)
43-
.DisableCoord()
44-
.MinimumShouldMatch(MinimumShouldMatch.Fixed(2))
4539
.Terms(new List<string> { "term1", "term2" })
4640
);
4741
}
@@ -59,7 +53,6 @@ public TermsListOfListIntegrationTests(ReadOnlyCluster cluster, EndpointUsage us
5953
_name = "named_query",
6054
boost = 1.1,
6155
description = new[] { new [] { "term1", "term2" } },
62-
disable_coord = true,
6356
}
6457
};
6558

@@ -68,16 +61,14 @@ public TermsListOfListIntegrationTests(ReadOnlyCluster cluster, EndpointUsage us
6861
Name = "named_query",
6962
Boost = 1.1,
7063
Field = "description",
71-
Terms = _terms,
72-
DisableCoord = true,
64+
Terms = _terms
7365
};
7466

7567
protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project> q) => q
7668
.Terms(c => c
7769
.Name("named_query")
7870
.Boost(1.1)
7971
.Field(p => p.Description)
80-
.DisableCoord()
8172
.Terms(_terms)
8273
);
8374

@@ -99,8 +90,7 @@ public TermsListOfListStringAgainstNumericFieldIntegrationTests(ReadOnlyCluster
9990
{
10091
_name = "named_query",
10192
boost = 1.1,
102-
numberOfCommits = new[] { new [] { "term1", "term2" } },
103-
disable_coord = true,
93+
numberOfCommits = new[] { new [] { "term1", "term2" } }
10494
}
10595
};
10696

@@ -110,15 +100,13 @@ public TermsListOfListStringAgainstNumericFieldIntegrationTests(ReadOnlyCluster
110100
Boost = 1.1,
111101
Field = "numberOfCommits",
112102
Terms = _terms,
113-
DisableCoord = true,
114103
};
115104

116105
protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project> q) => q
117106
.Terms(c => c
118107
.Name("named_query")
119108
.Boost(1.1)
120109
.Field(p => p.NumberOfCommits)
121-
.DisableCoord()
122110
.Terms(_terms)
123111
);
124112

0 commit comments

Comments
 (0)