@staticmethod
    def _add_append_script():

        # get elasticsearch base dir and resolve script file destination
        es_path = os.path.dirname(
            os.path.dirname(
                subprocess.check_output('which elasticsearch',
                                        shell=True).rstrip('\r\n')))
        es_scripts_path = os.path.join(es_path, 'config/scripts')
        script_path = os.path.join(es_scripts_path, 'append.groovy')

        if os.path.exists(script_path):
            return

        use_sudo = os.environ.get('CI') == 'true'
        script = ('if (ctx._source.containsKey(key))'
                  ' {ctx._source[key] += value;}'
                  ' else {ctx._source[key] = [value]}').replace('"', r'\"')

        if not os.path.exists(es_scripts_path):
            os.system('{0} mkdir -p {1}'.format(
                'sudo' if use_sudo else '',
                es_scripts_path))

        os.system('echo "{0}" | {1} tee {2}'.format(
            script,
            'sudo' if use_sudo else '',
            script_path
        ))
write the 'append to list' ES script to a file and store it at
dataset/ETHPy150Open cloudify-cosmo/cloudify-manager/tests/testenv/processes/elastic.py/ElasticSearchProcess._add_append_script