Skip to content

Commit 5fcb9a4

Browse files
committed
Has child/parent integration tests for inner hits
1 parent d2b6363 commit 5fcb9a4

File tree

1 file changed

+61
-8
lines changed

1 file changed

+61
-8
lines changed

src/Tests/Nest.Tests.Integration/Search/InnerHitsTests.cs

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public InnerHitsTests()
2828
);
2929

3030
var bulk = new BulkDescriptor();
31-
IndexAll(bulk, ()=> NestTestData.Session.List<King>(2).Get(), indexChildren: king =>
32-
IndexAll(bulk, ()=> NestTestData.Session.List<Prince>(2).Get(), king.Name, prince =>
33-
IndexAll(bulk, ()=> NestTestData.Session.List<Duke>(3).Get(), prince.Name, duke =>
34-
IndexAll(bulk, ()=> NestTestData.Session.List<Earl>(5).Get(), duke.Name, earl =>
35-
IndexAll(bulk, ()=> NestTestData.Session.List<Baron>(1).Get(), earl.Name)
31+
IndexAll(bulk, () => NestTestData.Session.List<King>(2).Get(), indexChildren: king =>
32+
IndexAll(bulk, () => NestTestData.Session.List<Prince>(2).Get(), king.Name, prince =>
33+
IndexAll(bulk, () => NestTestData.Session.List<Duke>(3).Get(), prince.Name, duke =>
34+
IndexAll(bulk, () => NestTestData.Session.List<Earl>(5).Get(), duke.Name, earl =>
35+
IndexAll(bulk, () => NestTestData.Session.List<Baron>(1).Get(), earl.Name)
3636
)
3737
)
3838
)
@@ -58,20 +58,73 @@ private void IndexAll<TRoyal>(BulkDescriptor bulk, Func<IList<TRoyal>> create, s
5858
}
5959

6060
[Test]
61+
[SkipVersion("0 - 1.4.9", "Inner hits introduced in 1.5")]
62+
public void HasParent()
63+
{
64+
var results = this.Client.Search<Prince>(s => s
65+
.Index(this._indexName)
66+
.Query(q => q
67+
.HasParent<King>(hp => hp
68+
.Query(qq => qq.MatchAll())
69+
.InnerHits()
70+
)
71+
)
72+
);
73+
74+
results.IsValid.Should().BeTrue();
75+
results.Hits.Should().NotBeEmpty();
76+
foreach(var hit in results.Hits)
77+
{
78+
var kings = hit.InnerHits["king"].Documents<King>();
79+
kings.Should().NotBeEmpty();
80+
}
81+
}
82+
83+
[Test]
84+
[SkipVersion("0 - 1.4.9", "Inner hits introduced in 1.5")]
85+
public void HasChild()
86+
{
87+
var results = this.Client.Search<King>(s => s
88+
.Index(this._indexName)
89+
.Query(q => q
90+
.Filtered(f => f
91+
.Filter(ff => ff
92+
.HasChild<Prince>(hc => hc
93+
.Query(qq => qq.MatchAll())
94+
.InnerHits(ih => ih
95+
.Name("princes")
96+
)
97+
)
98+
)
99+
)
100+
)
101+
);
102+
103+
results.IsValid.Should().BeTrue();
104+
results.Hits.Should().NotBeEmpty();
105+
foreach (var hit in results.Hits)
106+
{
107+
var princes = hit.InnerHits["princes"].Documents<Prince>();
108+
princes.Should().NotBeEmpty();
109+
};
110+
}
111+
112+
[Test]
113+
[SkipVersion("0 - 1.4.9", "Inner hits introduced in 1.5")]
61114
public void Search()
62115
{
63116
var results = this.Client.Search<Duke>(s => s
64117
.Index(this._indexName)
65118
.InnerHits(innerHits => innerHits
66119
.Add("earls", i => i
67-
.Type<Earl>(ii=>ii
120+
.Type<Earl>(ii => ii
68121
.Size(5)
69122
.InnerHits(innerInnerHits => innerInnerHits
70-
.Add("barons", iii=>iii.Type<Baron>())
123+
.Add("barons", iii => iii.Type<Baron>())
71124
)
72125
)
73126
)
74-
.Add("princes", i=>i.Type<Prince>())
127+
.Add("princes", i => i.Type<Prince>())
75128
)
76129
);
77130
results.IsValid.Should().BeTrue();

0 commit comments

Comments
 (0)