diff --git a/src/Nest/CommonAbstractions/Infer/Id/Id.cs b/src/Nest/CommonAbstractions/Infer/Id/Id.cs index 52e0577b054..c78831883c2 100644 --- a/src/Nest/CommonAbstractions/Infer/Id/Id.cs +++ b/src/Nest/CommonAbstractions/Infer/Id/Id.cs @@ -30,13 +30,10 @@ public class Id : IEquatable, IUrlParameter string IUrlParameter.GetString(IConnectionConfigurationValues settings) { - var nestSettings = settings as IConnectionSettingsValues; - return GetString(nestSettings); + var nestSettings = (IConnectionSettingsValues)settings; + return nestSettings.Inferrer.Id(this.Document) ?? this.StringOrLongValue; } - private string GetString(IConnectionSettingsValues nestSettings) => - this.Document != null ? nestSettings.Inferrer.Id(this.Document) : this.StringOrLongValue; - public bool Equals(Id other) { if (this.Tag + other.Tag == 1) diff --git a/src/Nest/Document/Single/Index/IndexRequest.cs b/src/Nest/Document/Single/Index/IndexRequest.cs index 2a10eb19f2c..022bb17b5b9 100644 --- a/src/Nest/Document/Single/Index/IndexRequest.cs +++ b/src/Nest/Document/Single/Index/IndexRequest.cs @@ -19,7 +19,8 @@ public partial class IndexRequest protected override HttpMethod HttpMethod => GetHttpMethod(this); - internal static HttpMethod GetHttpMethod(IIndexRequest request) => request.Id.IsConditionless() ? HttpMethod.POST : HttpMethod.PUT; + internal static HttpMethod GetHttpMethod(IIndexRequest request) => + request.Id?.StringOrLongValue != null || request.RouteValues.Id != null ? HttpMethod.PUT: HttpMethod.POST; partial void DocumentFromPath(TDocument document) => this.Document = document; @@ -27,7 +28,6 @@ public partial class IndexRequest void IProxyRequest.WriteJson(IElasticsearchSerializer sourceSerializer, Stream stream, SerializationFormatting formatting) => sourceSerializer.Serialize(this.Document, stream, formatting); - } public partial class IndexDescriptor where TDocument : class @@ -41,7 +41,5 @@ public partial class IndexDescriptor where TDocument : class void IProxyRequest.WriteJson(IElasticsearchSerializer sourceSerializer, Stream stream, SerializationFormatting formatting) => sourceSerializer.Serialize(Self.Document, stream, formatting); - } - } diff --git a/src/Tests/Document/Single/Index/IndexUrlTests.cs b/src/Tests/Document/Single/Index/IndexUrlTests.cs index 03e7724ed46..448e26f83f8 100644 --- a/src/Tests/Document/Single/Index/IndexUrlTests.cs +++ b/src/Tests/Document/Single/Index/IndexUrlTests.cs @@ -23,14 +23,11 @@ await POST("/project/doc?routing=NEST") Document = project })); - //no explit ID is provided and none can be inferred on the anonymous object so this falls back to a PUT to /index/type - await PUT("/project/doc") - .Fluent(c => c.Index(new { }, i => i.Index(typeof(Project)).Type(typeof(Project)))) - .FluentAsync(c => c.IndexAsync(new { }, i => i.Index(typeof(Project)).Type(typeof(Project)))); - - //no explit ID is provided and document is not fed into DocumentPath using explicit OIS. + //no explicit ID is provided and none can be inferred on the anonymous object so this falls back to a POST to /index/type await POST("/project/doc") + .Fluent(c => c.Index(new { }, i => i.Index(typeof(Project)).Type(typeof(Project)))) .Request(c => c.Index(new IndexRequest("project", "doc") {Document = new { }})) + .FluentAsync(c => c.IndexAsync(new { }, i => i.Index(typeof(Project)).Type(typeof(Project)))) .RequestAsync(c => c.IndexAsync(new IndexRequest(typeof(Project), TypeName.From()) { Document = new { }