From 73826f927199236a838ff537d14e570e70601ad5 Mon Sep 17 00:00:00 2001 From: bastien Date: Thu, 6 Jun 2019 16:47:32 +0200 Subject: [PATCH] Be a little bit verbose (#1524) change orders actions to avoid downtime and add some usefull informations --- doc/cookbook/aliased-indexes.md | 68 +++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/doc/cookbook/aliased-indexes.md b/doc/cookbook/aliased-indexes.md index f972ee6a2..bb545602e 100644 --- a/doc/cookbook/aliased-indexes.md +++ b/doc/cookbook/aliased-indexes.md @@ -18,20 +18,48 @@ fos_elastica: ``` The process for setting up aliases on an existing application is slightly more complicated -because the bundle is not able to set an alias as the same name as an index. You have some +because the bundle is not able to set an alias as the same name as an index. You have 2 options on how to handle this: -1) Delete the index from Elasticsearch. This option will make searching unavailable in your +1) Option with downtime : Delete the index from Elasticsearch. This option will make searching unavailable in your application until a population has completed itself, and an alias is created. ```bash $ curl -XDELETE 'http://localhost:9200/app/' ``` -2) Change the index_name parameter for your index to something new, and manually alias the +2) Option without downtime : Change the index_name parameter for your index to something new, and manually alias the current index to the new index_name, which will then be replaced when you run a repopulate. +```bash +# before actions +curl -XGET 'http://localhost:9200/_alias/?pretty' +{ + "app" : { + "aliases" : { } + } +} + +# create alias to switch after with no downtime +$ curl -XPOST 'http://localhost:9200/_aliases' -H 'Content-Type: application/json' -d ' +{ + "actions" : [ + { "add" : { "index" : "app", "alias" : "app_prod" } } + ] +}' + +#check alias is ok +curl -XGET 'http://localhost:9200/_alias/?pretty' +{ + "app" : { + "aliases" : { "app_prod" : { } } + } +} + +``` + ```yaml +#index name is alias name fos_elastica: indexes: app: @@ -39,11 +67,35 @@ fos_elastica: index_name: app_prod ``` +clear caches etc, now fos use alias instead of index ```bash -$ curl -XPOST 'http://localhost:9200/_aliases' -H 'Content-Type: application/json' -d ' +bin/console -eprod 'fos:elastica:populate' +``` +in other cli in // check indexes during populate process +```bash +curl -XGET 'http://localhost:9200/_alias/?pretty' { - "actions" : [ - { "add" : { "index" : "app", "alias" : "app_prod" } } - ] -}' + "app" : { + "aliases" : { + "app_prod" : { } + } + }, + "app_prod_2019-05-28-153852" : { + "aliases" : { } + } +} + +``` +when 'fos:elastica:populate' command finish + +```bash +curl -XGET 'http://localhost:9200/_alias/?pretty' +{ + "app_prod_2019-05-28-153852" : { + "aliases" : { + "app_prod" : { } + } + } +} + ```