Skip to content

Commit a16398a

Browse files
committed
added constructors to QueryPathBase and its subclasses to be more inline with other OIS classes, deleteby query untyped OIS parameterless constructor no longer defaults to _all index to be more inline with search requests defaulting to the default index
1 parent 100f87d commit a16398a

File tree

10 files changed

+108
-27
lines changed

10 files changed

+108
-27
lines changed

Diff for: src/Nest/DSL/CountDescriptor.cs

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Elasticsearch.Net;
34
using Newtonsoft.Json;
45

@@ -28,6 +29,12 @@ public static void Update(ElasticsearchPathInfo<CountRequestParameters> pathInfo
2829

2930
public partial class CountRequest : QueryPathBase<CountRequestParameters>, ICountRequest
3031
{
32+
public CountRequest() {}
33+
34+
public CountRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
35+
36+
public CountRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
37+
3138
public IQueryContainer Query { get; set; }
3239

3340
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<CountRequestParameters> pathInfo)
@@ -39,6 +46,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
3946
public partial class CountRequest<T> : QueryPathBase<CountRequestParameters, T>, ICountRequest
4047
where T : class
4148
{
49+
public CountRequest() {}
50+
51+
public CountRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
52+
53+
public CountRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
54+
4255
public IQueryContainer Query { get; set; }
4356

4457
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<CountRequestParameters> pathInfo)

Diff for: src/Nest/DSL/DeleteByQueryDescriptor.cs

+12-23
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,14 @@ public static void Update(ElasticsearchPathInfo<DeleteByQueryRequestParameters>
3333

3434
public partial class DeleteByQueryRequest : QueryPathBase<DeleteByQueryRequestParameters>, IDeleteByQueryRequest
3535
{
36-
public IQueryContainer Query { get; set; }
36+
public DeleteByQueryRequest() {}
3737

38-
/// <summary>
39-
/// Sents a delete query to _all indices
40-
/// </summary>
41-
public DeleteByQueryRequest()
42-
{
43-
this.AllIndices = true;
44-
this.AllTypes = true;
45-
}
46-
47-
public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null)
48-
{
49-
this.Indices = new [] { index };
50-
if (type != null)
51-
this.Types = new[] { type };
52-
else this.AllTypes = true;
53-
}
38+
public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
39+
40+
public DeleteByQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
41+
42+
public IQueryContainer Query { get; set; }
5443

55-
public DeleteByQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null)
56-
{
57-
this.Indices = indices;
58-
this.AllTypes = !types.HasAny();
59-
this.Types = types;
60-
}
6144

6245
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<DeleteByQueryRequestParameters> pathInfo)
6346
{
@@ -68,6 +51,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
6851

6952
public partial class DeleteByQueryRequest<T> : QueryPathBase<DeleteByQueryRequestParameters, T>, IDeleteByQueryRequest where T : class
7053
{
54+
public DeleteByQueryRequest() {}
55+
56+
public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
57+
58+
public DeleteByQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
59+
7160
public IQueryContainer Query { get; set; }
7261

7362
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<DeleteByQueryRequestParameters> pathInfo)

Diff for: src/Nest/DSL/Paths/QueryPathDescriptor.cs

+38
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ public static void SetRouteParameters<TParameters, T>(
7777
public abstract class QueryPathBase<TParameters> : BasePathRequest<TParameters>, IQueryPath<TParameters>
7878
where TParameters : IRequestParameters, new()
7979
{
80+
protected QueryPathBase()
81+
{
82+
this.AllTypes = true;
83+
}
84+
85+
protected QueryPathBase(IndexNameMarker index, TypeNameMarker type = null)
86+
{
87+
this.Indices = new [] { index };
88+
if (type != null)
89+
this.Types = new[] { type };
90+
else this.AllTypes = true;
91+
}
92+
93+
protected QueryPathBase(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null)
94+
{
95+
this.Indices = indices;
96+
this.AllTypes = !types.HasAny();
97+
this.Types = types;
98+
}
99+
80100

81101
protected override void SetRouteParameters(IConnectionSettingsValues settings, ElasticsearchPathInfo<TParameters> pathInfo)
82102
{
@@ -94,6 +114,24 @@ public abstract class QueryPathBase<TParameters, T> : QueryPathBase<TParameters>
94114
where TParameters : IRequestParameters, new()
95115
where T : class
96116
{
117+
protected QueryPathBase()
118+
{
119+
this.AllIndices = false;
120+
this.AllTypes = false;
121+
}
122+
123+
protected QueryPathBase(IndexNameMarker index, TypeNameMarker type = null)
124+
{
125+
this.Indices = new [] { index };
126+
if (type != null)
127+
this.Types = new[] { type };
128+
}
129+
130+
protected QueryPathBase(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null)
131+
{
132+
this.Indices = indices;
133+
this.Types = types;
134+
}
97135

98136
protected override void SetRouteParameters(IConnectionSettingsValues settings, ElasticsearchPathInfo<TParameters> pathInfo)
99137
{

Diff for: src/Nest/DSL/SearchDescriptor.cs

+12
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ public static void Update(IConnectionSettingsValues settings, ElasticsearchPathI
127127

128128
public partial class SearchRequest : QueryPathBase<SearchRequestParameters>, ISearchRequest
129129
{
130+
public SearchRequest() {}
131+
132+
public SearchRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
133+
134+
public SearchRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
135+
130136
private Type _clrType { get; set; }
131137
Type ISearchRequest.ClrType { get { return _clrType; } }
132138

@@ -186,6 +192,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
186192
public partial class SearchRequest<T> : QueryPathBase<SearchRequestParameters, T>, ISearchRequest
187193
where T : class
188194
{
195+
public SearchRequest() {}
196+
197+
public SearchRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
198+
199+
public SearchRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
200+
189201
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<SearchRequestParameters> pathInfo)
190202
{
191203
SearchPathInfo.Update(settings,pathInfo, this);

Diff for: src/Nest/DSL/SearchShardsDescriptor.cs

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public static void Update(IConnectionSettingsValues settings, ElasticsearchPathI
2727

2828
public partial class SearchShardsRequest : QueryPathBase<SearchShardsRequestParameters>, ISearchShardsRequest
2929
{
30+
public SearchShardsRequest() {}
31+
32+
public SearchShardsRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
33+
34+
public SearchShardsRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
35+
3036
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<SearchShardsRequestParameters> pathInfo)
3137
{
3238
SearchShardsPathInfo.Update(settings, pathInfo, this);
@@ -36,6 +42,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
3642
public partial class SearchShardsRequest<T> : QueryPathBase<SearchShardsRequestParameters, T>, ISearchShardsRequest
3743
where T : class
3844
{
45+
public SearchShardsRequest() {}
46+
47+
public SearchShardsRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
48+
49+
public SearchShardsRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
50+
3951
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<SearchShardsRequestParameters> pathInfo)
4052
{
4153
SearchShardsPathInfo.Update(settings,pathInfo, this);

Diff for: src/Nest/DSL/ValidateQueryDescriptor.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Elasticsearch.Net;
34
using Newtonsoft.Json;
45

@@ -29,7 +30,13 @@ public static void Update(ElasticsearchPathInfo<ValidateQueryRequestParameters>
2930

3031
public partial class ValidateQueryRequest : QueryPathBase<ValidateQueryRequestParameters>, IValidateQueryRequest
3132
{
32-
public IQueryContainer Query { get; set; }
33+
public ValidateQueryRequest() {}
34+
35+
public ValidateQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
36+
37+
public ValidateQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
38+
39+
public IQueryContainer Query { get; set; }
3340

3441
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<ValidateQueryRequestParameters> pathInfo)
3542
{
@@ -40,7 +47,14 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
4047
public partial class ValidateQueryRequest<T> : QueryPathBase<ValidateQueryRequestParameters, T>, IValidateQueryRequest<T>
4148
where T : class
4249
{
43-
public IQueryContainer Query { get; set; }
50+
51+
public ValidateQueryRequest() {}
52+
53+
public ValidateQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
54+
55+
public ValidateQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
56+
57+
public IQueryContainer Query { get; set; }
4458

4559
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<ValidateQueryRequestParameters> pathInfo)
4660
{

Diff for: src/Nest/ExposedInternals/ElasticInferrer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public string DefaultIndex
3939
{
4040
get
4141
{
42-
return (this._connectionSettings == null) ? string.Empty : this._connectionSettings.DefaultIndex;
42+
var index = (this._connectionSettings == null) ? string.Empty : this._connectionSettings.DefaultIndex;
43+
return index.IsNullOrEmpty() ? "_all" : index;
4344
}
4445
}
4546

Diff for: src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<Compile Include="..\..\Elasticsearch.Net\Extensions\TypeExtensions.cs">
9090
<Link>LinkedExtensions\TypeExtensions.cs</Link>
9191
</Compile>
92+
<Compile Include="Aggregations\CombinationTests.cs" />
9293
<Compile Include="Aggregations\NestedBucketAggregationTests.cs" />
9394
<Compile Include="Aggregations\BucketAggregationTests.cs" />
9495
<Compile Include="Aggregations\SingleBucketAggregationTests.cs" />

Diff for: src/Tests/Nest.Tests.Unit/ObjectInitializer/DeleteByQuery/DeleteByQueryRequestTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public DeleteByQueryRequestTests()
3030

3131
var request = new DeleteByQueryRequest()
3232
{
33+
AllIndices = true,
3334
AllowNoIndices = true,
3435
ExpandWildcards = ExpandWildcards.Closed,
3536
Query = query,

Diff for: src/Tests/Nest.Tests.Unit/ObjectInitializer/DeleteByQuery/DeleteByQueryRequestUrlTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Untyped_Defaults()
1717
var status = this._client.DeleteByQuery(new DeleteByQueryRequest())
1818
.ConnectionStatus;
1919

20-
status.RequestUrl.Should().EndWith("/_all/_query");
20+
status.RequestUrl.Should().EndWith("/nest_test_data/_query");
2121
status.RequestMethod.Should().Be("DELETE");
2222
}
2323

0 commit comments

Comments
 (0)