def test_mapping_created(self): es = elasticsearch_connection() mapping_type_name = Post.elasticsearch.mapping_type.get_type() response = es.indices.get_mapping( index=TEST_SETTINGS["GUM_ELASTICSEARCH_INDEX"], doc_type=mapping_type_name) self.assertDictEqual( response.get(TEST_SETTINGS["GUM_ELASTICSEARCH_INDEX"], {}).get("mappings"), Post.elasticsearch.mapping_type.mapping())
def remove_index(self): """Deletes used indices. TODO: Add settings configuration of the index. """ es = elasticsearch_connection() es.indices.delete(index=ELASTICSEARCH_INDICES, ignore=400) for _, mapping_type in six.iteritems(self._registry): mapping_type_es = mapping_type.get_elasticsearch_connection() if mapping_type.index != ELASTICSEARCH_INDICES or mapping_type.urls is not None: mapping_type_es.indices.delete(index=mapping_type.index, ignore=400)
def test_mapping_created(self): es = elasticsearch_connection() mapping_type_name = Post.elasticsearch.mapping_type.get_type() response = es.indices.get_mapping( index=TEST_SETTINGS["GUM_ELASTICSEARCH_INDEX"], doc_type=mapping_type_name ) self.assertDictEqual( response.get(TEST_SETTINGS["GUM_ELASTICSEARCH_INDEX"], {}).get("mappings"), Post.elasticsearch.mapping_type.mapping() )
def update_settings(self): """Updates the settings of the indexes.""" es = elasticsearch_connection() es.indices.close(index=ELASTICSEARCH_INDICES) es.indices.put_settings(index=ELASTICSEARCH_INDICES, body=DEFAULT_ELASTICSEARCH_SETTINGS) es.indices.open(index=ELASTICSEARCH_INDICES) for _, mapping_type in six.iteritems(self._registry): mapping_type_es = mapping_type.get_elasticsearch_connection() if mapping_type.index != ELASTICSEARCH_INDICES or mapping_type.urls is not None: mapping_type_es.indices.close(index=mapping_type.index) mapping_type_es.indices.put_settings( index=mapping_type.index, body=mapping_type.settings or DEFAULT_ELASTICSEARCH_SETTINGS, ) mapping_type_es.indices.open(index=mapping_type.index)
def initialize_index(self): """Creates and initialize index. TODO: Add settings configuration of the index. """ es = elasticsearch_connection() es.indices.create(index=ELASTICSEARCH_INDICES, body=DEFAULT_ELASTICSEARCH_SETTINGS, ignore=400) for _, mapping_type in six.iteritems(self._registry): mapping_type_es = mapping_type.get_elasticsearch_connection() if mapping_type.index != ELASTICSEARCH_INDICES or mapping_type.urls is not None: mapping_type_es.indices.create( index=mapping_type.index, body=mapping_type.settings or DEFAULT_ELASTICSEARCH_SETTINGS, ignore=400 )
def initialize_index(self): """Creates and initialize index. TODO: Add settings configuration of the index. """ es = elasticsearch_connection() es.indices.create(index=ELASTICSEARCH_INDICES, body=DEFAULT_ELASTICSEARCH_SETTINGS, ignore=400) for _, mapping_type in six.iteritems(self._registry): mapping_type_es = mapping_type.get_elasticsearch_connection() if mapping_type.index != ELASTICSEARCH_INDICES or mapping_type.urls is not None: mapping_type_es.indices.create( index=mapping_type.index, body=mapping_type.settings or DEFAULT_ELASTICSEARCH_SETTINGS, ignore=400)
def get_elasticsearch_connection(self): """Gets the Elasticsearch connection with the urls attribute""" return elasticsearch_connection(urls=self.urls)
def get_elasticsearch_connection(self): """Gets the Elasticsearch connection with the urls attribute""" if self.mapping_type is not None: return self.mapping_type.get_elasticsearch_connection() return elasticsearch_connection(urls=self.urls)