Search code examples
rubyyamlsymfonyfoselasticabundle

Use YAML variables to name keys


I need to use a YAML variable to name a YAML key. I've tried this, but yaml validator complains that its not valid YAML

#Elastic search configuration
variable_key: &variable_key_name vodacom_salimdev_local
fos_elastica:
   clients:
       default:
           host: %fos_elastica_host%
           port: %fos_elastica_port%
           logger: false
           headers: { Authorization: some_security_token }
   indexes:
       *variable_key_name:
           client: default
           settings:
                index:
                 analysis:
                   analyzer:
                     custom_analyzer :
                       type     :    custom

The reason i want a variable name for a key is because, i'll be reading the key from a different file. How do i name my index names using variables ?


Solution

  • Yes you can:

    #Elastic search configuration
    variable_key: &variable_key_name vodacom_salimdev_local
    fos_elastica:
       clients:
           default:
               host: %fos_elastica_host%
               port: %fos_elastica_port%
               logger: false
               headers: { Authorization: some_security_token }
       indexes:
           %index1%:
               client: default
               settings:
                    index:
                     analysis:
                       analyzer:
                         custom_analyzer :
                           type     :    custom
    

    Where the index1 var is defined in your parameters.yml or config.yml files. (or any parameters section of your loaded YAML files)

    parameters:
        index1: my_main_app_es_index_name