Skip to content

Commit 1ca27ac

Browse files
committed
Merge branch 'master' of github.com:elastic/elasticsearch-net
2 parents 5ebfdd9 + 1cc6a23 commit 1ca27ac

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/Nest/QueryDsl/Abstractions/Container/QueryContainerDescriptor.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ Action<TQueryInterface, IQueryContainer> assign
1616
where TQuery : class, TQueryInterface, IQuery, new()
1717
where TQueryInterface : class, IQuery
1818
{
19+
// Invoke the create delegate before assigning container; the create delegate
20+
// may mutate the current QueryContainerDescriptor<T> instance such that it
21+
// contains a query. See https://github.com/elastic/elasticsearch-net/issues/2875
22+
var query = create.InvokeOrDefault(new TQuery());
23+
1924
var container = this.ContainedQuery == null
2025
? this
2126
: new QueryContainerDescriptor<T>();
2227

23-
var query = create.InvokeOrDefault(new TQuery());
24-
2528
IQueryContainer c = container;
2629
c.IsVerbatim = query.IsVerbatim;
2730
c.IsStrict = query.IsStrict;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Nest;
2+
using Tests.Framework;
3+
using Tests.Framework.MockData;
4+
using static Tests.Framework.RoundTripper;
5+
6+
namespace Tests.Reproduce
7+
{
8+
public class GithubIssue2875
9+
{
10+
11+
[U] public void ReusingQueryDescriptorOutSideOfSelector()
12+
{
13+
Expect(new
14+
{
15+
query = new {
16+
@bool = new
17+
{
18+
must = new []
19+
{
20+
new { term = new { field = new { value = "value" } }}
21+
}
22+
23+
}
24+
}
25+
}).FromRequest(ReuseQueryDescriptorUnexpected);
26+
}
27+
28+
private static ISearchResponse<Project> ReuseQueryDescriptorUnexpected(IElasticClient client) => client.Search<Project>(s => s
29+
.Query(q => q
30+
.Bool(b => b
31+
.Must(q.Term("field", "value"))
32+
)
33+
)
34+
);
35+
}
36+
}

0 commit comments

Comments
 (0)