@@ -162,11 +162,8 @@ where
162
162
B : Serialize ,
163
163
{
164
164
/// Creates a new instance of a [bulk create operation](BulkCreateOperation)
165
- pub fn create < S > ( id : S , source : B ) -> BulkCreateOperation < B >
166
- where
167
- S : Into < String > ,
168
- {
169
- BulkCreateOperation :: new ( id, source)
165
+ pub fn create ( source : B ) -> BulkCreateOperation < B > {
166
+ BulkCreateOperation :: new ( source)
170
167
}
171
168
172
169
/// Creates a new instance of a [bulk index operation](BulkIndexOperation)
@@ -217,24 +214,30 @@ pub struct BulkCreateOperation<B> {
217
214
218
215
impl < B > BulkCreateOperation < B > {
219
216
/// Creates a new instance of [BulkCreateOperation]
220
- pub fn new < S > ( id : S , source : B ) -> Self
221
- where
222
- S : Into < String > ,
223
- {
217
+ pub fn new ( source : B ) -> Self {
224
218
Self {
225
219
operation : BulkOperation {
226
220
header : BulkHeader {
227
221
action : BulkAction :: Create ,
228
- metadata : BulkMetadata {
229
- _id : Some ( id. into ( ) ) ,
230
- ..Default :: default ( )
231
- } ,
222
+ metadata : BulkMetadata :: default ( ) ,
232
223
} ,
233
224
source : Some ( source) ,
234
225
} ,
235
226
}
236
227
}
237
228
229
+ /// Specify the id for the document
230
+ ///
231
+ /// If an id is not specified, Elasticsearch will generate an id for the document
232
+ /// which will be returned in the response.
233
+ pub fn id < S > ( mut self , id : S ) -> Self
234
+ where
235
+ S : Into < String > ,
236
+ {
237
+ self . operation . header . metadata . _id = Some ( id. into ( ) ) ;
238
+ self
239
+ }
240
+
238
241
/// Specify the name of the index to perform the bulk update operation against.
239
242
///
240
243
/// Each bulk operation can specify an index to operate against. If all bulk operations
@@ -697,7 +700,8 @@ mod tests {
697
700
. into ( ) ,
698
701
) ;
699
702
ops. push (
700
- BulkOperation :: create ( "2" , json ! ( { "bar" : "create" } ) )
703
+ BulkOperation :: create ( json ! ( { "bar" : "create" } ) )
704
+ . id ( "2" )
701
705
. pipeline ( "pipeline" )
702
706
. routing ( "routing" )
703
707
. index ( "create_index" )
@@ -779,7 +783,7 @@ mod tests {
779
783
. index ( "index_doc" )
780
784
. routing ( "routing" ) ,
781
785
) ?;
782
- ops. push ( BulkOperation :: create ( "2" , CreateDoc { bar : "create" } ) ) ?;
786
+ ops. push ( BulkOperation :: create ( CreateDoc { bar : "create" } ) . id ( "2" ) ) ?;
783
787
ops. push ( BulkOperation :: update ( "3" , UpdateDoc { baz : "update" } ) ) ?;
784
788
ops. push ( BulkOperation :: < ( ) > :: delete ( "4" ) ) ?;
785
789
0 commit comments