File tree Expand file tree Collapse file tree 3 files changed +67
-2
lines changed Expand file tree Collapse file tree 3 files changed +67
-2
lines changed Original file line number Diff line number Diff line change @@ -705,11 +705,11 @@ class Helpers {
705
705
}
706
706
const retry = [ ]
707
707
const { items } = body
708
+ let indexSlice = 0
708
709
for ( let i = 0 , len = items . length ; i < len ; i ++ ) {
709
710
const action = items [ i ]
710
711
const operation = Object . keys ( action ) [ 0 ]
711
712
const { status } = action [ operation ]
712
- const indexSlice = operation !== 'delete' ? i * 2 : i
713
713
714
714
if ( status >= 400 ) {
715
715
// 429 is the only staus code where we might want to retry
@@ -736,6 +736,7 @@ class Helpers {
736
736
} else {
737
737
stats . successful += 1
738
738
}
739
+ operation === 'delete' ? indexSlice += 1 : indexSlice += 2
739
740
}
740
741
callback ( null , retry )
741
742
} )
Original file line number Diff line number Diff line change 12
12
},
13
13
"homepage" : " http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html" ,
14
14
"version" : " 7.17.11" ,
15
- "versionCanary" : " 7.17.11-canary.0 " ,
15
+ "versionCanary" : " 7.17.11-canary.1 " ,
16
16
"keywords" : [
17
17
" elasticsearch" ,
18
18
" elastic" ,
Original file line number Diff line number Diff line change @@ -1082,6 +1082,70 @@ test('bulk delete', t => {
1082
1082
server . stop ( )
1083
1083
} )
1084
1084
1085
+ t . test ( 'Should call onDrop on the correct document when doing a mix of operations that includes deletes' , async t => {
1086
+ // checks to ensure onDrop doesn't provide the wrong document when some operations are deletes
1087
+ // see https://github.com/elastic/elasticsearch-js/issues/1751
1088
+ async function handler ( req , res ) {
1089
+ res . setHeader ( 'content-type' , 'application/json' )
1090
+ res . end ( JSON . stringify ( {
1091
+ took : 0 ,
1092
+ errors : true ,
1093
+ items : [
1094
+ { delete : { status : 200 } } ,
1095
+ { index : { status : 429 } } ,
1096
+ { index : { status : 200 } }
1097
+ ]
1098
+ } ) )
1099
+ }
1100
+
1101
+ const [ { port } , server ] = await buildServer ( handler )
1102
+ const client = new Client ( { node : `http://localhost:${ port } ` } )
1103
+ let counter = 0
1104
+ const result = await client . helpers . bulk ( {
1105
+ datasource : dataset . slice ( ) ,
1106
+ concurrency : 1 ,
1107
+ wait : 10 ,
1108
+ retries : 0 ,
1109
+ onDocument ( doc ) {
1110
+ counter ++
1111
+ if ( counter === 1 ) {
1112
+ return {
1113
+ delete : {
1114
+ _index : 'test' ,
1115
+ _id : String ( counter )
1116
+ }
1117
+ }
1118
+ } else {
1119
+ return {
1120
+ index : {
1121
+ _index : 'test'
1122
+ }
1123
+ }
1124
+ }
1125
+ } ,
1126
+ onDrop ( doc ) {
1127
+ t . same ( doc , {
1128
+ status : 429 ,
1129
+ error : null ,
1130
+ operation : { index : { _index : 'test' } } ,
1131
+ document : { user : 'arya' , age : 18 } ,
1132
+ retried : false
1133
+ } )
1134
+ }
1135
+ } )
1136
+
1137
+ t . type ( result . time , 'number' )
1138
+ t . type ( result . bytes , 'number' )
1139
+ t . match ( result , {
1140
+ total : 3 ,
1141
+ successful : 2 ,
1142
+ retry : 0 ,
1143
+ failed : 1 ,
1144
+ aborted : false
1145
+ } )
1146
+ server . stop ( )
1147
+ } )
1148
+
1085
1149
t . end ( )
1086
1150
} )
1087
1151
You can’t perform that action at this time.
0 commit comments