Skip to content

Commit

Permalink
Uso API de Index en metadatos
Browse files Browse the repository at this point in the history
Creación, refresh y forcemerge del índice, sin pasar por el cliente base de Elasticsearch
  • Loading branch information
lucaslavandeira committed Aug 6, 2018
1 parent 6ae8e18 commit 7d12fa0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions series_tiempo_ar_api/apps/metadata/indexer/metadata_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 7d12fa0

Please sign in to comment.