@@ -71,6 +71,7 @@ export interface IndexParams {
7171 index : string ;
7272 body : Annotation ;
7373 refresh : boolean | 'wait_for' | undefined ;
74+ require_alias ?: boolean ;
7475 id ?: string ;
7576}
7677
@@ -99,6 +100,7 @@ export function annotationProvider({ asInternalUser }: IScopedClusterClient) {
99100 index : ML_ANNOTATIONS_INDEX_ALIAS_WRITE ,
100101 body : annotation ,
101102 refresh : 'wait_for' ,
103+ require_alias : true ,
102104 } ;
103105
104106 if ( typeof annotation . _id !== 'undefined' ) {
@@ -407,14 +409,37 @@ export function annotationProvider({ asInternalUser }: IScopedClusterClient) {
407409 }
408410
409411 async function deleteAnnotation ( id : string ) {
410- const params : DeleteParams = {
411- index : ML_ANNOTATIONS_INDEX_ALIAS_WRITE ,
412+ // Find the index the annotation is stored in.
413+ const searchParams : estypes . SearchRequest = {
414+ index : ML_ANNOTATIONS_INDEX_ALIAS_READ ,
415+ size : 1 ,
416+ body : {
417+ query : {
418+ ids : {
419+ values : [ id ] ,
420+ } ,
421+ } ,
422+ } ,
423+ } ;
424+
425+ const { body } = await asInternalUser . search ( searchParams ) ;
426+ const totalCount =
427+ typeof body . hits . total === 'number' ? body . hits . total : body . hits . total . value ;
428+
429+ if ( totalCount === 0 ) {
430+ throw Boom . notFound ( `Cannot find annotation with ID ${ id } ` ) ;
431+ }
432+
433+ const index = body . hits . hits [ 0 ] . _index ;
434+
435+ const deleteParams : DeleteParams = {
436+ index,
412437 id,
413438 refresh : 'wait_for' ,
414439 } ;
415440
416- const { body } = await asInternalUser . delete ( params ) ;
417- return body ;
441+ const { body : deleteResponse } = await asInternalUser . delete ( deleteParams ) ;
442+ return deleteResponse ;
418443 }
419444
420445 return {
0 commit comments