diff --git a/src/CodeGeneration/ApiGenerator/Domain/Specification/ApiEndpoint.cs b/src/CodeGeneration/ApiGenerator/Domain/Specification/ApiEndpoint.cs index 6c2d761230f..d12ab9feba5 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/Specification/ApiEndpoint.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/Specification/ApiEndpoint.cs @@ -133,6 +133,10 @@ public IReadOnlyCollection LowLevelClientMethods var methodName = CsharpNames.PerPathMethodName(path.Path); var parts = new List(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) { diff --git a/src/Elasticsearch.Net/ElasticLowLevelClient.NoNamespace.cs b/src/Elasticsearch.Net/ElasticLowLevelClient.NoNamespace.cs index 34ed62f6d6d..15bbb8e5153 100644 --- a/src/Elasticsearch.Net/ElasticLowLevelClient.NoNamespace.cs +++ b/src/Elasticsearch.Net/ElasticLowLevelClient.NoNamespace.cs @@ -622,28 +622,28 @@ public TResponse Index(string index, string id, PostData body, IndexR [MapsApi("index", "index, id, body")] public Task IndexAsync(string index, string id, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default) where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync(PUT, Url($"{index:index}/_doc/{id:id}"), ctx, body, RequestParams(requestParameters)); - ///PUT on /{index}/_doc https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + ///POST on /{index}/_doc https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html ///The name of the index ///The document ///Request specific configuration such as querystring parameters & request specific connection settings. public TResponse Index(string index, PostData body, IndexRequestParameters requestParameters = null) - where TResponse : class, IElasticsearchResponse, new() => DoRequest(PUT, Url($"{index:index}/_doc"), body, RequestParams(requestParameters)); - ///PUT on /{index}/_doc https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + where TResponse : class, IElasticsearchResponse, new() => DoRequest(POST, Url($"{index:index}/_doc"), body, RequestParams(requestParameters)); + ///POST on /{index}/_doc https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html ///The name of the index ///The document ///Request specific configuration such as querystring parameters & request specific connection settings. [MapsApi("index", "index, body")] public Task IndexAsync(string index, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default) - where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync(PUT, Url($"{index:index}/_doc"), ctx, body, RequestParams(requestParameters)); - ///PUT on /{index}/{type} https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync(POST, Url($"{index:index}/_doc"), ctx, body, RequestParams(requestParameters)); + ///POST on /{index}/{type} https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html ///The name of the index ///The type of the document ///The document ///Request specific configuration such as querystring parameters & request specific connection settings. [Obsolete("Deprecated in version 7.0.0: Specifying types in urls has been deprecated")] public TResponse IndexUsingType(string index, string type, PostData body, IndexRequestParameters requestParameters = null) - where TResponse : class, IElasticsearchResponse, new() => DoRequest(PUT, Url($"{index:index}/{type:type}"), body, RequestParams(requestParameters)); - ///PUT on /{index}/{type} https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + where TResponse : class, IElasticsearchResponse, new() => DoRequest(POST, Url($"{index:index}/{type:type}"), body, RequestParams(requestParameters)); + ///POST on /{index}/{type} https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html ///The name of the index ///The type of the document ///The document @@ -651,7 +651,7 @@ public TResponse IndexUsingType(string index, string type, PostData b [Obsolete("Deprecated in version 7.0.0: Specifying types in urls has been deprecated")] [MapsApi("index", "index, type, body")] public Task IndexUsingTypeAsync(string index, string type, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default) - where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync(PUT, Url($"{index:index}/{type:type}"), ctx, body, RequestParams(requestParameters)); + where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync(POST, Url($"{index:index}/{type:type}"), ctx, body, RequestParams(requestParameters)); ///PUT on /{index}/{type}/{id} https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html ///The name of the index ///The type of the document diff --git a/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs b/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs index b4f09d5fef7..791ee4b6752 100644 --- a/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs +++ b/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs @@ -517,19 +517,19 @@ TResponse Index(string index, string id, PostData body, IndexRequestP ///Request specific configuration such as querystring parameters & request specific connection settings. Task IndexAsync(string index, string id, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default) where TResponse : class, IElasticsearchResponse, new(); - ///PUT on /{index}/_doc https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + ///POST on /{index}/_doc https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html ///The name of the index ///The document ///Request specific configuration such as querystring parameters & request specific connection settings. TResponse Index(string index, PostData body, IndexRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new(); - ///PUT on /{index}/_doc https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + ///POST on /{index}/_doc https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html ///The name of the index ///The document ///Request specific configuration such as querystring parameters & request specific connection settings. Task IndexAsync(string index, PostData body, IndexRequestParameters requestParameters = null, CancellationToken ctx = default) where TResponse : class, IElasticsearchResponse, new(); - ///PUT on /{index}/{type} https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + ///POST on /{index}/{type} https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html ///The name of the index ///The type of the document ///The document @@ -537,7 +537,7 @@ Task IndexAsync(string index, PostData body, IndexRequestP [Obsolete("Deprecated in version 7.0.0: Specifying types in urls has been deprecated")] TResponse IndexUsingType(string index, string type, PostData body, IndexRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new(); - ///PUT on /{index}/{type} https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + ///POST on /{index}/{type} https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html ///The name of the index ///The type of the document ///The document diff --git a/src/Tests/Tests/Document/Single/Index/IndexUrlTests.cs b/src/Tests/Tests/Document/Single/Index/IndexUrlTests.cs index 4b4e67e9899..5447a59e3d1 100644 --- a/src/Tests/Tests/Document/Single/Index/IndexUrlTests.cs +++ b/src/Tests/Tests/Document/Single/Index/IndexUrlTests.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Elastic.Xunit.XunitPlumbing; +using Elasticsearch.Net; using FluentAssertions; using Nest; using Tests.Domain; @@ -42,6 +43,20 @@ await PUT("/project/_doc/NEST") .RequestAsync(c => c.IndexAsync(new IndexRequest(project))); } + [U] public async Task LowLevelUrls() + { + var project = new Project { Name = "NEST" }; + + await POST("/index/_doc") + .LowLevel(c => c.Index("index", PostData.Empty)) + .LowLevelAsync(c => c.IndexAsync("index", PostData.Empty)); + + await PUT("/index/_doc/id") + .LowLevel(c => c.Index("index", "id", PostData.Empty)) + .LowLevelAsync(c => c.IndexAsync("index", "id", PostData.Empty)); + + } + [U] public async Task CanIndexUrlIds() { var id = "http://my.local/id?qwe=2"; diff --git a/src/Tests/Tests/Framework/EndpointTests/UrlTests.cs b/src/Tests/Tests/Framework/EndpointTests/UrlTests.cs index d604309cdbe..6bf18ed192b 100644 --- a/src/Tests/Tests/Framework/EndpointTests/UrlTests.cs +++ b/src/Tests/Tests/Framework/EndpointTests/UrlTests.cs @@ -71,6 +71,11 @@ public UrlTester LowLevel(Func call) var callDetails = call(Client.LowLevel); return Assert("lowlevel", callDetails); } + public async Task LowLevelAsync(Func> call) + { + var callDetails = await call(Client.LowLevel); + return Assert("lowlevel async", callDetails); + } private UrlTester WhenCalling(Func call, string typeOfCall) where TResponse : IResponse