Skip to content

Commit b5cae7c

Browse files
committed
Renamed Id(T) to IdFrom(T), PartialDocument() to Doc() and PartialDocumentAsUpsert() to DocAsUpsert()
1 parent 8f5e5dd commit b5cae7c

File tree

16 files changed

+152
-79
lines changed

16 files changed

+152
-79
lines changed

src/Nest/DSL/Bulk/BulkUpdateDescriptor.cs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public interface IBulkUpdateOperation<TDocument, TPartialDocument> : IBulkOperat
1313

1414
TDocument Upsert { get; set; }
1515

16-
TPartialDocument PartialDocument { get; set; }
16+
TPartialDocument Doc { get; set; }
1717

18-
bool? PartialDocumentAsUpsert { get; set; }
18+
bool? DocAsUpsert { get; set; }
1919

2020
string Lang { get; set; }
2121

@@ -29,15 +29,34 @@ public class BulkUpdateOperation<TDocument, TPartialDocument> : BulkOperationBas
2929
where TPartialDocument : class
3030
{
3131

32-
public BulkUpdateOperation(TDocument inferFrom)
32+
33+
public BulkUpdateOperation(string id) { this.Id = id; }
34+
public BulkUpdateOperation(long id) : this(id.ToString(CultureInfo.InvariantCulture)) {}
35+
36+
/// <summary>
37+
/// Create a new bulk operation
38+
/// </summary>
39+
/// <param name="idFrom">Use this document to infer the id from</param>
40+
/// <param name="useIdFromAsUpsert">Use the document to infer on as the upsert document in this update operation</param>
41+
public BulkUpdateOperation(TDocument idFrom, bool useIdFromAsUpsert = false)
3342
{
34-
this.InferFrom = inferFrom;
43+
this.InferFrom = idFrom;
44+
if (useIdFromAsUpsert)
45+
this.Upsert = idFrom;
3546
}
3647

37-
public BulkUpdateOperation(TDocument inferFrom, TPartialDocument update)
48+
/// <summary>
49+
/// Create a new Bulk Operation
50+
/// </summary>
51+
/// <param name="idFrom">Use this document to infer the id from</param>
52+
/// <param name="update">The partial update document (doc) to send as update</param>
53+
/// <param name="useIdFromAsUpsert">Use the document to infer on as the upsert document in this update operation</param>
54+
public BulkUpdateOperation(TDocument idFrom, TPartialDocument update, bool useIdFromAsUpsert = false)
3855
{
39-
this.InferFrom = inferFrom;
40-
this.PartialDocument = update;
56+
this.InferFrom = idFrom;
57+
if (useIdFromAsUpsert)
58+
this.Upsert = idFrom;
59+
this.Doc = update;
4160
}
4261

4362

@@ -54,19 +73,19 @@ public override object GetBody()
5473
{
5574
return new BulkUpdateBody<TDocument, TPartialDocument>
5675
{
57-
_PartialUpdate = this.PartialDocument,
76+
_PartialUpdate = this.Doc,
5877
_Script = this.Script,
5978
_Lang = this.Lang,
6079
_Params = this.Params,
6180
_Upsert = this.Upsert,
62-
_DocAsUpsert = this.PartialDocumentAsUpsert
81+
_DocAsUpsert = this.DocAsUpsert
6382
};
6483
}
6584

6685
public TDocument InferFrom { get; set; }
6786
public TDocument Upsert { get; set; }
68-
public TPartialDocument PartialDocument { get; set; }
69-
public bool? PartialDocumentAsUpsert { get; set; }
87+
public TPartialDocument Doc { get; set; }
88+
public bool? DocAsUpsert { get; set; }
7089
public string Lang { get; set; }
7190
public string Script { get; set; }
7291
public Dictionary<string, object> Params { get; set; }
@@ -85,9 +104,9 @@ public class BulkUpdateDescriptor<TDocument, TPartialDocument> : BulkOperationDe
85104

86105
TDocument IBulkUpdateOperation<TDocument, TPartialDocument>.Upsert { get; set; }
87106

88-
TPartialDocument IBulkUpdateOperation<TDocument, TPartialDocument>.PartialDocument { get; set; }
107+
TPartialDocument IBulkUpdateOperation<TDocument, TPartialDocument>.Doc { get; set; }
89108

90-
bool? IBulkUpdateOperation<TDocument, TPartialDocument>.PartialDocumentAsUpsert { get; set; }
109+
bool? IBulkUpdateOperation<TDocument, TPartialDocument>.DocAsUpsert { get; set; }
91110

92111
string IBulkUpdateOperation<TDocument, TPartialDocument>.Lang { get; set; }
93112

@@ -99,12 +118,12 @@ protected override object GetBulkOperationBody()
99118
{
100119
return new BulkUpdateBody<TDocument, TPartialDocument>
101120
{
102-
_PartialUpdate = Self.PartialDocument,
121+
_PartialUpdate = Self.Doc,
103122
_Script = Self.Script,
104123
_Lang = Self.Lang,
105124
_Params = Self.Params,
106125
_Upsert = Self.Upsert,
107-
_DocAsUpsert = Self.PartialDocumentAsUpsert
126+
_DocAsUpsert = Self.DocAsUpsert
108127
};
109128
}
110129

@@ -164,7 +183,7 @@ public BulkUpdateDescriptor<TDocument, TPartialDocument> Id(string id)
164183
/// The object to update, if id is not manually set it will be inferred from the object.
165184
/// Used ONLY to infer the ID see Document() to apply a partial object merge.
166185
/// </summary>
167-
public BulkUpdateDescriptor<TDocument, TPartialDocument> Id(TDocument @object, bool useAsUpsert = false)
186+
public BulkUpdateDescriptor<TDocument, TPartialDocument> IdFrom(TDocument @object, bool useAsUpsert = false)
168187
{
169188
Self.InferFrom = @object;
170189
if (useAsUpsert) return this.Upsert(@object);
@@ -181,15 +200,15 @@ public BulkUpdateDescriptor<TDocument, TPartialDocument> Upsert(TDocument @objec
181200
/// <summary>
182201
/// The partial update document to be merged on to the existing object.
183202
/// </summary>
184-
public BulkUpdateDescriptor<TDocument, TPartialDocument> PartialDocument(TPartialDocument @object)
203+
public BulkUpdateDescriptor<TDocument, TPartialDocument> Doc(TPartialDocument @object)
185204
{
186-
Self.PartialDocument = @object;
205+
Self.Doc = @object;
187206
return this;
188207
}
189208

190-
public BulkUpdateDescriptor<TDocument, TPartialDocument> PartialDocumentAsUpsert(bool partialDocumentAsUpsert = true)
209+
public BulkUpdateDescriptor<TDocument, TPartialDocument> DocAsUpsert(bool partialDocumentAsUpsert = true)
191210
{
192-
Self.PartialDocumentAsUpsert = partialDocumentAsUpsert;
211+
Self.DocAsUpsert = partialDocumentAsUpsert;
193212
return this;
194213
}
195214

src/Nest/DSL/Paths/DocumentOptionalPathDescriptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public abstract class DocumentOptionalPathBase<TParameters, T> : BasePathRequest
8787

8888
public DocumentOptionalPathBase(string id) { this.Id = id; }
8989
public DocumentOptionalPathBase(long id) : this(id.ToString(CultureInfo.InvariantCulture)) {}
90-
public DocumentOptionalPathBase(T document) { this.IdFrom = document; }
90+
public DocumentOptionalPathBase(T idFrom) { this.IdFrom = idFrom; }
9191

9292
protected override void SetRouteParameters(IConnectionSettingsValues settings, ElasticsearchPathInfo<TParameters> pathInfo)
9393
{
@@ -159,7 +159,7 @@ public TDescriptor Id(string id)
159159
Self.Id = id;
160160
return (TDescriptor)this;
161161
}
162-
public TDescriptor Id(T @object)
162+
public TDescriptor IdFrom(T @object)
163163
{
164164
Self.IdFrom = @object;
165165
return (TDescriptor)this;

src/Nest/DSL/UpdateDescriptor.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public interface IUpdateRequest<TDocument, TPartialDocument> : IDocumentOptional
2626
TDocument Upsert { get; set; }
2727

2828
[JsonProperty(PropertyName = "doc_as_upsert")]
29-
bool? PartialDocumentAsUpsert { get; set; }
29+
bool? DocAsUpsert { get; set; }
3030

3131
[JsonProperty(PropertyName = "doc")]
32-
TPartialDocument PartialDocument { get; set; }
32+
TPartialDocument Doc { get; set; }
3333
}
3434

3535
public class UpdateRequest<TDocument> : UpdateRequest<TDocument, TDocument>
@@ -53,10 +53,10 @@ public UpdateRequest(string id) : base(id) { }
5353

5454
public UpdateRequest(long id) : base(id) { }
5555

56-
public UpdateRequest(TDocument document, bool useAsUpsert = false) : base(document)
56+
public UpdateRequest(TDocument idFrom, bool useAsUpsert = false) : base(idFrom)
5757
{
5858
if (useAsUpsert)
59-
this.Upsert = document;
59+
this.Upsert = idFrom;
6060
}
6161

6262
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<UpdateRequestParameters> pathInfo)
@@ -69,8 +69,8 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
6969
public string Language { get; set; }
7070
public Dictionary<string, object> Params { get; set; }
7171
public TDocument Upsert { get; set; }
72-
public bool? PartialDocumentAsUpsert { get; set; }
73-
public TPartialDocument PartialDocument { get; set; }
72+
public bool? DocAsUpsert { get; set; }
73+
public TPartialDocument Doc { get; set; }
7474
}
7575

7676

@@ -81,8 +81,6 @@ public partial class UpdateDescriptor<TDocument,TPartialDocument>
8181
where TPartialDocument : class
8282
{
8383

84-
private TDocument _inferFrom { get; set; }
85-
8684
private IUpdateRequest<TDocument, TPartialDocument> Self { get { return this; } }
8785

8886
string IUpdateRequest<TDocument, TPartialDocument>.Script { get; set; }
@@ -93,9 +91,9 @@ public partial class UpdateDescriptor<TDocument,TPartialDocument>
9391

9492
TDocument IUpdateRequest<TDocument, TPartialDocument>.Upsert { get; set; }
9593

96-
bool? IUpdateRequest<TDocument, TPartialDocument>.PartialDocumentAsUpsert { get; set; }
94+
bool? IUpdateRequest<TDocument, TPartialDocument>.DocAsUpsert { get; set; }
9795

98-
TPartialDocument IUpdateRequest<TDocument, TPartialDocument>.PartialDocument { get; set; }
96+
TPartialDocument IUpdateRequest<TDocument, TPartialDocument>.Doc { get; set; }
9997

10098

10199
public UpdateDescriptor<TDocument, TPartialDocument> Script(string script)
@@ -134,15 +132,15 @@ public UpdateDescriptor<TDocument, TPartialDocument> Upsert(TDocument upsertObje
134132
/// <summary>
135133
/// The partial update document to be merged on to the existing object.
136134
/// </summary>
137-
public UpdateDescriptor<TDocument, TPartialDocument> PartialDocument(TPartialDocument @object)
135+
public UpdateDescriptor<TDocument, TPartialDocument> Doc(TPartialDocument @object)
138136
{
139-
Self.PartialDocument = @object;
137+
Self.Doc = @object;
140138
return this;
141139
}
142140

143-
public UpdateDescriptor<TDocument, TPartialDocument> PartialDocumentAsUpsert(bool docAsUpsert = true)
141+
public UpdateDescriptor<TDocument, TPartialDocument> DocAsUpsert(bool docAsUpsert = true)
144142
{
145-
Self.PartialDocumentAsUpsert = docAsUpsert;
143+
Self.DocAsUpsert = docAsUpsert;
146144
return this;
147145
}
148146

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>().Id(@object));
16+
var descriptor = indexSelector(new IndexDescriptor<T>().IdFrom(@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>().Id(@object));
37+
var descriptor = indexSelector(new IndexDescriptor<T>().IdFrom(@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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public void BulkUpdateObject()
2626
{
2727
int id = i;
2828
descriptor.Update<ElasticsearchProject, object>(op => op
29-
.Id(new ElasticsearchProject { Id = id })
30-
.PartialDocument(new { name = "SufixedName-" + id})
29+
.IdFrom(new ElasticsearchProject { Id = id })
30+
.Doc(new { name = "SufixedName-" + id})
3131
);
3232
}
3333

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.Id(newDocument).Refresh());
132+
this.Client.Delete<ElasticsearchProject>(f=>f.IdFrom(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.Id(newDocument).Refresh());
168+
this.Client.Delete<ElasticsearchProject>(d=>d.IdFrom(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.Id(elasticsearchProject).Index(tempIndex));
25+
var existsResponse = this.Client.DocumentExists<ElasticsearchProject>(d => d.IdFrom(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.Id(elasticsearchProject).Index(tempIndex + "-random"));
30+
var doesNotExistsResponse = this.Client.DocumentExists<ElasticsearchProject>(d => d.IdFrom(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: 3 additions & 3 deletions
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-
.Id(project)
19+
.IdFrom(project)
2020
.Script("ctx._source.loc += 10")
2121
.RetryOnConflict(5)
2222
.Refresh()
@@ -61,12 +61,12 @@ public void DocAsUpsert()
6161
var loc = project.LOC;
6262
this.Client.Update<ElasticsearchProject, ElasticsearchProjectLocUpdate>(u => u
6363
.Id(1)
64-
.PartialDocument(new ElasticsearchProjectLocUpdate
64+
.Doc(new ElasticsearchProjectLocUpdate
6565
{
6666
Id = project.Id,
6767
LOC = project.LOC + 10
6868
})
69-
.PartialDocumentAsUpsert()
69+
.DocAsUpsert()
7070
.Refresh()
7171
);
7272
project = this.Client.Source<ElasticsearchProject>(s => s.Id(1));

src/Tests/Nest.Tests.Integration/Reproduce/Reproduce732Tests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void UpdateUsingDynamicObject()
3232
var loc = project.LOC;
3333
this.Client.Update<ElasticsearchProject, dynamic>(u => u
3434
.Id(id)
35-
.PartialDocument(new
35+
.Doc(new
3636
{
3737
Id = project.Id,
3838
LOC = project.LOC + 10
@@ -89,7 +89,7 @@ public bool UpdateViaBulk(dynamic partial)
8989
IBulkResponse response = Client.Bulk(b => b
9090
.Update<Load, dynamic>(u => u
9191
.Id(partial.Id)
92-
.PartialDocument(partial)
92+
.Doc(partial)
9393
));
9494

9595
return response.IsValid;
@@ -98,7 +98,7 @@ public bool UpdateLoad(dynamic partial)
9898
{
9999
IUpdateResponse response = Client.Update<Load, dynamic>(u => u
100100
.Id((int)partial.Id)
101-
.PartialDocument((object)partial)
101+
.Doc((object)partial)
102102
);
103103
return response.IsValid;
104104
}

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

Lines changed: 3 additions & 3 deletions
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.Id(new Doc { Id = "1" })));
113+
Do("GET", "/mydefaultindex/doc/1/_mlt", c => c.MoreLikeThis<Doc>(m => m.IdFrom(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())));
@@ -150,8 +150,8 @@ public void TestAllTheUrls()
150150
Do("GET", "/mydefaultindex/_status", c => c.Status(s => s.Index<Doc>()));
151151
Do("DELETE", "/mydefaultindex/.percolator/mypercolator", c => c.UnregisterPercolator<ElasticsearchProject>("mypercolator"));
152152
Do("DELETE", "/mycustomindex/.percolator/mypercolator", c => c.UnregisterPercolator<ElasticsearchProject>("mypercolator", r => r.Index("mycustomindex")));
153-
Do("POST", "/mydefaultindex/doc/1/_update", c => c.Update<Doc, OtherDoc>(u => u.Id(1).PartialDocument(new OtherDoc { Name = "asd" })));
154-
Do("POST", "/mydefaultindex/customtype/1/_update", c => c.Update<Doc, OtherDoc>(u => u.Id(1).Type("customtype").PartialDocument(new OtherDoc { Name = "asd" })));
153+
Do("POST", "/mydefaultindex/doc/1/_update", c => c.Update<Doc, OtherDoc>(u => u.Id(1).Doc(new OtherDoc { Name = "asd" })));
154+
Do("POST", "/mydefaultindex/customtype/1/_update", c => c.Update<Doc, OtherDoc>(u => u.Id(1).Type("customtype").Doc(new OtherDoc { Name = "asd" })));
155155
Do("PUT", "/mydefaultindex/_settings", c => c.UpdateSettings(u => u.AutoExpandReplicas(false)));
156156
Do("PUT", "/mycustomindex/_settings", c => c.UpdateSettings(u => u.Index("mycustomindex").AutoExpandReplicas(false)));
157157
Do("POST", "/_all/doc/_validate/query", c => c.Validate<Doc>(v => v.AllIndices()));

0 commit comments

Comments
 (0)