Skip to content
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
7 changes: 2 additions & 5 deletions src/Nest/CommonAbstractions/Infer/Id/Id.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ public class Id : IEquatable<Id>, 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)
Expand Down
6 changes: 2 additions & 4 deletions src/Nest/Document/Single/Index/IndexRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public partial class IndexRequest<TDocument>

protected override HttpMethod HttpMethod => GetHttpMethod(this);

internal static HttpMethod GetHttpMethod(IIndexRequest<TDocument> request) => request.Id.IsConditionless() ? HttpMethod.POST : HttpMethod.PUT;
internal static HttpMethod GetHttpMethod(IIndexRequest<TDocument> request) =>
request.Id?.StringOrLongValue != null || request.RouteValues.Id != null ? HttpMethod.PUT: HttpMethod.POST;

partial void DocumentFromPath(TDocument document) => this.Document = document;

private TDocument AutoRouteDocument() => Self.Document;

void IProxyRequest.WriteJson(IElasticsearchSerializer sourceSerializer, Stream stream, SerializationFormatting formatting) =>
sourceSerializer.Serialize(this.Document, stream, formatting);

}

public partial class IndexDescriptor<TDocument> where TDocument : class
Expand All @@ -41,7 +41,5 @@ public partial class IndexDescriptor<TDocument> where TDocument : class

void IProxyRequest.WriteJson(IElasticsearchSerializer sourceSerializer, Stream stream, SerializationFormatting formatting) =>
sourceSerializer.Serialize(Self.Document, stream, formatting);

}

}
9 changes: 3 additions & 6 deletions src/Tests/Document/Single/Index/IndexUrlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<object>("project", "doc") {Document = new { }}))
.FluentAsync(c => c.IndexAsync(new { }, i => i.Index(typeof(Project)).Type(typeof(Project))))
.RequestAsync(c => c.IndexAsync(new IndexRequest<object>(typeof(Project), TypeName.From<Project>())
{
Document = new { }
Expand Down