<commit_before>from pyshelf.search.metadata import Metadata
import yaml
import os
from pyshelf.search.connection import Connection


class ElasticInitializer(object):
    def __init__(self, config_path):
        self.config_path = config_path

    def initialize(self):
        config = self.read_config()
        connection = Connection(config["connectionString"],
                config.get("accessKey"), config.get("secretKey"), config.get("region"))
        connection.indices.create(index=connection.es_index, ignore=400)
        Metadata.init(using=connection, index=connection.es_index)
        connection.indices.refresh(index=connection.es_index)

    def read_config(self):
        with open(self.config_path) as cf:
            config = yaml.load(cf.read())

            return config.get("elasticsearch")

bin_dir = os.path.dirname(os.path.realpath(__file__))
config_path = os.path.realpath(os.path.join(bin_dir, "../config.yaml"))
elastic = ElasticInitializer(config_path)
elastic.initialize()
<commit_msg>Check if index exists if not I init metadata map.<commit_after>from pyshelf.search.metadata import Metadata
import yaml
import os
from pyshelf.search.connection import Connection


class ElasticInitializer(object):
    def __init__(self, config_path):
        self.config_path = config_path

    def initialize(self):
        config = self.read_config()
        connection = Connection(config["connectionString"],
                                config.get("accessKey"),
                                config.get("secretKey"),
                                config.get("region"))

        index_exists = connection.indices.exists(index=connection.es_index)

        if not index_exists:
            Metadata.init(using=connection, index=connection.es_index)

        connection.indices.refresh(index=connection.es_index)

    def read_config(self):
        with open(self.config_path) as cf:
            config = yaml.load(cf.read())

            return config.get("elasticsearch")

bin_dir = os.path.dirname(os.path.realpath(__file__))
config_path = os.path.realpath(os.path.join(bin_dir, "../config.yaml"))
elastic = ElasticInitializer(config_path)
elastic.initialize()

{'fraction_non_alphanumeric': 0.10898312813497492, 'fraction_numerical': 0.0013679890560875513, 'mean_word_length': 3.203065134099617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2840110', 'n_tokens_mistral': 624, 'n_tokens_neox': 594, 'n_words': 114}