@@ -33,22 +33,40 @@ async function indicesRollover(params, options) {
3333 } else {
3434 aliasesToRollover . push ( alias ) ;
3535 }
36- // Is the given alias is a wildcard, search for other indicies starting with this alias
36+ /* Is the given alias is a wildcard (e.g. apigw-traffic-summary-*), search for other aliases starting with this alias
37+ * This the result we may get
38+ * alias index filter routing.index routing.search is_write_index
39+ * apigw-trace-messages-us apigw-trace-messages-us-000002 - - - true
40+ * apigw-trace-messages-us apigw-trace-messages-us-000001 - - - false
41+ * apigw-trace-messages-eu apigw-trace-messages-us-000001 - - - false
42+ * apigw-trace-messages-eu apigw-trace-messages-us-000002 - - - false
43+ * apigw-trace-messages-eu apigw-trace-messages-us-000003 - - - true
44+ *
45+ * For each found alias it must be rolled once, hence it must be the write index
46+ */
3747 if ( wildcardAlias ) {
3848 aliasesToRollover = [ ] ;
3949 logger . debug ( `Rolling over all indicies starting with alias: ${ alias } ` ) ;
40- var indicesFound = await client . indices . getAlias ( { name : `${ alias } *` } , { ignore : [ 404 ] , maxRetries : 3 } ) ;
41- for ( const index of Object . values ( indicesFound . body ) ) {
42- var indexAlias = Object . keys ( index . aliases ) [ 0 ] ;
43- aliasesToRollover . push ( indexAlias ) ;
44- }
50+ var foundAliases = await client . indices . getAlias ( { name : `${ alias } *` } , { ignore : [ 404 ] , maxRetries : 3 } ) ;
51+ // Based on the alias name we get all indicies
52+ for ( const [ key , value ] of Object . entries ( foundAliases . body ) ) {
53+ for ( const [ aliasName , aliasSettings ] of Object . entries ( value . aliases ) ) {
54+ // Each can have only one write index, which we use to perform the rollover
55+ if ( aliasSettings . is_write_index ) {
56+ logger . debug ( `Adding is write alias: ${ aliasName } to the list of aliases to rollover` ) ;
57+ aliasesToRollover . push ( aliasName ) ;
58+ break ;
59+ }
60+ }
61+ }
4562 }
4663 if ( aliasesToRollover . length == 0 ) {
4764 throw new Error ( `No index found to rollover for alias: ${ JSON . stringify ( alias ) } ` ) ;
4865 }
4966 try {
5067 var result = [ ] ;
5168 for ( alias of aliasesToRollover ) {
69+ logger . debug ( `Rolling over index: ${ alias } ` ) ;
5270 var rolloverResult = await client . indices . rollover ( { alias : alias } , { ignore : [ 404 ] , maxRetries : 3 } ) ;
5371 result . push ( rolloverResult ) ;
5472 }
0 commit comments