@@ -61,11 +61,16 @@ func migrate(ctx context.Context, bulker bulk.Bulk, fn migrationBodyFn) (int, er
6161 for {
6262 name , index , body , err := fn ()
6363 if err != nil {
64- return updatedDocs , fmt .Errorf (": %w" , err )
64+ return updatedDocs ,
65+ fmt .Errorf ("failed to prepare request for migration %s: %w" ,
66+ name , err )
6567 }
6668
6769 resp , err := applyMigration (ctx , name , index , bulker , body )
6870 if err != nil {
71+ log .Err (err ).
72+ Bytes ("http.request.body.content" , body ).
73+ Msgf ("migration %s failed: %w" , err )
6974 return updatedDocs , fmt .Errorf ("failed to apply migration %q: %w" ,
7075 name , err )
7176 }
@@ -239,7 +244,9 @@ map.put("id", ctx._source.default_api_key_id);
239244
240245// Make current API key empty, so fleet-server will generate a new one
241246// Add current API jey to be retired
242- ctx._source['` + fieldOutputs + `']['default'].to_retire_api_key_ids.add(map);
247+ if (ctx._source['` + fieldOutputs + `']['default'].to_retire_api_key_ids != null) {
248+ ctx._source['` + fieldOutputs + `']['default'].to_retire_api_key_ids.add(map);
249+ }
243250ctx._source['` + fieldOutputs + `']['default'].api_key="";
244251ctx._source['` + fieldOutputs + `']['default'].api_key_id="";
245252ctx._source['` + fieldOutputs + `']['default'].permissions_hash=ctx._source.policy_output_permissions_hash;
@@ -273,10 +280,13 @@ func migratePolicyCoordinatorIdx() (string, string, []byte, error) {
273280
274281 query := dsl .NewRoot ()
275282 query .Query ().MatchAll ()
276- query .Param ("script" , `ctx._source.coordinator_idx++;` )
283+ painless := `ctx._source.coordinator_idx++;`
284+ query .Param ("script" , painless )
277285
278286 body , err := query .MarshalJSON ()
279287 if err != nil {
288+ log .Debug ().Str ("painlessScript" , painless ).
289+ Msgf ("%s: failed painless script" , migrationName )
280290 return migrationName , FleetPolicies , nil , fmt .Errorf ("could not marshal ES query: %w" , err )
281291 }
282292
0 commit comments