Skip to content

Commit fc7f78e

Browse files
committed
Fix #4289 low level client index http method generation wrong
We used to always send POST which is not right either but the server accepted it. Now that we have a new format and transform to the old format in the interim we only picked up PUT for all which is not correct for index operations without an id.
1 parent 7cb539a commit fc7f78e

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/CodeGeneration/ApiGenerator/Domain/Specification/ApiEndpoint.cs

+4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ public IReadOnlyCollection<LowLevelClientMethod> LowLevelClientMethods
133133
var methodName = CsharpNames.PerPathMethodName(path.Path);
134134
var parts = new List<UrlPart>(path.Parts);
135135
var mapsApiArgumentHints = parts.Select(p => p.Name).ToList();
136+
// TODO This is hack until we stop transforming the new spec format into the old
137+
if (Name == "index" && !mapsApiArgumentHints.Contains("id"))
138+
httpMethod = "POST";
139+
else if (Name == "index") httpMethod = PreferredHttpMethod;
136140

137141
if (Body != null)
138142
{

src/Elasticsearch.Net/ElasticLowLevelClient.NoNamespace.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -622,36 +622,36 @@ public TResponse Index<TResponse>(string index, string id, PostData body, IndexR
622622
[MapsApi("index", "index, id, body")]
623623
public Task<TResponse> IndexAsync<TResponse>(string index, string id, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default)
624624
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"{index:index}/_doc/{id:id}"), ctx, body, RequestParams(requestParameters));
625-
///<summary>PUT on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
625+
///<summary>POST on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
626626
///<param name = "index">The name of the index</param>
627627
///<param name = "body">The document</param>
628628
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
629629
public TResponse Index<TResponse>(string index, PostData body, IndexRequestParameters requestParameters = null)
630-
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(PUT, Url($"{index:index}/_doc"), body, RequestParams(requestParameters));
631-
///<summary>PUT on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
630+
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(POST, Url($"{index:index}/_doc"), body, RequestParams(requestParameters));
631+
///<summary>POST on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
632632
///<param name = "index">The name of the index</param>
633633
///<param name = "body">The document</param>
634634
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
635635
[MapsApi("index", "index, body")]
636636
public Task<TResponse> IndexAsync<TResponse>(string index, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default)
637-
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"{index:index}/_doc"), ctx, body, RequestParams(requestParameters));
638-
///<summary>PUT on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
637+
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(POST, Url($"{index:index}/_doc"), ctx, body, RequestParams(requestParameters));
638+
///<summary>POST on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
639639
///<param name = "index">The name of the index</param>
640640
///<param name = "type">The type of the document</param>
641641
///<param name = "body">The document</param>
642642
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
643643
[Obsolete("Deprecated in version 7.0.0: Specifying types in urls has been deprecated")]
644644
public TResponse IndexUsingType<TResponse>(string index, string type, PostData body, IndexRequestParameters requestParameters = null)
645-
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(PUT, Url($"{index:index}/{type:type}"), body, RequestParams(requestParameters));
646-
///<summary>PUT on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
645+
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(POST, Url($"{index:index}/{type:type}"), body, RequestParams(requestParameters));
646+
///<summary>POST on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
647647
///<param name = "index">The name of the index</param>
648648
///<param name = "type">The type of the document</param>
649649
///<param name = "body">The document</param>
650650
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
651651
[Obsolete("Deprecated in version 7.0.0: Specifying types in urls has been deprecated")]
652652
[MapsApi("index", "index, type, body")]
653653
public Task<TResponse> IndexUsingTypeAsync<TResponse>(string index, string type, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default)
654-
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"{index:index}/{type:type}"), ctx, body, RequestParams(requestParameters));
654+
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(POST, Url($"{index:index}/{type:type}"), ctx, body, RequestParams(requestParameters));
655655
///<summary>PUT on /{index}/{type}/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
656656
///<param name = "index">The name of the index</param>
657657
///<param name = "type">The type of the document</param>

src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -517,27 +517,27 @@ TResponse Index<TResponse>(string index, string id, PostData body, IndexRequestP
517517
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
518518
Task<TResponse> IndexAsync<TResponse>(string index, string id, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default)
519519
where TResponse : class, IElasticsearchResponse, new();
520-
///<summary>PUT on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
520+
///<summary>POST on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
521521
///<param name = "index">The name of the index</param>
522522
///<param name = "body">The document</param>
523523
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
524524
TResponse Index<TResponse>(string index, PostData body, IndexRequestParameters requestParameters = null)
525525
where TResponse : class, IElasticsearchResponse, new();
526-
///<summary>PUT on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
526+
///<summary>POST on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
527527
///<param name = "index">The name of the index</param>
528528
///<param name = "body">The document</param>
529529
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
530530
Task<TResponse> IndexAsync<TResponse>(string index, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default)
531531
where TResponse : class, IElasticsearchResponse, new();
532-
///<summary>PUT on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
532+
///<summary>POST on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
533533
///<param name = "index">The name of the index</param>
534534
///<param name = "type">The type of the document</param>
535535
///<param name = "body">The document</param>
536536
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
537537
[Obsolete("Deprecated in version 7.0.0: Specifying types in urls has been deprecated")]
538538
TResponse IndexUsingType<TResponse>(string index, string type, PostData body, IndexRequestParameters requestParameters = null)
539539
where TResponse : class, IElasticsearchResponse, new();
540-
///<summary>PUT on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
540+
///<summary>POST on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
541541
///<param name = "index">The name of the index</param>
542542
///<param name = "type">The type of the document</param>
543543
///<param name = "body">The document</param>

0 commit comments

Comments
 (0)