Skip to content

Fix #4289 low level client index http method generation wrong #4290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public IReadOnlyCollection<LowLevelClientMethod> LowLevelClientMethods
var methodName = CsharpNames.PerPathMethodName(path.Path);
var parts = new List<UrlPart>(path.Parts);
var mapsApiArgumentHints = parts.Select(p => p.Name).ToList();
// TODO This is hack until we stop transforming the new spec format into the old
if (Name == "index" && !mapsApiArgumentHints.Contains("id"))
httpMethod = "POST";
else if (Name == "index") httpMethod = PreferredHttpMethod;

if (Body != null)
{
Expand Down
16 changes: 8 additions & 8 deletions src/Elasticsearch.Net/ElasticLowLevelClient.NoNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,36 +622,36 @@ public TResponse Index<TResponse>(string index, string id, PostData body, IndexR
[MapsApi("index", "index, id, body")]
public Task<TResponse> IndexAsync<TResponse>(string index, string id, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"{index:index}/_doc/{id:id}"), ctx, body, RequestParams(requestParameters));
///<summary>PUT on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<summary>POST on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<param name = "index">The name of the index</param>
///<param name = "body">The document</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public TResponse Index<TResponse>(string index, PostData body, IndexRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(PUT, Url($"{index:index}/_doc"), body, RequestParams(requestParameters));
///<summary>PUT on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(POST, Url($"{index:index}/_doc"), body, RequestParams(requestParameters));
///<summary>POST on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<param name = "index">The name of the index</param>
///<param name = "body">The document</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
[MapsApi("index", "index, body")]
public Task<TResponse> IndexAsync<TResponse>(string index, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"{index:index}/_doc"), ctx, body, RequestParams(requestParameters));
///<summary>PUT on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(POST, Url($"{index:index}/_doc"), ctx, body, RequestParams(requestParameters));
///<summary>POST on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<param name = "index">The name of the index</param>
///<param name = "type">The type of the document</param>
///<param name = "body">The document</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
[Obsolete("Deprecated in version 7.0.0: Specifying types in urls has been deprecated")]
public TResponse IndexUsingType<TResponse>(string index, string type, PostData body, IndexRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(PUT, Url($"{index:index}/{type:type}"), body, RequestParams(requestParameters));
///<summary>PUT on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(POST, Url($"{index:index}/{type:type}"), body, RequestParams(requestParameters));
///<summary>POST on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<param name = "index">The name of the index</param>
///<param name = "type">The type of the document</param>
///<param name = "body">The document</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
[Obsolete("Deprecated in version 7.0.0: Specifying types in urls has been deprecated")]
[MapsApi("index", "index, type, body")]
public Task<TResponse> IndexUsingTypeAsync<TResponse>(string index, string type, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"{index:index}/{type:type}"), ctx, body, RequestParams(requestParameters));
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(POST, Url($"{index:index}/{type:type}"), ctx, body, RequestParams(requestParameters));
///<summary>PUT on /{index}/{type}/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<param name = "index">The name of the index</param>
///<param name = "type">The type of the document</param>
Expand Down
8 changes: 4 additions & 4 deletions src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,27 +517,27 @@ TResponse Index<TResponse>(string index, string id, PostData body, IndexRequestP
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
Task<TResponse> IndexAsync<TResponse>(string index, string id, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new();
///<summary>PUT on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<summary>POST on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<param name = "index">The name of the index</param>
///<param name = "body">The document</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
TResponse Index<TResponse>(string index, PostData body, IndexRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new();
///<summary>PUT on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<summary>POST on /{index}/_doc <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<param name = "index">The name of the index</param>
///<param name = "body">The document</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
Task<TResponse> IndexAsync<TResponse>(string index, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new();
///<summary>PUT on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<summary>POST on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<param name = "index">The name of the index</param>
///<param name = "type">The type of the document</param>
///<param name = "body">The document</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
[Obsolete("Deprecated in version 7.0.0: Specifying types in urls has been deprecated")]
TResponse IndexUsingType<TResponse>(string index, string type, PostData body, IndexRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new();
///<summary>PUT on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<summary>POST on /{index}/{type} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html</para></summary>
///<param name = "index">The name of the index</param>
///<param name = "type">The type of the document</param>
///<param name = "body">The document</param>
Expand Down
15 changes: 15 additions & 0 deletions src/Tests/Tests/Document/Single/Index/IndexUrlTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using Elastic.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Domain;
Expand Down Expand Up @@ -42,6 +43,20 @@ await PUT("/project/_doc/NEST")
.RequestAsync(c => c.IndexAsync(new IndexRequest<Project>(project)));
}

[U] public async Task LowLevelUrls()
{
var project = new Project { Name = "NEST" };

await POST("/index/_doc")
.LowLevel(c => c.Index<VoidResponse>("index", PostData.Empty))
.LowLevelAsync(c => c.IndexAsync<VoidResponse>("index", PostData.Empty));

await PUT("/index/_doc/id")
.LowLevel(c => c.Index<VoidResponse>("index", "id", PostData.Empty))
.LowLevelAsync(c => c.IndexAsync<VoidResponse>("index", "id", PostData.Empty));

}

[U] public async Task CanIndexUrlIds()
{
var id = "http://my.local/id?qwe=2";
Expand Down
5 changes: 5 additions & 0 deletions src/Tests/Tests/Framework/EndpointTests/UrlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public UrlTester LowLevel(Func<IElasticLowLevelClient, IApiCallDetails> call)
var callDetails = call(Client.LowLevel);
return Assert("lowlevel", callDetails);
}
public async Task<UrlTester> LowLevelAsync(Func<IElasticLowLevelClient, Task<VoidResponse>> call)
{
var callDetails = await call(Client.LowLevel);
return Assert("lowlevel async", callDetails);
}

private UrlTester WhenCalling<TResponse>(Func<IElasticClient, TResponse> call, string typeOfCall)
where TResponse : IResponse
Expand Down