Skip to content

Commit 1166d8e

Browse files
committed
Fix #1736 index request incorrectly doing not resolved
1 parent 20fdc1a commit 1166d8e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Diff for: src/Nest/CommonAbstractions/Infer/Id/Id.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal string GetString(IConnectionSettingsValues nestSettings)
3030
{
3131
if (this.Document != null)
3232
{
33-
return nestSettings.Inferrer.Id(this.Document);
33+
Value = nestSettings.Inferrer.Id(this.Document);
3434
}
3535

3636
var s = Value as string;

Diff for: src/Nest/Document/Single/Index/IndexRequest.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ public partial interface IIndexRequest<TDocument> : IIndexRequest where TDocumen
1717
public partial class IndexRequest<TDocument>
1818
where TDocument : class
1919
{
20-
protected override HttpMethod HttpMethod => ((IIndexRequest<TDocument>)this).Id == null ? HttpMethod.POST : HttpMethod.PUT;
20+
protected override HttpMethod HttpMethod => GetHttpMethod(this);
2121

2222
partial void DocumentFromPath(TDocument doc) => this.Document = doc;
2323

2424
object IIndexRequest.UntypedDocument => this.Document;
2525

2626
public TDocument Document { get; set; }
27+
28+
internal static HttpMethod GetHttpMethod(IIndexRequest<TDocument> r) => (r.Id != null && r.Id.Value != null) ? HttpMethod.PUT : HttpMethod.POST;
2729
}
2830

2931
public partial class IndexDescriptor<TDocument> where TDocument : class
3032
{
31-
protected override HttpMethod HttpMethod => Self.Id == null ? HttpMethod.POST : HttpMethod.PUT;
33+
protected override HttpMethod HttpMethod => IndexRequest<TDocument>.GetHttpMethod(this);
3234
partial void DocumentFromPath(TDocument doc) => Assign(a => a.Document = doc);
3335
object IIndexRequest.UntypedDocument => Self.Document;
3436

Diff for: src/Tests/Document/Single/Index/IndexUrlTests.cs

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ await POST("/project/project")
2222
}))
2323
;
2424

25+
await POST("/project/project")
26+
.Fluent(c => c.Index(new { }, i => i.Index(typeof(Project)).Type(typeof(Project))))
27+
.Request(c => c.Index(new IndexRequest<object>("project", "project") { Document = new { } }))
28+
.FluentAsync(c => c.IndexAsync(new { }, i => i.Index(typeof(Project)).Type(typeof(Project))))
29+
.RequestAsync(c => c.IndexAsync(new IndexRequest<object>(typeof(Project), TypeName.From<Project>())
30+
{
31+
Document = new { }
32+
}))
33+
;
34+
2535
await PUT("/project/project/NEST")
2636
.Fluent(c => c.Index(project))
2737
.Request(c => c.Index(new IndexRequest<Project>("project", "project", "NEST") { Document = project }))

0 commit comments

Comments
 (0)