<commit_before>from elasticsearch import Elasticsearch
import json
import os

SETTINGS_FILE = os.path.join(os.path.dirname(__file__), 'index_settings.json')

with open(SETTINGS_FILE) as json_file:
    settings = json.load(json_file)


def get_elasticsearch(request):
    elastichost = \
        request.registry.settings.get('elastic.servers', 'localhost:9200')
    return Elasticsearch(hosts=elastichost, timeout=60)


def get_index(request):
    return request.registry.settings.get('elastic.index', 'index')


def ensure_index(client, index, recreate=False):
    exists = client.indices.exists(index)
    if recreate or not exists:
        if exists:
            client.indices.delete(index)
        client.indices.create(index, body=settings)<commit_msg>fix: use env variable for ES config<commit_after>from elasticsearch import Elasticsearch
import json
import os

SETTINGS_FILE = os.path.join(os.path.dirname(__file__), 'index_settings.json')

with open(SETTINGS_FILE) as json_file:
    settings = json.load(json_file)


def get_elasticsearch(request):
    elastichost = os.environ['ELASTIC_SERVERS'] if 'ELASTIC_SERVERS' in os.environ else 'localhost:9200'
    return Elasticsearch(hosts=elastichost, timeout=60)


def get_index(request):
    return os.environ['ELASTIC_INDEX'] if 'ELASTIC_INDEX' in os.environ else 'index'


def ensure_index(client, index, recreate=False):
    exists = client.indices.exists(index)
    if recreate or not exists:
        if exists:
            client.indices.delete(index)
        client.indices.create(index, body=settings)
{'fraction_non_alphanumeric': 0.10344827586206896, 'fraction_numerical': 0.007662835249042145, 'mean_word_length': 4.576512455516014, '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': '2550422', 'n_tokens_mistral': 492, 'n_tokens_neox': 485, 'n_words': 107}