Skip to content

Commit 035e102

Browse files
committed
Merge branch 'fix/2.x-querycontainer-instantiations' into 2.x
2 parents 50c9cf9 + 9c83836 commit 035e102

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ namespace Nest
88
[JsonObject(MemberSerialization.OptIn)]
99
public class QueryContainerDescriptor<T> : QueryContainer where T : class
1010
{
11-
private QueryContainerDescriptor<T> Assign(Action<IQueryContainer> assigner) => Fluent.Assign(this, assigner);
12-
1311
[Obsolete("Scheduled to be removed in 5.0.0. Setting Strict() at the container level does is a noop and must be set on each individual query.")]
1412
public QueryContainerDescriptor<T> Strict(bool strict = true) => this;
1513

1614
[Obsolete("Scheduled to be removed in 5.0.0. Setting Verbatim() at the container level is a noop and must be set on each individual query.")]
1715
public QueryContainerDescriptor<T> Verbatim(bool verbatim = true) => this;
1816

19-
private static QueryContainer WrapInContainer<TQuery, TQueryInterface>(
17+
private QueryContainer WrapInContainer<TQuery, TQueryInterface>(
2018
Func<TQuery, TQueryInterface> create,
2119
Action<TQueryInterface, IQueryContainer> assign
2220
)
2321
where TQuery : class, TQueryInterface, IQuery, new()
2422
where TQueryInterface : class, IQuery
25-
{
26-
var query = create.InvokeOrDefault(new TQuery());
27-
var container = new QueryContainerDescriptor<T>();
23+
{
24+
var container = this.ContainedQuery == null
25+
? this
26+
: new QueryContainerDescriptor<T>();
27+
28+
var query = create.InvokeOrDefault(new TQuery());
29+
2830
IQueryContainer c = container;
2931
c.IsVerbatim = query.IsVerbatim;
3032
c.IsStrict = query.IsStrict;
@@ -47,9 +49,9 @@ Action<TQueryInterface, IQueryContainer> assign
4749
/// Insert raw query json at this position of the query
4850
/// <para>Be sure to start your json with '{'</para>
4951
/// </summary>
50-
/// <param name="rawJson"></param>
51-
/// <returns></returns>
52-
public QueryContainer Raw(string rawJson) => Assign(a => a.RawQuery = new RawQueryDescriptor(rawJson));
52+
/// <param name="rawJson">The query dsl json</param>
53+
public QueryContainer Raw(string rawJson) =>
54+
WrapInContainer((RawQueryDescriptor descriptor) => descriptor.Raw(rawJson), (query, container) => container.RawQuery = query);
5355

5456
/// <summary>
5557
/// A query that uses a query parser in order to parse its content.

0 commit comments

Comments
 (0)