Skip to content

Commit 39c53b1

Browse files
committed
2.3 new API's feature parity
This commit adds support for the new 2.3 API's: * tasks_list * tasks_cancel * update_by_query * reindex The spec changes have also been updated in core upstream. The Reindex API is called `ReindexOnServer()` to offset it against our current `Reindex()` implementation which is still very useful. Both the reindex and update_by_query steal the status code from one of the failures and return a valid json body that we need to deserialize. To support this this AllowedStatusCodes now accepts a -1. .IsValid for these API's inspects whether any failures have been returned or not.
1 parent f0a71c4 commit 39c53b1

File tree

52 files changed

+2056
-1005
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2056
-1005
lines changed

src/CodeGeneration/CodeGeneration.LowLevelClient/ApiEndpoints/root.html

Lines changed: 132 additions & 672 deletions
Large diffs are not rendered by default.

src/CodeGeneration/CodeGeneration.LowLevelClient/ApiEndpoints/tasks.cancel.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"paths": ["/_tasks/_cancel", "/_tasks/{task_id}/_cancel"],
88
"parts": {
99
"task_id": {
10-
"type": "number",
10+
"type": "string",
1111
"description": "Cancel the task with specified id"
1212
}
1313
},
@@ -25,7 +25,7 @@
2525
"description": "Cancel tasks with specified parent node."
2626
},
2727
"parent_task": {
28-
"type" : "number",
28+
"type" : "string",
2929
"description" : "Cancel tasks with specified parent task id. Set to -1 to cancel all."
3030
}
3131
}

src/CodeGeneration/CodeGeneration.LowLevelClient/ApiEndpoints/tasks.list.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"paths": ["/_tasks", "/_tasks/{task_id}"],
88
"parts": {
99
"task_id": {
10-
"type": "number",
10+
"type": "string",
1111
"description": "Return the task with specified id"
1212
}
1313
},
@@ -29,7 +29,7 @@
2929
"description": "Return tasks with specified parent node."
3030
},
3131
"parent_task": {
32-
"type" : "number",
32+
"type" : "string",
3333
"description" : "Return tasks with specified parent task id. Set to -1 to return all."
3434
},
3535
"wait_for_completion": {

src/CodeGeneration/CodeGeneration.LowLevelClient/ApiEndpoints/update_by_query.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"comment": "most things below this are just copied from search.json",
99
"parts": {
1010
"index": {
11+
"required" : true,
1112
"type" : "list",
1213
"description" : "A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices"
1314
},

src/CodeGeneration/CodeGeneration.LowLevelClient/CodeGeneration.LowLevelClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<Compile Include="Overrides\Descriptors\PutIndexTemplateDescriptorOverrides.cs" />
6969
<Compile Include="Overrides\Descriptors\ScrollDescriptorOverrides.cs" />
7070
<Compile Include="Overrides\Descriptors\SearchDescriptorOverrides.cs" />
71+
<Compile Include="Overrides\Descriptors\ReindexOnServerDescriptorOverrides.cs" />
7172
<Compile Include="Overrides\Descriptors\UpdateDescriptorOverrides.cs" />
7273
<Compile Include="Overrides\Global\GlobalQueryParameters.cs" />
7374
<Compile Include="Program.cs" />

src/CodeGeneration/CodeGeneration.LowLevelClient/Domain/ApiQueryParameters.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public string CsharpType(string paramName)
1919
return "bool";
2020
case "list":
2121
return "params string[]";
22+
case "integer":
2223
case "number":
23-
return new [] {"boost", "percen", "score"}.Any(s=>paramName.ToLowerInvariant().Contains(s))
24-
? "double"
24+
return new [] {"boost", "percen", "score"}.Any(s=>paramName.ToLowerInvariant().Contains(s))
25+
? "double"
2526
: "long";
2627
case "duration":
2728
case "time":
@@ -36,7 +37,7 @@ public string CsharpType(string paramName)
3637
return this.Type;
3738
}
3839
}
39-
40+
4041
public string HighLevelType(string paramName)
4142
{
4243
var csharpType = this.CsharpType(paramName);
@@ -49,4 +50,4 @@ public string HighLevelType(string paramName)
4950
}
5051
}
5152
}
52-
}
53+
}

src/CodeGeneration/CodeGeneration.LowLevelClient/Domain/ApiUrlPart.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public string ClrTypeName
2121
case "id": return this.Type == "string" ? "Id" : "Ids";
2222
case "node_id": return this.Type == "string" ? "NodeId" : "NodeIds";
2323
case "scroll_id": return this.Type == "string" ? "ScrollId" : "ScrollIds";
24-
case "field":
24+
case "field":
2525
case "fields": return this.Type == "string" ? "Field" : "Fields";
2626
case "index_metric": return "IndexMetrics";
2727
case "metric": return "Metrics";
@@ -30,6 +30,7 @@ public string ClrTypeName
3030
case "snapshot":
3131
case "lang":
3232
case "name": return this.Type == "string" ? "Name" : "Names";
33+
case "task_id": return "TaskId";
3334
default: return this.Type + "_";
3435
}
3536
}
@@ -47,4 +48,4 @@ public string InterfaceName
4748
}
4849
}
4950
}
50-
}
51+
}

src/CodeGeneration/CodeGeneration.LowLevelClient/Domain/CsharpMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public IEnumerable<Constructor> RequestConstructors()
120120
{
121121
var generic = this.RequestTypeGeneric.Replace("<", "").Replace(">", "");
122122
generated = $"public {m}({par}) : this({cp.First().Key}, typeof({generic})){{}}";
123-
}
123+
}
124124

125125
var c = new Constructor { Generated = generated, Description = doc };
126126
ctors.Add(c);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
3+
namespace CodeGeneration.LowLevelClient.Overrides.Descriptors
4+
{
5+
// ReSharper disable once UnusedMember.Global
6+
public class ReindexOnServerDescriptorOverrides : IDescriptorOverrides
7+
{
8+
public IEnumerable<string> SkipQueryStringParams => new []
9+
{
10+
"source"
11+
};
12+
13+
public IDictionary<string, string> RenameQueryStringParams => null;
14+
}
15+
16+
}

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,32 +3545,28 @@ public class PutSearchTemplateRequestParameters : FluentRequestParameters<PutSea
35453545
///https://www.elastic.co/guide/en/elasticsearch/plugins/master/plugins-reindex.html
35463546
///</pre>
35473547
///</summary>
3548-
public class ReindexRequestParameters : FluentRequestParameters<ReindexRequestParameters>
3548+
public class ReindexOnServerRequestParameters : FluentRequestParameters<ReindexOnServerRequestParameters>
35493549
{
35503550
public override HttpMethod DefaultHttpMethod => HttpMethod.POST;
35513551

35523552
///<summary>Should the effected indexes be refreshed?</summary>
3553-
public ReindexRequestParameters Refresh(bool refresh) => this.AddQueryString("refresh", refresh);
3553+
public ReindexOnServerRequestParameters Refresh(bool refresh) => this.AddQueryString("refresh", refresh);
35543554

35553555

35563556
///<summary>Time each individual bulk request should wait for shards that are unavailable.</summary>
3557-
public ReindexRequestParameters Timeout(TimeSpan timeout) => this.AddQueryString("timeout", timeout.ToTimeUnit());
3557+
public ReindexOnServerRequestParameters Timeout(TimeSpan timeout) => this.AddQueryString("timeout", timeout.ToTimeUnit());
35583558

35593559

35603560
///<summary>Explicit write consistency setting for the operation</summary>
3561-
public ReindexRequestParameters Consistency(Consistency consistency) => this.AddQueryString("consistency", consistency);
3561+
public ReindexOnServerRequestParameters Consistency(Consistency consistency) => this.AddQueryString("consistency", consistency);
35623562

35633563

35643564
///<summary>Should the request should block until the reindex is complete.</summary>
3565-
public ReindexRequestParameters WaitForCompletion(bool wait_for_completion) => this.AddQueryString("wait_for_completion", wait_for_completion);
3566-
3567-
3568-
///<summary>The URL-encoded request definition</summary>
3569-
public ReindexRequestParameters Source(string source) => this.AddQueryString("source", source);
3565+
public ReindexOnServerRequestParameters WaitForCompletion(bool wait_for_completion) => this.AddQueryString("wait_for_completion", wait_for_completion);
35703566

35713567

35723568
///<summary>Comma separated list of filters used to reduce the response returned by Elasticsearch</summary>
3573-
public ReindexRequestParameters FilterPath(string filter_path) => this.AddQueryString("filter_path", filter_path);
3569+
public ReindexOnServerRequestParameters FilterPath(string filter_path) => this.AddQueryString("filter_path", filter_path);
35743570

35753571
}
35763572

@@ -4144,7 +4140,7 @@ public class TasksCancelRequestParameters : FluentRequestParameters<TasksCancelR
41444140

41454141

41464142
///<summary>Cancel tasks with specified parent task id. Set to -1 to cancel all.</summary>
4147-
public TasksCancelRequestParameters ParentTask(long parent_task) => this.AddQueryString("parent_task", parent_task);
4143+
public TasksCancelRequestParameters ParentTask(string parent_task) => this.AddQueryString("parent_task", parent_task);
41484144

41494145

41504146
///<summary>The URL-encoded request definition</summary>
@@ -4182,7 +4178,7 @@ public class TasksListRequestParameters : FluentRequestParameters<TasksListReque
41824178

41834179

41844180
///<summary>Return tasks with specified parent task id. Set to -1 to return all.</summary>
4185-
public TasksListRequestParameters ParentTask(long parent_task) => this.AddQueryString("parent_task", parent_task);
4181+
public TasksListRequestParameters ParentTask(string parent_task) => this.AddQueryString("parent_task", parent_task);
41864182

41874183

41884184
///<summary>Wait for the matching tasks to complete (default: false)</summary>
@@ -4504,7 +4500,7 @@ public class UpdateByQueryRequestParameters : FluentRequestParameters<UpdateByQu
45044500

45054501

45064502
///<summary>Size on the scroll request powering the update_by_query</summary>
4507-
public UpdateByQueryRequestParameters ScrollSize(integer scroll_size) => this.AddQueryString("scroll_size", scroll_size);
4503+
public UpdateByQueryRequestParameters ScrollSize(long scroll_size) => this.AddQueryString("scroll_size", scroll_size);
45084504

45094505

45104506
///<summary>Should the request should block until the reindex is complete.</summary>

src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6558,7 +6558,7 @@ public Task<ElasticsearchResponse<T>> PutTemplatePostAsync<T>(string id, PostDat
65586558
///</summary>
65596559
///<param name="body">The search definition using the Query DSL and the prototype for the index request.</param>
65606560
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
6561-
public ElasticsearchResponse<T> Reindex<T>(PostData<object> body, Func<ReindexRequestParameters, ReindexRequestParameters> requestParameters = null)
6561+
public ElasticsearchResponse<T> Reindex<T>(PostData<object> body, Func<ReindexOnServerRequestParameters, ReindexOnServerRequestParameters> requestParameters = null)
65626562
where T : class => this.DoRequest<T>(POST, Url($"_reindex"), body, _params(requestParameters));
65636563

65646564
///<summary>Represents a POST on /_reindex
@@ -6572,7 +6572,7 @@ public ElasticsearchResponse<T> Reindex<T>(PostData<object> body, Func<ReindexRe
65726572
///</summary>
65736573
///<param name="body">The search definition using the Query DSL and the prototype for the index request.</param>
65746574
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
6575-
public Task<ElasticsearchResponse<T>> ReindexAsync<T>(PostData<object> body, Func<ReindexRequestParameters, ReindexRequestParameters> requestParameters = null)
6575+
public Task<ElasticsearchResponse<T>> ReindexAsync<T>(PostData<object> body, Func<ReindexOnServerRequestParameters, ReindexOnServerRequestParameters> requestParameters = null)
65766576
where T : class => this.DoRequestAsync<T>(POST, Url($"_reindex"), body, _params(requestParameters));
65776577

65786578
///<summary>Represents a GET on /_render/template
@@ -7990,7 +7990,7 @@ public Task<ElasticsearchResponse<T>> TasksCancelAsync<T>(Func<TasksCancelReques
79907990
///</summary>
79917991
///<param name="task_id">Cancel the task with specified id</param>
79927992
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
7993-
public ElasticsearchResponse<T> TasksCancel<T>(number task_id, Func<TasksCancelRequestParameters, TasksCancelRequestParameters> requestParameters = null)
7993+
public ElasticsearchResponse<T> TasksCancel<T>(string task_id, Func<TasksCancelRequestParameters, TasksCancelRequestParameters> requestParameters = null)
79947994
where T : class => this.DoRequest<T>(POST, Url($"_tasks/{task_id.NotNull("task_id")}/_cancel"), null, _params(requestParameters));
79957995

79967996
///<summary>Represents a POST on /_tasks/{task_id}/_cancel
@@ -8004,7 +8004,7 @@ public ElasticsearchResponse<T> TasksCancel<T>(number task_id, Func<TasksCancelR
80048004
///</summary>
80058005
///<param name="task_id">Cancel the task with specified id</param>
80068006
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
8007-
public Task<ElasticsearchResponse<T>> TasksCancelAsync<T>(number task_id, Func<TasksCancelRequestParameters, TasksCancelRequestParameters> requestParameters = null)
8007+
public Task<ElasticsearchResponse<T>> TasksCancelAsync<T>(string task_id, Func<TasksCancelRequestParameters, TasksCancelRequestParameters> requestParameters = null)
80088008
where T : class => this.DoRequestAsync<T>(POST, Url($"_tasks/{task_id.NotNull("task_id")}/_cancel"), null, _params(requestParameters));
80098009

80108010
///<summary>Represents a GET on /_tasks
@@ -8044,7 +8044,7 @@ public Task<ElasticsearchResponse<T>> TasksListAsync<T>(Func<TasksListRequestPar
80448044
///</summary>
80458045
///<param name="task_id">Return the task with specified id</param>
80468046
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
8047-
public ElasticsearchResponse<T> TasksList<T>(number task_id, Func<TasksListRequestParameters, TasksListRequestParameters> requestParameters = null)
8047+
public ElasticsearchResponse<T> TasksList<T>(string task_id, Func<TasksListRequestParameters, TasksListRequestParameters> requestParameters = null)
80488048
where T : class => this.DoRequest<T>(GET, Url($"_tasks/{task_id.NotNull("task_id")}"), null, _params(requestParameters));
80498049

80508050
///<summary>Represents a GET on /_tasks/{task_id}
@@ -8058,7 +8058,7 @@ public ElasticsearchResponse<T> TasksList<T>(number task_id, Func<TasksListReque
80588058
///</summary>
80598059
///<param name="task_id">Return the task with specified id</param>
80608060
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
8061-
public Task<ElasticsearchResponse<T>> TasksListAsync<T>(number task_id, Func<TasksListRequestParameters, TasksListRequestParameters> requestParameters = null)
8061+
public Task<ElasticsearchResponse<T>> TasksListAsync<T>(string task_id, Func<TasksListRequestParameters, TasksListRequestParameters> requestParameters = null)
80628062
where T : class => this.DoRequestAsync<T>(GET, Url($"_tasks/{task_id.NotNull("task_id")}"), null, _params(requestParameters));
80638063

80648064
///<summary>Represents a GET on /{index}/{type}/_termvectors

src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6109,7 +6109,7 @@ public partial interface IElasticLowLevelClient
61096109
///</summary>
61106110
///<param name="body">The search definition using the Query DSL and the prototype for the index request.</param>
61116111
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
6112-
ElasticsearchResponse<T> Reindex<T>(PostData<object> body, Func<ReindexRequestParameters, ReindexRequestParameters> requestParameters = null) where T : class;
6112+
ElasticsearchResponse<T> Reindex<T>(PostData<object> body, Func<ReindexOnServerRequestParameters, ReindexOnServerRequestParameters> requestParameters = null) where T : class;
61136113

61146114
///<summary>Represents a POST on /_reindex
61156115
///<para></para>Returns: A task of ElasticsearchResponse&lt;T&gt; where the behaviour depends on the type of T:
@@ -6122,7 +6122,7 @@ public partial interface IElasticLowLevelClient
61226122
///</summary>
61236123
///<param name="body">The search definition using the Query DSL and the prototype for the index request.</param>
61246124
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
6125-
Task<ElasticsearchResponse<T>> ReindexAsync<T>(PostData<object> body, Func<ReindexRequestParameters, ReindexRequestParameters> requestParameters = null) where T : class;
6125+
Task<ElasticsearchResponse<T>> ReindexAsync<T>(PostData<object> body, Func<ReindexOnServerRequestParameters, ReindexOnServerRequestParameters> requestParameters = null) where T : class;
61266126

61276127
///<summary>Represents a GET on /_render/template
61286128
///<para></para>Returns: ElasticsearchResponse&lt;T&gt; where the behavior depends on the type of T:
@@ -7441,7 +7441,7 @@ public partial interface IElasticLowLevelClient
74417441
///</summary>
74427442
///<param name="task_id">Cancel the task with specified id</param>
74437443
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
7444-
ElasticsearchResponse<T> TasksCancel<T>(number task_id, Func<TasksCancelRequestParameters, TasksCancelRequestParameters> requestParameters = null) where T : class;
7444+
ElasticsearchResponse<T> TasksCancel<T>(string task_id, Func<TasksCancelRequestParameters, TasksCancelRequestParameters> requestParameters = null) where T : class;
74457445

74467446
///<summary>Represents a POST on /_tasks/{task_id}/_cancel
74477447
///<para></para>Returns: A task of ElasticsearchResponse&lt;T&gt; where the behaviour depends on the type of T:
@@ -7454,7 +7454,7 @@ public partial interface IElasticLowLevelClient
74547454
///</summary>
74557455
///<param name="task_id">Cancel the task with specified id</param>
74567456
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
7457-
Task<ElasticsearchResponse<T>> TasksCancelAsync<T>(number task_id, Func<TasksCancelRequestParameters, TasksCancelRequestParameters> requestParameters = null) where T : class;
7457+
Task<ElasticsearchResponse<T>> TasksCancelAsync<T>(string task_id, Func<TasksCancelRequestParameters, TasksCancelRequestParameters> requestParameters = null) where T : class;
74587458

74597459
///<summary>Represents a GET on /_tasks
74607460
///<para></para>Returns: ElasticsearchResponse&lt;T&gt; where the behavior depends on the type of T:
@@ -7491,7 +7491,7 @@ public partial interface IElasticLowLevelClient
74917491
///</summary>
74927492
///<param name="task_id">Return the task with specified id</param>
74937493
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
7494-
ElasticsearchResponse<T> TasksList<T>(number task_id, Func<TasksListRequestParameters, TasksListRequestParameters> requestParameters = null) where T : class;
7494+
ElasticsearchResponse<T> TasksList<T>(string task_id, Func<TasksListRequestParameters, TasksListRequestParameters> requestParameters = null) where T : class;
74957495

74967496
///<summary>Represents a GET on /_tasks/{task_id}
74977497
///<para></para>Returns: A task of ElasticsearchResponse&lt;T&gt; where the behaviour depends on the type of T:
@@ -7504,7 +7504,7 @@ public partial interface IElasticLowLevelClient
75047504
///</summary>
75057505
///<param name="task_id">Return the task with specified id</param>
75067506
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
7507-
Task<ElasticsearchResponse<T>> TasksListAsync<T>(number task_id, Func<TasksListRequestParameters, TasksListRequestParameters> requestParameters = null) where T : class;
7507+
Task<ElasticsearchResponse<T>> TasksListAsync<T>(string task_id, Func<TasksListRequestParameters, TasksListRequestParameters> requestParameters = null) where T : class;
75087508

75097509
///<summary>Represents a GET on /{index}/{type}/_termvectors
75107510
///<para></para>Returns: ElasticsearchResponse&lt;T&gt; where the behavior depends on the type of T:

src/Elasticsearch.Net/Responses/ElasticsearchResponse.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class ElasticsearchResponse<T> : IApiCallDetails
7575
public bool SuccessOrKnownError =>
7676
this.Success || (HttpStatusCode >= 400 && HttpStatusCode < 599
7777
&& HttpStatusCode != 503 //service unavailable needs to be retried
78-
&& HttpStatusCode != 502 //bad gateway needs to be retried
78+
&& HttpStatusCode != 502 //bad gateway needs to be retried
7979
);
8080

8181
public Exception OriginalException { get; protected internal set; }
@@ -90,7 +90,8 @@ public ElasticsearchResponse(Exception e)
9090

9191
public ElasticsearchResponse(int statusCode, IEnumerable<int> allowedStatusCodes)
9292
{
93-
this.Success = statusCode >= 200 && statusCode < 300 || allowedStatusCodes.Contains(statusCode);
93+
var statusCodes = allowedStatusCodes as int[] ?? allowedStatusCodes.ToArray();
94+
this.Success = statusCode >= 200 && statusCode < 300 || statusCodes.Contains(statusCode) || statusCodes.Contains(-1);
9495
this.HttpStatusCode = statusCode;
9596
}
9697

src/Elasticsearch.Net/Serialization/UrlFormatProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public string GetStringValue(object valueType)
4646

4747
return AttemptTheRightToString(valueType);
4848
}
49-
49+
5050
public string AttemptTheRightToString(object value)
5151
{
5252
var explicitImplementation = this.QueryStringValueType(value as IUrlParameter);
5353
if (explicitImplementation != null) return explicitImplementation;
54-
54+
5555

5656
return value.ToString();
5757
}
@@ -64,4 +64,4 @@ public string QueryStringValueType(IUrlParameter value)
6464

6565

6666
}
67-
}
67+
}

0 commit comments

Comments
 (0)