Skip to content

Commit 8f5e5dd

Browse files
committed
renamed .Object(T) in favor of .Id(T), improved naming on Update() and Bulk(Update()) and made them consistent
1 parent ed8c3b8 commit 8f5e5dd

File tree

15 files changed

+133
-20
lines changed

15 files changed

+133
-20
lines changed

src/Nest/DSL/Bulk/BulkUpdateDescriptor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public BulkUpdateOperation(TDocument inferFrom)
3333
{
3434
this.InferFrom = inferFrom;
3535
}
36+
3637
public BulkUpdateOperation(TDocument inferFrom, TPartialDocument update)
3738
{
3839
this.InferFrom = inferFrom;
@@ -163,7 +164,7 @@ public BulkUpdateDescriptor<TDocument, TPartialDocument> Id(string id)
163164
/// The object to update, if id is not manually set it will be inferred from the object.
164165
/// Used ONLY to infer the ID see Document() to apply a partial object merge.
165166
/// </summary>
166-
public BulkUpdateDescriptor<TDocument, TPartialDocument> InferFrom(TDocument @object, bool useAsUpsert = false)
167+
public BulkUpdateDescriptor<TDocument, TPartialDocument> Id(TDocument @object, bool useAsUpsert = false)
167168
{
168169
Self.InferFrom = @object;
169170
if (useAsUpsert) return this.Upsert(@object);

src/Nest/DSL/Paths/DocumentOptionalPathDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public TDescriptor Id(string id)
159159
Self.Id = id;
160160
return (TDescriptor)this;
161161
}
162-
public TDescriptor Object(T @object)
162+
public TDescriptor Id(T @object)
163163
{
164164
Self.IdFrom = @object;
165165
return (TDescriptor)this;

src/Nest/DSL/UpdateDescriptor.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public partial class UpdateDescriptor<TDocument,TPartialDocument>
8181
where TPartialDocument : class
8282
{
8383

84+
private TDocument _inferFrom { get; set; }
85+
8486
private IUpdateRequest<TDocument, TPartialDocument> Self { get { return this; } }
8587

8688
string IUpdateRequest<TDocument, TPartialDocument>.Script { get; set; }
@@ -110,6 +112,15 @@ public UpdateDescriptor<TDocument, TPartialDocument> Params(Func<FluentDictionar
110112
return this;
111113
}
112114

115+
public UpdateDescriptor<TDocument, TPartialDocument> Id(TDocument document, bool useAsUpsert)
116+
{
117+
((IDocumentOptionalPath<UpdateRequestParameters, TDocument>)Self).IdFrom = document;
118+
if (useAsUpsert)
119+
return this.Upsert(document);
120+
return this;
121+
}
122+
123+
113124
/// <summary>
114125
/// The full document to be created if an existing document does not exist for a partial merge.
115126
/// </summary>
@@ -155,8 +166,10 @@ public UpdateDescriptor<TDocument,TPartialDocument> Fields(params Expression<Fun
155166

156167
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<UpdateRequestParameters> pathInfo)
157168
{
158-
if (Self.PartialDocument != null && Self.Id == null)
159-
Self.Id = new ElasticInferrer(settings).Id(Self.PartialDocument);
169+
if (pathInfo.Id.IsNullOrEmpty())
170+
{
171+
pathInfo.Id = settings.Inferrer.Id(Self.Upsert);
172+
}
160173

161174
pathInfo.HttpMethod = PathInfoHttpMethod.POST;
162175
}

src/Nest/ElasticClient-Index.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public IIndexResponse Index<T>(T @object, Func<IndexDescriptor<T>, IndexDescript
1313
{
1414
@object.ThrowIfNull("object");
1515
indexSelector = indexSelector ?? (s => s);
16-
var descriptor = indexSelector(new IndexDescriptor<T>().Object(@object));
16+
var descriptor = indexSelector(new IndexDescriptor<T>().Id(@object));
1717
return this.Dispatch<IndexDescriptor<T>, IndexRequestParameters, IndexResponse>(
1818
descriptor,
1919
(p, d) => this.RawDispatch.IndexDispatch<IndexResponse>(p, @object));
@@ -34,7 +34,7 @@ public Task<IIndexResponse> IndexAsync<T>(T @object, Func<IndexDescriptor<T>, In
3434
{
3535
@object.ThrowIfNull("object");
3636
indexSelector = indexSelector ?? (s => s);
37-
var descriptor = indexSelector(new IndexDescriptor<T>().Object(@object));
37+
var descriptor = indexSelector(new IndexDescriptor<T>().Id(@object));
3838
return this.DispatchAsync<IndexDescriptor<T>, IndexRequestParameters, IndexResponse, IIndexResponse>(
3939
descriptor,
4040
(p, d) => this.RawDispatch.IndexDispatchAsync<IndexResponse>(p, @object));

src/Tests/Nest.Tests.Integration/Core/Bulk/BulkUpdateTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void BulkUpdateObject()
2626
{
2727
int id = i;
2828
descriptor.Update<ElasticsearchProject, object>(op => op
29-
.InferFrom(new ElasticsearchProject { Id = id })
29+
.Id(new ElasticsearchProject { Id = id })
3030
.PartialDocument(new { name = "SufixedName-" + id})
3131
);
3232
}

src/Tests/Nest.Tests.Integration/Core/DeleteTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void IndexThanDeleteDocumentByObject()
129129

130130
//act
131131
//now remove the item that was added
132-
this.Client.Delete<ElasticsearchProject>(f=>f.Object(newDocument).Refresh());
132+
this.Client.Delete<ElasticsearchProject>(f=>f.Id(newDocument).Refresh());
133133

134134
//assert
135135
//make sure getting by id returns nothing
@@ -165,7 +165,7 @@ public void IndexThenDeleteUsingRefresh()
165165

166166
//act
167167
//now remove the item that was added
168-
this.Client.Delete<ElasticsearchProject>(d=>d.Object(newDocument).Refresh());
168+
this.Client.Delete<ElasticsearchProject>(d=>d.Id(newDocument).Refresh());
169169

170170
//assert
171171
//make sure getting by id returns nothing

src/Tests/Nest.Tests.Integration/Core/Exists/DocumentExistsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public void TestSuggest()
2222

2323
indexResponse.IsValid.Should().BeTrue();
2424

25-
var existsResponse = this.Client.DocumentExists<ElasticsearchProject>(d => d.Object(elasticsearchProject).Index(tempIndex));
25+
var existsResponse = this.Client.DocumentExists<ElasticsearchProject>(d => d.Id(elasticsearchProject).Index(tempIndex));
2626
existsResponse.IsValid.Should().BeTrue();
2727
existsResponse.Exists.Should().BeTrue();
2828
existsResponse.ConnectionStatus.RequestMethod.Should().Be("HEAD");
2929

30-
var doesNotExistsResponse = this.Client.DocumentExists<ElasticsearchProject>(d => d.Object(elasticsearchProject).Index(tempIndex + "-random"));
30+
var doesNotExistsResponse = this.Client.DocumentExists<ElasticsearchProject>(d => d.Id(elasticsearchProject).Index(tempIndex + "-random"));
3131
doesNotExistsResponse.IsValid.Should().BeTrue();
3232
doesNotExistsResponse.Exists.Should().BeFalse();
3333

src/Tests/Nest.Tests.Integration/Core/UpdateTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void TestUpdate()
1616
Assert.Greater(project.LOC, 0);
1717
var loc = project.LOC;
1818
this.Client.Update<ElasticsearchProject>(u => u
19-
.Object(project)
19+
.Id(project)
2020
.Script("ctx._source.loc += 10")
2121
.RetryOnConflict(5)
2222
.Refresh()

src/Tests/Nest.Tests.Unit/BigBadUrlUnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void TestAllTheUrls()
110110
Do("PUT", "/mydefaultindex/doc/_mapping", c => c.Map<Doc>(m => m.MapFromAttributes()));
111111
Do("PUT", "/mycustomindex/doc/_mapping", c => c.Map<Doc>(m => m.Index("mycustomindex")));
112112
Do("PUT", "/mycustomindex/customtype/_mapping", c => c.Map<Doc>(m => m.Index("mycustomindex").Type("customtype")));
113-
Do("GET", "/mydefaultindex/doc/1/_mlt", c => c.MoreLikeThis<Doc>(m => m.Object(new Doc { Id = "1" })));
113+
Do("GET", "/mydefaultindex/doc/1/_mlt", c => c.MoreLikeThis<Doc>(m => m.Id(new Doc { Id = "1" })));
114114
Do("GET", "/mydefaultindex/doc/1/_mlt", c => c.MoreLikeThis<Doc>(m => m.Id(1)));
115115
Do("GET", "/mycustomindex/mycustomtype/1/_mlt", c => c.MoreLikeThis<Doc>(m => m.Id(1).Index("mycustomindex").Type("mycustomtype")));
116116
Do("POST", "/_msearch", c => c.MultiSearch(m => m.Search<Doc>(s => s.MatchAll())));

src/Tests/Nest.Tests.Unit/Core/Bulk/BulkTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void BulkOperations()
2424
.Document(new ElasticsearchProject { Id = 4 })
2525
.VersionType(VersionType.ExternalGte))
2626
.Update<ElasticsearchProject, object>(i => i
27-
.InferFrom(new ElasticsearchProject { Id = 3 })
27+
.Id(new ElasticsearchProject { Id = 3 })
2828
.VersionType(VersionType.External)
2929
.PartialDocument(new { name = "NEST"})
3030
)
@@ -68,7 +68,7 @@ public void BulkUpdateDetails()
6868
{
6969
var result = this._client.Bulk(b => b
7070
.Update<ElasticsearchProject, object>(i => i
71-
.InferFrom(new ElasticsearchProject { Id = 3 })
71+
.Id(new ElasticsearchProject { Id = 3 })
7272
.PartialDocument(new { name = "NEST" })
7373
.RetriesOnConflict(4)
7474
)

0 commit comments

Comments
 (0)