Skip to content

Commit f2e893b

Browse files
committed
added reprocude tests for #346 to demonstrate that spawning subqueries of a parent lambda leads to wrong queries fix #346
1 parent ecee021 commit f2e893b

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

src/Nest.Tests.Integration/Nest.Tests.Integration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<Compile Include="Integration\HighlightTests.cs" />
111111
<Compile Include="Integration\Query\TermQueryDynamic.cs" />
112112
<Compile Include="Mapping\NotAnalyzedTest.cs" />
113+
<Compile Include="Reproduce\Reproduce346Tests.cs" />
113114
<Compile Include="Reproduce\Reproduce325Tests.cs" />
114115
<Compile Include="Reproduce\Reproduce308Tests.cs" />
115116
<Compile Include="Reproduce\Reproduce319Tests.cs" />
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
5+
using Nest.Tests.MockData;
6+
using Nest.Tests.MockData.Domain;
7+
using NUnit.Framework;
8+
using System.Diagnostics;
9+
using FluentAssertions;
10+
11+
namespace Nest.Tests.Integration.Reproduce
12+
{
13+
/// <summary>
14+
/// tests to reproduce reported errors
15+
/// </summary>
16+
[TestFixture]
17+
public class Reproduce346Tests : IntegrationTests
18+
{
19+
public class MediaStreamEntry
20+
{
21+
public int Id { get; set; }
22+
public Guid StreamId { get; set; }
23+
public ApprovalSettings ApprovalSettings { get; set; }
24+
}
25+
public class ApprovalSettings
26+
{
27+
public bool Approved { get; set; }
28+
}
29+
30+
31+
/// <summary>
32+
/// https://github.com/Mpdreamz/NEST/issues/346
33+
/// </summary>
34+
[Test]
35+
public void NoSearchResults()
36+
{
37+
//test teardown will delete defaultindex_* indices
38+
//process id makes it so we can run these tests concurrently using NCrunch
39+
var index = ElasticsearchConfiguration.DefaultIndex + "_posts_" + Process.GetCurrentProcess().Id.ToString();
40+
41+
var client = new ElasticClient(this._settings, new InMemoryConnection(this._settings));
42+
43+
var streamId = new Guid("8d00cf65-bf84-4035-9adb-695b1366304c");
44+
var approved = true;
45+
46+
var response = client.Count<MediaStreamEntry>(
47+
new[] { "StreamEntry" },
48+
x => x.Bool(
49+
b => b.Must
50+
(
51+
x.Term(f => f.StreamId, streamId.ToString())
52+
, x.Term(f => f.ApprovalSettings.Approved, approved)
53+
)
54+
)
55+
);
56+
57+
//Approval settings appears twice because we are spawing the nested queries of x
58+
Assert.AreEqual(2, Regex.Matches(response.ConnectionStatus.Request, @"approvalSettings\.approved").Count);
59+
60+
//either use the lambda overload
61+
response = client.Count<MediaStreamEntry>(
62+
new[] { "StreamEntry" },
63+
x => x.Bool(
64+
b => b.Must
65+
(
66+
m=> m.Term(f => f.StreamId, streamId.ToString())
67+
, m => m.Term(f => f.ApprovalSettings.Approved, approved)
68+
)
69+
)
70+
);
71+
72+
//now we only see the query once
73+
Assert.AreEqual(1, Regex.Matches(response.ConnectionStatus.Request, @"approvalSettings\.approved").Count);
74+
75+
76+
//or use the static Query<MediaStreamEntry>
77+
response = client.Count<MediaStreamEntry>(
78+
new[] { "StreamEntry" },
79+
x => x.Bool(
80+
b => b.Must
81+
(
82+
Query<MediaStreamEntry>.Term(f => f.StreamId, streamId.ToString())
83+
, Query<MediaStreamEntry>.Term(f => f.ApprovalSettings.Approved, approved.ToString())
84+
)
85+
)
86+
);
87+
88+
//now we still only see the query once
89+
Assert.AreEqual(1, Regex.Matches(response.ConnectionStatus.Request, @"approvalSettings\.approved").Count);
90+
}
91+
92+
}
93+
}

0 commit comments

Comments
 (0)