Skip to content

Commit 0fdcdbf

Browse files
committed
Merge pull request #1388 from elastic/feature/min-score-type
Has child/top children: support for min score type and min/max_children
2 parents f0c7da1 + ea9bbd3 commit 0fdcdbf

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/Nest/DSL/Query/HasChildQueryDescriptor.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public interface IHasChildQuery : IQuery
1818
[JsonConverter(typeof (StringEnumConverter))]
1919
ChildScoreType? ScoreType { get; set; }
2020

21+
[JsonProperty("min_children")]
22+
int? MinChildren { get; set; }
23+
24+
[JsonProperty("max_children")]
25+
int? MaxChildren { get; set; }
26+
2127
[JsonProperty("query")]
2228
[JsonConverter(typeof(CompositeJsonConverter<ReadAsTypeConverter<QueryDescriptor<object>>, CustomJsonConverter>))]
2329
IQueryContainer Query { get; set; }
@@ -39,6 +45,8 @@ protected override void WrapInContainer(IQueryContainer container)
3945
bool IQuery.IsConditionless { get { return false; } }
4046
public TypeNameMarker Type { get; set; }
4147
public ChildScoreType? ScoreType { get; set; }
48+
public int? MinChildren { get; set; }
49+
public int? MaxChildren { get; set; }
4250
public IQueryContainer Query { get; set; }
4351
public IInnerHits InnerHits { get; set; }
4452
}
@@ -51,6 +59,10 @@ public class HasChildQueryDescriptor<T> : IHasChildQuery where T : class
5159

5260
ChildScoreType? IHasChildQuery.ScoreType { get; set; }
5361

62+
int? IHasChildQuery.MinChildren { get; set; }
63+
64+
int? IHasChildQuery.MaxChildren { get; set; }
65+
5466
IQueryContainer IHasChildQuery.Query { get; set; }
5567

5668
IInnerHits IHasChildQuery.InnerHits { get; set; }
@@ -95,6 +107,18 @@ public HasChildQueryDescriptor<T> Score(ChildScoreType? scoreType)
95107
return this;
96108
}
97109

110+
public HasChildQueryDescriptor<T> MinChildren(int minChildren)
111+
{
112+
Self.MinChildren = minChildren;
113+
return this;
114+
}
115+
116+
public HasChildQueryDescriptor<T> MaxChildren(int maxChildren)
117+
{
118+
Self.MaxChildren = maxChildren;
119+
return this;
120+
}
121+
98122
public HasChildQueryDescriptor<T> InnerHits()
99123
{
100124
Self.InnerHits = new InnerHits();

src/Nest/Domain/DSL/ChildScoreType.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public enum ChildScoreType
1717
[EnumMember(Value = "sum")]
1818
Sum,
1919
[EnumMember(Value = "max")]
20-
Max
20+
Max,
21+
[EnumMember(Value = "min")]
22+
Min
2123
}
2224
}

src/Nest/Enums/TopChildrenScore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public enum TopChildrenScore
1515
[EnumMember(Value = "sum")]
1616
Sum,
1717
[EnumMember(Value = "avg")]
18-
Average
18+
Average,
19+
[EnumMember(Value = "min")]
20+
Min
1921
}
20-
21-
2222
}

src/Tests/Nest.Tests.Unit/QueryParsers/Queries/HasChildQueryTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ public void HasChild_Deserializes()
1616
f=>f.HasChild<Person>(hq=>hq
1717
.Query(qq=>Query2)
1818
.Score(ChildScoreType.Average)
19+
.MinChildren(2)
20+
.MaxChildren(10)
1921
.InnerHits()
2022
)
2123
);
2224
q.Type.Should().Be("person");
2325
q.ScoreType.Should().Be(ChildScoreType.Average);
2426
q.InnerHits.Should().NotBeNull();
27+
q.MinChildren.Should().Be(2);
28+
q.MaxChildren.Should().Be(10);
2529
AssertIsTermQuery(q.Query, Query2);
2630
}
2731
}

0 commit comments

Comments
 (0)