Exemple #1
0
    def __init__(self, connection_alias, **connection_options):
        super(ElasticsearchSearchBackend, self).__init__(connection_alias, **connection_options)

        # Update DEFAULT_SETTINGS with custom settings
        self.DEFAULT_SETTINGS.update(**merge_dict(self.DEFAULT_SETTINGS, es_settings.INDEX_SETTINGS))

        # Update FIELD_MAPPINGS with custom field mappings
        FIELD_MAPPINGS.update(**merge_dict(FIELD_MAPPINGS, es_settings.FIELD_MAPPINGS))
try:
    import elasticsearch
    if not ((5, 0, 0) <= elasticsearch.__version__ < (6, 0, 0)):
        raise ImportError
    from elasticsearch.helpers import bulk, scan
except ImportError:
    raise MissingDependency("The 'elasticsearch5' backend requires the \
                            installation of 'elasticsearch>=5.0.0,<6.0.0'. \
                            Please refer to the documentation.")

DEFAULT_FIELD_MAPPING = {'type': 'text', 'analyzer': 'snowball'}
FIELD_MAPPINGS.update({
    'text': {
        'type': 'text',
        'analyzer': 'snowball'
    },
    'keyword': {
        'type': 'keyword'
    }
})


class Elasticsearch5SearchBackend(ElasticsearchSearchBackend):
    def __init__(self, connection_alias, **connection_options):
        super(Elasticsearch5SearchBackend,
              self).__init__(connection_alias, **connection_options)
        self.content_field_name = None

    def clear(self, models=None, commit=True):
        """
        Clears the backend of all documents/objects for a collection of models.