Skip to content

Commit a73b2ff

Browse files
committed
Merge pull request #903 from elasticsearch/feature/template-exists
fix #503 add support for template exists requests
2 parents 62a0309 + 710f604 commit a73b2ff

File tree

15 files changed

+234
-39
lines changed

15 files changed

+234
-39
lines changed

src/CodeGeneration/CodeGeneration.LowLevelClient/Overrides/Allow404/ApiEndpointsThatAllow404.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static class ApiEndpointsThatAllow404
1515
"Delete",
1616
"IndexExists",
1717
"AliasExists",
18+
"TemplateExists",
1819
"TypeExists",
1920
"Exists"
2021
};

src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,12 +2838,12 @@ public AliasExistsRequestParameters Local(bool local)
28382838
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-templates.html
28392839
///</pre>
28402840
///</summary>
2841-
public class IndicesExistsTemplateRequestParameters : FluentRequestParameters<IndicesExistsTemplateRequestParameters>
2841+
public class TemplateExistsRequestParameters : FluentRequestParameters<TemplateExistsRequestParameters>
28422842
{
28432843

28442844
internal bool _local { get; set; }
28452845
///<summary>Return local information, do not retrieve the state from master node (default: false)</summary>
2846-
public IndicesExistsTemplateRequestParameters Local(bool local)
2846+
public TemplateExistsRequestParameters Local(bool local)
28472847
{
28482848
this._local = local;
28492849
this.AddQueryString("local", this._local);

src/Elasticsearch.Net/Elasticsearch.Net.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<Compile Include="Domain\Response\VoidResponse.cs" />
6868
<Compile Include="Domain\Response\ElasticsearchServerError.cs" />
6969
<Compile Include="Exceptions\OneToOneServerException.cs" />
70+
<Compile Include="Obsolete\IndicesTemplateExists.cs" />
7071
<Compile Include="Obsolete\IndicesGetFieldMapping.cs" />
7172
<Compile Include="Obsolete\Mpercolate.cs" />
7273
<Compile Include="Obsolete\IndicesExistsType.cs" />

src/Elasticsearch.Net/ElasticsearchClient.Generated.cs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12064,15 +12064,19 @@ public Task<ElasticsearchResponse<DynamicDictionary>> IndicesExistsAliasAsync(st
1206412064
///<para> - If T is of type byte[] deserialization will be shortcircuited</para>
1206512065
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
1206612066
///</returns>
12067-
public ElasticsearchResponse<T> IndicesExistsTemplateForAll<T>(string name, Func<IndicesExistsTemplateRequestParameters, IndicesExistsTemplateRequestParameters> requestParameters = null)
12067+
public ElasticsearchResponse<T> IndicesExistsTemplateForAll<T>(string name, Func<TemplateExistsRequestParameters, TemplateExistsRequestParameters> requestParameters = null)
1206812068
{
1206912069
name.ThrowIfNullOrEmpty("name");
1207012070
var url = "_template/{0}".F(Encoded(name));
1207112071
IRequestParameters requestParams = null;
1207212072

12073-
if (requestParameters != null)
12074-
{
12075-
requestParams = requestParameters(new IndicesExistsTemplateRequestParameters());
12073+
requestParameters = requestParameters ?? (s => s);
12074+
var passIn = new TemplateExistsRequestParameters();
12075+
requestParams = requestParameters(passIn);
12076+
if (requestParams.RequestConfiguration == null)
12077+
requestParams.RequestConfiguration = new RequestConfiguration { AllowedStatusCodes = new [] { 404 } };
12078+
else {
12079+
requestParams.RequestConfiguration.AllowedStatusCodes = new [] { 404 };
1207612080
}
1207712081

1207812082

@@ -12098,15 +12102,19 @@ public ElasticsearchResponse<T> IndicesExistsTemplateForAll<T>(string name, Func
1209812102
///<para> - If T is of type byte[] deserialization will be shortcircuited</para>
1209912103
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
1210012104
///</returns>
12101-
public Task<ElasticsearchResponse<T>> IndicesExistsTemplateForAllAsync<T>(string name, Func<IndicesExistsTemplateRequestParameters, IndicesExistsTemplateRequestParameters> requestParameters = null)
12105+
public Task<ElasticsearchResponse<T>> IndicesExistsTemplateForAllAsync<T>(string name, Func<TemplateExistsRequestParameters, TemplateExistsRequestParameters> requestParameters = null)
1210212106
{
1210312107
name.ThrowIfNullOrEmpty("name");
1210412108
var url = "_template/{0}".F(Encoded(name));
1210512109
IRequestParameters requestParams = null;
1210612110

12107-
if (requestParameters != null)
12108-
{
12109-
requestParams = requestParameters(new IndicesExistsTemplateRequestParameters());
12111+
requestParameters = requestParameters ?? (s => s);
12112+
var passIn = new TemplateExistsRequestParameters();
12113+
requestParams = requestParameters(passIn);
12114+
if (requestParams.RequestConfiguration == null)
12115+
requestParams.RequestConfiguration = new RequestConfiguration { AllowedStatusCodes = new [] { 404 } };
12116+
else {
12117+
requestParams.RequestConfiguration.AllowedStatusCodes = new [] { 404 };
1211012118
}
1211112119

1211212120

@@ -12134,15 +12142,19 @@ public Task<ElasticsearchResponse<T>> IndicesExistsTemplateForAllAsync<T>(string
1213412142
///<para> - i.e result.Response.hits.hits[0].property.nested["nested_deeper"]</para>
1213512143
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
1213612144
///</returns>
12137-
public ElasticsearchResponse<DynamicDictionary> IndicesExistsTemplateForAll(string name, Func<IndicesExistsTemplateRequestParameters, IndicesExistsTemplateRequestParameters> requestParameters = null)
12145+
public ElasticsearchResponse<DynamicDictionary> IndicesExistsTemplateForAll(string name, Func<TemplateExistsRequestParameters, TemplateExistsRequestParameters> requestParameters = null)
1213812146
{
1213912147
name.ThrowIfNullOrEmpty("name");
1214012148
var url = "_template/{0}".F(Encoded(name));
1214112149
IRequestParameters requestParams = null;
1214212150

12143-
if (requestParameters != null)
12144-
{
12145-
requestParams = requestParameters(new IndicesExistsTemplateRequestParameters());
12151+
requestParameters = requestParameters ?? (s => s);
12152+
var passIn = new TemplateExistsRequestParameters();
12153+
requestParams = requestParameters(passIn);
12154+
if (requestParams.RequestConfiguration == null)
12155+
requestParams.RequestConfiguration = new RequestConfiguration { AllowedStatusCodes = new [] { 404 } };
12156+
else {
12157+
requestParams.RequestConfiguration.AllowedStatusCodes = new [] { 404 };
1214612158
}
1214712159

1214812160

@@ -12170,15 +12182,19 @@ public ElasticsearchResponse<DynamicDictionary> IndicesExistsTemplateForAll(stri
1217012182
///<para> - i.e result.Response.hits.hits[0].property.nested["nested_deeper"]</para>
1217112183
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
1217212184
///</returns>
12173-
public Task<ElasticsearchResponse<DynamicDictionary>> IndicesExistsTemplateForAllAsync(string name, Func<IndicesExistsTemplateRequestParameters, IndicesExistsTemplateRequestParameters> requestParameters = null)
12185+
public Task<ElasticsearchResponse<DynamicDictionary>> IndicesExistsTemplateForAllAsync(string name, Func<TemplateExistsRequestParameters, TemplateExistsRequestParameters> requestParameters = null)
1217412186
{
1217512187
name.ThrowIfNullOrEmpty("name");
1217612188
var url = "_template/{0}".F(Encoded(name));
1217712189
IRequestParameters requestParams = null;
1217812190

12179-
if (requestParameters != null)
12180-
{
12181-
requestParams = requestParameters(new IndicesExistsTemplateRequestParameters());
12191+
requestParameters = requestParameters ?? (s => s);
12192+
var passIn = new TemplateExistsRequestParameters();
12193+
requestParams = requestParameters(passIn);
12194+
if (requestParams.RequestConfiguration == null)
12195+
requestParams.RequestConfiguration = new RequestConfiguration { AllowedStatusCodes = new [] { 404 } };
12196+
else {
12197+
requestParams.RequestConfiguration.AllowedStatusCodes = new [] { 404 };
1218212198
}
1218312199

1218412200

src/Elasticsearch.Net/IElasticsearchClient.Generated.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6392,7 +6392,7 @@ public interface IElasticsearchClient
63926392
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
63936393
///</returns>
63946394

6395-
ElasticsearchResponse<T> IndicesExistsTemplateForAll<T>(string name, Func<IndicesExistsTemplateRequestParameters, IndicesExistsTemplateRequestParameters> requestParameters = null);
6395+
ElasticsearchResponse<T> IndicesExistsTemplateForAll<T>(string name, Func<TemplateExistsRequestParameters, TemplateExistsRequestParameters> requestParameters = null);
63966396

63976397
///<summary>Represents a HEAD on /_template/{name}
63986398
///<para></para>Returns: A task that'll return an ElasticsearchResponse&lt;T&gt; holding the reponse body deserialized as T.
@@ -6410,7 +6410,7 @@ public interface IElasticsearchClient
64106410
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
64116411
///</returns>
64126412

6413-
Task<ElasticsearchResponse<T>> IndicesExistsTemplateForAllAsync<T>(string name, Func<IndicesExistsTemplateRequestParameters, IndicesExistsTemplateRequestParameters> requestParameters = null);
6413+
Task<ElasticsearchResponse<T>> IndicesExistsTemplateForAllAsync<T>(string name, Func<TemplateExistsRequestParameters, TemplateExistsRequestParameters> requestParameters = null);
64146414

64156415
///<summary>Represents a HEAD on /_template/{name}
64166416
///<para></para>Returns: ElasticsearchResponse&lt;T&gt; holding the response body deserialized as DynamicDictionary
@@ -6430,7 +6430,7 @@ public interface IElasticsearchClient
64306430
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
64316431
///</returns>
64326432

6433-
ElasticsearchResponse<DynamicDictionary> IndicesExistsTemplateForAll(string name, Func<IndicesExistsTemplateRequestParameters, IndicesExistsTemplateRequestParameters> requestParameters = null);
6433+
ElasticsearchResponse<DynamicDictionary> IndicesExistsTemplateForAll(string name, Func<TemplateExistsRequestParameters, TemplateExistsRequestParameters> requestParameters = null);
64346434

64356435
///<summary>Represents a HEAD on /_template/{name}
64366436
///<para></para>Returns: Task that'll return an ElasticsearchResponse&lt;T$gt; holding the response body deserialized as DynamicDictionary
@@ -6450,7 +6450,7 @@ public interface IElasticsearchClient
64506450
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
64516451
///</returns>
64526452

6453-
Task<ElasticsearchResponse<DynamicDictionary>> IndicesExistsTemplateForAllAsync(string name, Func<IndicesExistsTemplateRequestParameters, IndicesExistsTemplateRequestParameters> requestParameters = null);
6453+
Task<ElasticsearchResponse<DynamicDictionary>> IndicesExistsTemplateForAllAsync(string name, Func<TemplateExistsRequestParameters, TemplateExistsRequestParameters> requestParameters = null);
64546454

64556455
///<summary>Represents a HEAD on /{index}/{type}
64566456
///<para></para>Returns: ElasticsearchResponse&lt;T&gt; holding the reponse body deserialized as T.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace Elasticsearch.Net
8+
{
9+
#pragma warning disable 0618
10+
using IndicesExistsTemplateSelector = Func<IndicesExistsTemplateRequestParameters , IndicesExistsTemplateRequestParameters >;
11+
#pragma warning restore 0618
12+
13+
[Obsolete("Scheduled to be removed in 2.0, renamed to AliasExistsRequestParameters")]
14+
public class IndicesExistsTemplateRequestParameters : TemplateExistsRequestParameters { }
15+
16+
public static class IndicesExistsTemplateClientExtensions
17+
{
18+
[Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of IndicesExistsRequestParameters")]
19+
public static ElasticsearchResponse<T> IndicesExistsTemplateForAll<T>(this IElasticsearchClient client, string name, IndicesExistsTemplateSelector requestParameters = null)
20+
{
21+
var selector = Obsolete.UpCastSelector<IndicesExistsTemplateRequestParameters, TemplateExistsRequestParameters>(requestParameters);
22+
return client.IndicesExistsTemplateForAll<T>(name, requestParameters);
23+
}
24+
25+
[Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of IndicesExistsRequestParameters")]
26+
public static Task<ElasticsearchResponse<T>> IndicesExistsTemplateForAllAsync<T>(this IElasticsearchClient client, string name, IndicesExistsTemplateSelector requestParameters = null)
27+
{
28+
var selector = Obsolete.UpCastSelector<IndicesExistsTemplateRequestParameters, TemplateExistsRequestParameters>(requestParameters);
29+
return client.IndicesExistsTemplateForAllAsync<T>(name, requestParameters);
30+
}
31+
32+
[Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of IndicesExistsRequestParameters")]
33+
public static ElasticsearchResponse<DynamicDictionary> IndicesExistsTemplateForAll(this IElasticsearchClient client, string name, IndicesExistsTemplateSelector requestParameters = null)
34+
{
35+
var selector = Obsolete.UpCastSelector<IndicesExistsTemplateRequestParameters, TemplateExistsRequestParameters>(requestParameters);
36+
return client.IndicesExistsTemplateForAll(name, requestParameters);
37+
}
38+
39+
[Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of IndicesExistsRequestParameters")]
40+
public static Task<ElasticsearchResponse<DynamicDictionary>> IndicesExistsTemplateForAllAsync(this IElasticsearchClient client, string name, IndicesExistsTemplateSelector requestParameters = null)
41+
{
42+
var selector = Obsolete.UpCastSelector<IndicesExistsTemplateRequestParameters, TemplateExistsRequestParameters>(requestParameters);
43+
return client.IndicesExistsTemplateForAllAsync(name, requestParameters);
44+
}
45+
46+
47+
}
48+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Elasticsearch.Net;
5+
using Newtonsoft.Json;
6+
7+
namespace Nest
8+
{
9+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
10+
public interface ITemplateExistsRequest : INamePath<TemplateExistsRequestParameters> { }
11+
12+
internal static class TemplateExistsPathInfo
13+
{
14+
public static void Update(ElasticsearchPathInfo<TemplateExistsRequestParameters> pathInfo, ITemplateExistsRequest request)
15+
{
16+
pathInfo.HttpMethod = PathInfoHttpMethod.HEAD;
17+
}
18+
}
19+
20+
public partial class TemplateExistsRequest : NamePathBase<TemplateExistsRequestParameters>, ITemplateExistsRequest
21+
{
22+
public TemplateExistsRequest(string name) : base(name) { }
23+
24+
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<TemplateExistsRequestParameters> pathInfo)
25+
{
26+
TemplateExistsPathInfo.Update(pathInfo, this);
27+
}
28+
}
29+
[DescriptorFor("IndicesExistsTemplate")]
30+
public partial class TemplateExistsDescriptor : NamePathDescriptor<TemplateExistsDescriptor, TemplateExistsRequestParameters>, ITemplateExistsRequest
31+
{
32+
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<TemplateExistsRequestParameters> pathInfo)
33+
{
34+
TemplateExistsPathInfo.Update(pathInfo, this);
35+
}
36+
}
37+
}

src/Nest/DSL/_Descriptors.generated.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,24 +2729,18 @@ public AliasExistsDescriptor Local(bool local = true)
27292729
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-templates.html
27302730
///</pre>
27312731
///</summary>
2732-
public partial class IndicesExistsTemplateDescriptor : BaseRequest<IndicesExistsTemplateRequestParameters>
2732+
public partial class TemplateExistsDescriptor
27332733
{
27342734

27352735

27362736

27372737
///<summary>Return local information, do not retrieve the state from master node (default: false)</summary>
2738-
public IndicesExistsTemplateDescriptor Local(bool local = true)
2738+
public TemplateExistsDescriptor Local(bool local = true)
27392739
{
27402740
this.Request.RequestParameters.Local(local);
27412741
return this;
27422742
}
27432743

2744-
2745-
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<IndicesExistsTemplateRequestParameters> pathInfo)
2746-
{
2747-
throw new NotImplementedException();
2748-
}
2749-
27502744

27512745
}
27522746

src/Nest/DSL/_Requests.generated.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,7 @@ public bool Local
24802480
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-templates.html
24812481
///</pre>
24822482
///</summary>
2483-
public partial class IndicesExistsTemplateRequest : BasePathRequest<IndicesExistsTemplateRequestParameters>
2483+
public partial class TemplateExistsRequest
24842484
{
24852485

24862486
///<summary>Return local information, do not retrieve the state from master node (default: false)</summary>
@@ -2490,12 +2490,6 @@ public bool Local
24902490
set { this.Request.RequestParameters.AddQueryString("local", value); }
24912491
}
24922492

2493-
2494-
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<IndicesExistsTemplateRequestParameters> pathInfo)
2495-
{
2496-
throw new NotImplementedException();
2497-
}
2498-
24992493
}
25002494

25012495

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Elasticsearch.Net;
7+
8+
namespace Nest
9+
{
10+
using TemplateExistConverter = Func<IElasticsearchResponse, Stream, ExistsResponse>;
11+
12+
public partial class ElasticClient
13+
{
14+
/// <inheritdoc />
15+
public IExistsResponse TemplateExists(Func<TemplateExistsDescriptor, TemplateExistsDescriptor> selector)
16+
{
17+
return this.Dispatch<TemplateExistsDescriptor, TemplateExistsRequestParameters, ExistsResponse>(
18+
selector,
19+
(p, d) => this.RawDispatch.IndicesExistsTemplateDispatch<ExistsResponse>(
20+
p.DeserializationState(new TemplateExistConverter(DeserializeExistsResponse))
21+
)
22+
);
23+
}
24+
25+
/// <inheritdoc />
26+
public IExistsResponse TemplateExists(ITemplateExistsRequest templateRequest)
27+
{
28+
return this.Dispatch<ITemplateExistsRequest, TemplateExistsRequestParameters, ExistsResponse>(
29+
templateRequest,
30+
(p, d) => this.RawDispatch.IndicesExistsTemplateDispatch<ExistsResponse>(
31+
p.DeserializationState(new TemplateExistConverter(DeserializeExistsResponse))
32+
)
33+
);
34+
}
35+
36+
/// <inheritdoc />
37+
public Task<IExistsResponse> TemplateExistsAsync(Func<TemplateExistsDescriptor, TemplateExistsDescriptor> selector)
38+
{
39+
return this.DispatchAsync<TemplateExistsDescriptor, TemplateExistsRequestParameters, ExistsResponse, IExistsResponse>(
40+
selector,
41+
(p, d) => this.RawDispatch.IndicesExistsTemplateDispatchAsync<ExistsResponse>(
42+
p.DeserializationState(new TemplateExistConverter(DeserializeExistsResponse))
43+
)
44+
);
45+
}
46+
47+
/// <inheritdoc />
48+
public Task<IExistsResponse> TemplateExistsAsync(ITemplateExistsRequest templateRequest)
49+
{
50+
return this.DispatchAsync<ITemplateExistsRequest, TemplateExistsRequestParameters, ExistsResponse, IExistsResponse>(
51+
templateRequest,
52+
(p, d) => this.RawDispatch.IndicesExistsTemplateDispatchAsync<ExistsResponse>(
53+
p.DeserializationState(new TemplateExistConverter(DeserializeExistsResponse))
54+
)
55+
);
56+
}
57+
58+
}
59+
}

0 commit comments

Comments
 (0)