Skip to content

Commit d25143b

Browse files
committed
laid the ground work for all the cat endpoints starting with cat_aliases
1 parent 13ce126 commit d25143b

File tree

14 files changed

+648
-148
lines changed

14 files changed

+648
-148
lines changed

src/CodeGeneration/CodeGeneration.LowLevelClient/Views/ElasticsearchClient.Generated.cshtml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,15 @@ namespace Elasticsearch.Net
8585
else {
8686
@if (url.StartsWith("_cat"))
8787
{
88-
<text>requestParams.RequestConfiguration.ContentType = "text/plain";</text>
88+
<text>if (string.IsNullOrWhiteSpace(requestParams.RequestConfiguration.ContentType)) {
89+
requestParams.RequestConfiguration.ContentType = "text/plain";
90+
}</text>
8991
}
9092
@if (method.Allow404)
9193
{
92-
<text>requestParams.RequestConfiguration.AllowedStatusCodes = new [] { 404 };</text>
94+
<text> if (requestParams.RequestConfiguration.AllowedStatusCodes == null) {
95+
requestParams.RequestConfiguration.AllowedStatusCodes = new [] { 404 };
96+
}</text>
9397
}
9498
}
9599
</text>

src/Elasticsearch.Net/ElasticsearchClient.Generated.cs

Lines changed: 336 additions & 112 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Elasticsearch.Net;
2+
using Newtonsoft.Json;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace Nest
9+
{
10+
internal static class CatRequestPathInfo
11+
{
12+
public static void Update(IElasticsearchPathInfo pathInfo)
13+
{
14+
pathInfo.HttpMethod = PathInfoHttpMethod.GET;
15+
}
16+
}
17+
18+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
19+
public interface ICatAliasesRequest : IRequest<CatAliasesRequestParameters>
20+
{
21+
}
22+
23+
public partial class CatAliasesRequest : BasePathRequest<CatAliasesRequestParameters>, ICatAliasesRequest
24+
{
25+
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<CatAliasesRequestParameters> pathInfo)
26+
{
27+
CatRequestPathInfo.Update(pathInfo);
28+
}
29+
}
30+
31+
public partial class CatAliasesDescriptor : BasePathDescriptor<CatAliasesDescriptor, CatAliasesRequestParameters>, ICatAliasesRequest
32+
{
33+
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<CatAliasesRequestParameters> pathInfo)
34+
{
35+
CatRequestPathInfo.Update(pathInfo);
36+
}
37+
}
38+
}

src/Nest/DSL/Common/BaseRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public abstract class BaseRequest<TParameters> : IRequest<TParameters>
1111
protected IRequest<TParameters> Request { get { return this; } }
1212

1313
[JsonIgnore]
14-
IRequestConfiguration IRequest<TParameters>.RequestConfiguration
14+
IRequestConfiguration IRequest.RequestConfiguration
1515
{
1616
get { return _requestConfiguration; }
1717
set { _requestConfiguration = value; }

src/Nest/DSL/Common/IRequest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ namespace Nest
77
/// <summary>
88
/// </summary>
99
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
10-
public interface IRequest {}
10+
public interface IRequest
11+
{
12+
IRequestConfiguration RequestConfiguration { get; set; }
13+
}
1114
public interface IRequest<TParameters> : IPathInfo<TParameters>, IRequest
1215
where TParameters : IRequestParameters, new()
1316
{
@@ -17,9 +20,5 @@ public interface IRequest<TParameters> : IPathInfo<TParameters>, IRequest
1720
/// </summary>
1821
TParameters RequestParameters { get; set; }
1922

20-
/// <summary>
21-
///
22-
/// </summary>
23-
IRequestConfiguration RequestConfiguration { get; set; }
2423
}
2524
}

src/Nest/DSL/_Descriptors.generated.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public BulkDescriptor TypeQueryString(string type)
9797
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/cat-aliases.html
9898
///</pre>
9999
///</summary>
100-
public partial class CatAliasesDescriptor : BaseRequest<CatAliasesRequestParameters>
100+
public partial class CatAliasesDescriptor
101101
{
102102

103103

@@ -141,12 +141,6 @@ public CatAliasesDescriptor V(bool v = true)
141141
return this;
142142
}
143143

144-
145-
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<CatAliasesRequestParameters> pathInfo)
146-
{
147-
throw new NotImplementedException();
148-
}
149-
150144

151145
}
152146

src/Nest/DSL/_Requests.generated.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public string TypeQueryString
9393
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/cat-aliases.html
9494
///</pre>
9595
///</summary>
96-
public partial class CatAliasesRequest : BasePathRequest<CatAliasesRequestParameters>
96+
public partial class CatAliasesRequest
9797
{
9898

9999
///<summary>Return local information, do not retrieve the state from master node (default: false)</summary>
@@ -135,12 +135,6 @@ public bool V
135135
set { this.Request.RequestParameters.AddQueryString("v", value); }
136136
}
137137

138-
139-
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<CatAliasesRequestParameters> pathInfo)
140-
{
141-
throw new NotImplementedException();
142-
}
143-
144138
}
145139

146140

src/Nest/Domain/Paths/ElasticSearchPathInfo.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Nest
66
{
7-
public class ElasticsearchPathInfo<TParameters>
7+
public class ElasticsearchPathInfo<TParameters> : IElasticsearchPathInfo
88
where TParameters : IRequestParameters, new()
99
{
1010
public PathInfoHttpMethod HttpMethod { get; set; }
@@ -36,4 +36,23 @@ public ElasticsearchPathInfo<TParameters> DeserializationState(Func<IElasticsear
3636
return this;
3737
}
3838
}
39+
40+
public interface IElasticsearchPathInfo
41+
{
42+
PathInfoHttpMethod HttpMethod { get; set; }
43+
string Index { get; set; }
44+
string Type { get; set; }
45+
string Id { get; set; }
46+
string Name { get; set; }
47+
string Field { get; set; }
48+
string ScrollId { get; set; }
49+
string NodeId { get; set; }
50+
string Fields { get; set; }
51+
string SearchGroups { get; set; }
52+
string IndexingTypes { get; set; }
53+
string Repository { get; set; }
54+
string Snapshot { get; set; }
55+
string Metric { get; set; }
56+
string IndexMetric { get; set; }
57+
}
3958
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Elasticsearch.Net;
2+
using Newtonsoft.Json;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace Nest
9+
{
10+
public interface ICatResponse<TCatRectord> : IResponse
11+
where TCatRectord : ICatRecord
12+
{
13+
IEnumerable<TCatRectord> Records { get; }
14+
}
15+
16+
[JsonObject]
17+
public class CatResponse<TCatRecord> : BaseResponse, ICatResponse<TCatRecord>
18+
where TCatRecord : ICatRecord
19+
{
20+
public IEnumerable<TCatRecord> Records { get; internal set; }
21+
22+
public CatResponse(IElasticsearchResponse response)
23+
{
24+
this.IsValid = response.Success && response.HttpStatusCode == 200;
25+
}
26+
}
27+
28+
public interface ICatRecord {}
29+
30+
[JsonObject]
31+
public class CatAliasesRecord : ICatRecord
32+
{
33+
[JsonProperty("alias")]
34+
public string Alias { get; set; }
35+
36+
[JsonProperty("index")]
37+
public string Index { get; set; }
38+
39+
[JsonProperty("filter")]
40+
public string Filter { get; set; }
41+
42+
[JsonProperty("indexRouting")]
43+
public string IndexRouting { get; set; }
44+
45+
[JsonProperty("searchRouting")]
46+
public string SearchRouting { get; set; }
47+
48+
}
49+
}

src/Nest/ElasticClient-Cat.cs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
using Elasticsearch.Net;
6+
7+
namespace Nest
8+
{
9+
public partial class ElasticClient
10+
{
11+
12+
/// <inheritdoc />
13+
public ICatResponse<CatAliasesRecord> CatAliases(Func<CatAliasesDescriptor, CatAliasesDescriptor> selector = null)
14+
{
15+
return this.DoCat<CatAliasesDescriptor, CatAliasesRequestParameters, CatAliasesRecord>(selector, this.RawDispatch.CatAliasesDispatch<CatResponse<CatAliasesRecord>>);
16+
}
17+
18+
public ICatResponse<CatAliasesRecord> CatAliases(ICatAliasesRequest request)
19+
{
20+
return this.DoCat<ICatAliasesRequest, CatAliasesRequestParameters, CatAliasesRecord>(request, this.RawDispatch.CatAliasesDispatch<CatResponse<CatAliasesRecord>>);
21+
}
22+
23+
public Task<ICatResponse<CatAliasesRecord>> CatAliasesAsync(Func<CatAliasesDescriptor, CatAliasesDescriptor> selector = null)
24+
{
25+
return this.DoCatAsync<CatAliasesDescriptor, CatAliasesRequestParameters, CatAliasesRecord>(selector, this.RawDispatch.CatAliasesDispatchAsync<CatResponse<CatAliasesRecord>>);
26+
}
27+
28+
public Task<ICatResponse<CatAliasesRecord>> CatAliasesAsync(ICatAliasesRequest request)
29+
{
30+
return this.DoCatAsync<ICatAliasesRequest, CatAliasesRequestParameters, CatAliasesRecord>(request, this.RawDispatch.CatAliasesDispatchAsync<CatResponse<CatAliasesRecord>>);
31+
}
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
private CatResponse<TCatRecord> DeserializeCatResponse<TCatRecord>(IElasticsearchResponse response, Stream stream)
42+
where TCatRecord : ICatRecord
43+
{
44+
var records = this.Serializer.Deserialize<IEnumerable<TCatRecord>>(stream);
45+
return new CatResponse<TCatRecord>(response) { Records = records };
46+
}
47+
48+
49+
private Task<ICatResponse<TCatRecord>> DoCatAsync<TRequest, TParams, TCatRecord>(
50+
Func<TRequest, TRequest> selector,
51+
Func<ElasticsearchPathInfo<TParams>, Task<ElasticsearchResponse<CatResponse<TCatRecord>>>> dispatch
52+
)
53+
where TCatRecord : ICatRecord
54+
where TParams : FluentRequestParameters<TParams>, new()
55+
where TRequest : class, IRequest<TParams>, new()
56+
{
57+
return this.DispatchAsync<TRequest, TParams, CatResponse<TCatRecord>, ICatResponse<TCatRecord>>(
58+
this.ForceConfiguration(selector, c => c.ContentType = "application/json"),
59+
(p, d) => dispatch(p.DeserializationState(
60+
new Func<IElasticsearchResponse, Stream, CatResponse<TCatRecord>>(this.DeserializeCatResponse<TCatRecord>))
61+
)
62+
);
63+
}
64+
65+
private Task<ICatResponse<TCatRecord>> DoCatAsync<TRequest, TParams, TCatRecord>(
66+
TRequest request,
67+
Func<ElasticsearchPathInfo<TParams>, Task<ElasticsearchResponse<CatResponse<TCatRecord>>>> dispatch
68+
)
69+
where TCatRecord : ICatRecord
70+
where TParams : FluentRequestParameters<TParams>, new()
71+
where TRequest : IRequest<TParams>
72+
{
73+
return this.DispatchAsync<TRequest, TParams, CatResponse<TCatRecord>, ICatResponse<TCatRecord>>(
74+
this.ForceConfiguration(request, c => c.ContentType = "application/json"),
75+
(p, d) => dispatch(p.DeserializationState(
76+
new Func<IElasticsearchResponse, Stream, CatResponse<TCatRecord>>(this.DeserializeCatResponse<TCatRecord>))
77+
)
78+
);
79+
}
80+
81+
private ICatResponse<TCatRecord> DoCat<TRequest, TParams, TCatRecord>(
82+
Func<TRequest, TRequest> selector,
83+
Func<ElasticsearchPathInfo<TParams>, ElasticsearchResponse<CatResponse<TCatRecord>>> dispatch
84+
)
85+
where TCatRecord : ICatRecord
86+
where TParams : FluentRequestParameters<TParams>, new()
87+
where TRequest : class, IRequest<TParams>, new()
88+
{
89+
return this.Dispatch<TRequest, TParams, CatResponse<TCatRecord>>(
90+
this.ForceConfiguration(selector, c => c.ContentType = "application/json"),
91+
(p, d) => dispatch(p.DeserializationState(
92+
new Func<IElasticsearchResponse, Stream, CatResponse<TCatRecord>>(this.DeserializeCatResponse<TCatRecord>))
93+
)
94+
);
95+
}
96+
97+
private ICatResponse<TCatRecord> DoCat<TRequest, TParams, TCatRecord>(
98+
TRequest request,
99+
Func<ElasticsearchPathInfo<TParams>, ElasticsearchResponse<CatResponse<TCatRecord>>> dispatch
100+
)
101+
where TCatRecord : ICatRecord
102+
where TParams : FluentRequestParameters<TParams>, new()
103+
where TRequest : IRequest<TParams>
104+
{
105+
return this.Dispatch<TRequest, TParams, CatResponse<TCatRecord>>(
106+
this.ForceConfiguration(request, c => c.ContentType = "application/json"),
107+
(p, d) => dispatch(p.DeserializationState(
108+
new Func<IElasticsearchResponse, Stream, CatResponse<TCatRecord>>(this.DeserializeCatResponse<TCatRecord>))
109+
)
110+
);
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)