grails / elasticsearch-grails-plugin

The Elasticsearch Grails plugin
https://grails-plugins.github.io/elasticsearch-grails-plugin/
Other
15 stars 23 forks source link

Deletion of old aliases during new index creation #158

Closed purpleraven closed 2 years ago

purpleraven commented 2 years ago

Expected Behavior

with default migration.strategy: alias new index will be created during migration and new alias will point on it. But old alias not removed and in ES will be few indexes with same aliases.

in the code of ElasticSearchAdminService missed the delete logic execution. But all preparation done:

void pointAliasTo(String alias, String index, Integer version = null) {
        index = versionIndex(index, version)
        LOG.debug "Creating alias ${alias}, pointing to index ${index} ..."
        String oldIndex = indexPointedBy(alias)
        elasticSearchHelper.withElasticSearch { RestHighLevelClient client ->
            if (oldIndex && oldIndex != index) {
                LOG.debug "Index used to point to ${oldIndex}, removing ..."
                new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.REMOVE)
                        .index(oldIndex)
                        .alias(alias)
            }
            IndicesAliasesRequest request = new IndicesAliasesRequest()
            IndicesAliasesRequest.AliasActions aliasAction =
                    new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.ADD)
                            .index(index)
                            .alias(alias)
            request.addAliasAction(aliasAction)
            LOG.debug "Create alias -> index: ${index}; alias: ${alias}"
            client.indices().updateAliases(request, RequestOptions.DEFAULT)
        }
    }

AliasActions created but not executed. Is a mistake of expected behaviour? In case of mistake I can provide a PR with a fix

Actual Behaviour

No response

Steps To Reproduce

No response

Environment Information

Version of plugin 3.0.0-snapshot

Example Application

No response

Version

4