def get_client(): """ Obtain the current Elasticsearch client. If undefined, an exception will be raised. This function also checks the integrity of the indices expected by this application and populate them when they cannot be found. """ if not _es_client: raise ImproperlyConfigured('The Elasticsearch client has not been set up yet. Please call setup() first.') create_indexes_if_needed(_es_client) # TODO: find a better place! return _es_client
def get_host(): """ Return one of the Elasticsearch hosts configured in our client. In the future this function could look it up in the Elasticsearch client instead of using the module attribute _es_hosts, because in an Elasticsearch cluster, nodes can be added or removed dynamically. """ if not _es_hosts: raise ImproperlyConfigured('The Elasticsearch client has not been set up yet, please call setup() first.') if isinstance(_es_hosts, (list, tuple)): return _es_hosts[0] return _es_hosts
def __init__(self, connection_alias, **connection_options): """ :param connection_alias: The connection name. Usually 'default' :param connection_options: The connection settings. """ super(ElasticsearchMultilingualSearchBackend, self).__init__( connection_alias, **connection_options) # self.index_name will be modified for each translation. self.index_base_name = self.index_name if not hasattr(django_settings, 'LANGUAGES'): raise ImproperlyConfigured("You must specify 'LANGUAGES' in your Django settings.") self.languages = [l[0] for l in django_settings.LANGUAGES] self._reset_existing_mapping() self.content_field_name = ''
from hashlib import sha224 as hash_class from json import dumps as serialize from amcat.tools import queryparser, toolkit from amcat.tools.toolkit import multidict, splitlist from elasticsearch import Elasticsearch, ImproperlyConfigured from elasticsearch.client import indices, cluster from elasticsearch.helpers import scan from django.conf import settings from amcat.tools.caching import cached from amcat.tools.progress import NullMonitor if settings.ES_USE_LEGACY_HASH_FUNCTION is None: error_msg = "Environment variable AMCAT_ES_LEGACY_HASH should be explicitely set." raise ImproperlyConfigured(error_msg) ARTICLE_FIELDS = frozenset({ "id", "date", "section", "pagenr", "headline", "byline", "length", "metastring", "url", "externalid", "author", "addressee", "uuid", "text", "parent_id", "medium_id", "medium__name" }) # These fields should be cleaned using _clean() ARTICLE_CLEAN_FIELDS = frozenset({ "section", "headline", "byline", "metastring", "addressee", "text", })