Skip to content

Commit de6f8cb

Browse files
committed
Can now specify Id on BulkParameters to override the id on the object that was passed
1 parent e0e3887 commit de6f8cb

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Nest/Domain/Parameters/BulkParameters.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class BulkParameters<T> where T : class
1414
{
1515
public VersionType VersionType { get; set; }
1616
public string Version { get; set; }
17+
public string Id { get; set; }
1718
public string Routing { get; set; }
1819
public string Parent { get; set; }
1920

src/Nest/ElasticClient-Bulk.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ private string GenerateBulkCommand<T>(IEnumerable<BulkParameters<T>> @objects, s
236236
continue;
237237

238238
var objectAction = action;
239-
240-
objectAction += ", \"_id\" : \"{0}\" ".F(this.Infer.Id(@object.Document));
239+
if (!@object.Id.IsNullOrEmpty())
240+
objectAction += ", \"_id\" : \"{0}\" ".F(@object.Id);
241+
else
242+
objectAction += ", \"_id\" : \"{0}\" ".F(this.Infer.Id(@object.Document));
241243

242244
if (!@object.Version.IsNullOrEmpty())
243245
objectAction += ", \"version\" : \"{0}\" ".F(@object.Version);

0 commit comments

Comments
 (0)