@@ -395,22 +395,18 @@ func (r *runner) getDocs(dataStream string) (*hits, error) {
395
395
r .options .API .Search .WithSize (elasticsearchQuerySize ),
396
396
r .options .API .Search .WithSource ("true" ),
397
397
r .options .API .Search .WithBody (strings .NewReader (allFieldsBody )),
398
+ r .options .API .Search .WithIgnoreUnavailable (true ),
398
399
)
399
400
if err != nil {
400
401
return nil , fmt .Errorf ("could not search data stream: %w" , err )
401
402
}
402
403
defer resp .Body .Close ()
403
404
404
- if resp .StatusCode == http .StatusNotFound {
405
- // No docs yet.
406
- return & hits {}, nil
407
- }
408
405
if resp .StatusCode == http .StatusServiceUnavailable && strings .Contains (resp .String (), "no_shard_available_action_exception" ) {
409
406
// Index is being created, but no shards are available yet.
410
407
// See https://github.com/elastic/elasticsearch/issues/65846
411
408
return & hits {}, nil
412
409
}
413
-
414
410
if resp .IsError () {
415
411
return nil , fmt .Errorf ("failed to search docs for data stream %s: %s" , dataStream , resp .String ())
416
412
}
@@ -1186,14 +1182,16 @@ func (r *runner) previewTransform(transformId string) ([]common.MapStr, error) {
1186
1182
1187
1183
func deleteDataStreamDocs (api * elasticsearch.API , dataStream string ) error {
1188
1184
body := strings .NewReader (`{ "query": { "match_all": {} } }` )
1189
- resp , err := api .DeleteByQuery ([]string {dataStream }, body )
1185
+ resp , err := api .DeleteByQuery ([]string {dataStream }, body ,
1186
+ // Unavailable index is ok, this means that data is already not there.
1187
+ r .options .ESAPI .DeleteByQuery .WithIgnoreUnavailable (true ),
1188
+ )
1190
1189
if err != nil {
1191
1190
return fmt .Errorf ("failed to delete data stream docs: %w" , err )
1192
1191
}
1193
1192
defer resp .Body .Close ()
1194
1193
1195
- // Not found error is fine here, this means that data was already not there.
1196
- if resp .IsError () && resp .StatusCode != http .StatusNotFound {
1194
+ if resp .IsError () {
1197
1195
return fmt .Errorf ("failed to delete data stream docs for data stream %s: %s" , dataStream , resp .String ())
1198
1196
}
1199
1197
0 commit comments