From 7d12fa05482eff7ac3444417b8b7c6bd37e633a8 Mon Sep 17 00:00:00 2001 From: Lucas Lavandeira <19612265+lucaslavandeira@users.noreply.github.com> Date: Mon, 6 Aug 2018 11:34:16 -0300 Subject: [PATCH] Uso API de Index en metadatos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creación, refresh y forcemerge del índice, sin pasar por el cliente base de Elasticsearch --- .../apps/metadata/indexer/metadata_indexer.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/series_tiempo_ar_api/apps/metadata/indexer/metadata_indexer.py b/series_tiempo_ar_api/apps/metadata/indexer/metadata_indexer.py index e93b69e0..4073f366 100644 --- a/series_tiempo_ar_api/apps/metadata/indexer/metadata_indexer.py +++ b/series_tiempo_ar_api/apps/metadata/indexer/metadata_indexer.py @@ -6,7 +6,6 @@ from elasticsearch_dsl import Index from django_datajsonar.models import Node from series_tiempo_ar_api.apps.metadata.models import IndexMetadataTask -from series_tiempo_ar_api.libs.indexing.elastic import ElasticInstance from .doc_types import Field from .catalog_meta_indexer import CatalogMetadataIndexer from .index import get_fields_meta_index @@ -18,20 +17,19 @@ class MetadataIndexer: def __init__(self, task, doc_type=Field, index: Index = get_fields_meta_index()): self.task = task - self.elastic = ElasticInstance.get() self.index = index self.doc_type = doc_type - def init_index(self): + def setup_index(self): if not self.index.exists(): self.index.doc_type(self.doc_type) self.index.create() - - # Actualizo el mapping por si se agregan nuevos campos - self.doc_type._doc_type.refresh() + else: + # Actualizo el mapping por si se agregan nuevos campos + self.index.refresh() def run(self): - self.init_index() + self.setup_index() for node in Node.objects.filter(indexable=True): try: IndexMetadataTask.info(self.task, @@ -45,7 +43,7 @@ def run(self): IndexMetadataTask.info(self.task, u'Error en la lectura del catálogo {}: {}'.format(node.catalog_id, e)) - self.elastic.indices.forcemerge(self.index) + self.index.forcemerge() @job('indexing', timeout=10000)