minor documentation / annotation fixes

This commit is contained in:
Stephan preeker 2018-01-05 11:58:33 +01:00
parent 2ed2aaf58f
commit 2433a1b981
4 changed files with 16 additions and 12 deletions

View File

@ -28,7 +28,7 @@ def push_updated_user(user_to_index: dict):
if not doc:
return
log.debug('index update user elasticsearch %s', doc._id)
log.debug('Index update user doc elasticsearch %s.', doc._id)
doc.save()
@ -36,7 +36,6 @@ def index_node_save(node_to_index: dict):
"""
Push an update to the Elastic index when a node item is saved.
"""
if not node_to_index:
return
@ -45,7 +44,7 @@ def index_node_save(node_to_index: dict):
if not doc:
return
log.debug('index created node elasticsearch %s', doc._id)
log.debug('Index created node doc elasticsearch %s.', doc._id)
doc.save()
@ -53,8 +52,7 @@ def index_node_delete(delete_id: str):
"""
Delete node document from Elastic index useing a node id
"""
log.debug('index node delete %s', delete_id)
log.debug('Index node doc delete %s', delete_id)
try:
doc = documents.Node.get(id=delete_id)

View File

@ -14,11 +14,12 @@ log = logging.getLogger(__name__)
class ResetIndexTask(object):
""" Clear and build index / mapping """
index_key = ''
"""Key into the ELASTIC_INDICES dict in the app config."""
# Key into the ELASTIC_INDICES dict in the app config.
index_key: str = ''
# List of elastic document types
doc_types = []
doc_types: List = []
name = 'remove index'
def __init__(self):

View File

@ -1,7 +1,8 @@
import json
import logging
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, Q
import logging
from pillar import current_app
log = logging.getLogger(__name__)
@ -12,7 +13,9 @@ user_agg_terms = ['roles', ]
class TheELKClient():
"""
current_app is not available when on import
Elastic-client singleton.
`current_app` is not available when on import
"""
client: Elasticsearch = None
@ -23,6 +26,7 @@ class TheELKClient():
else:
return self.client
elk = TheELKClient()
@ -89,6 +93,7 @@ def do_search(query: str, terms: dict) -> dict:
add_aggs_to_search(search, node_agg_terms)
if log.isEnabledFor(logging.DEBUG):
# logging removes readable indendation.
print(json.dumps(search.to_dict(), indent=4))
response = search.execute()

View File

@ -79,7 +79,7 @@ def _reindex_nodes():
nodes_coll = nodes_coll.find({'project': {'$in': _public_project_ids()}})
node_count = nodes_coll.count()
log.debug('Reindexing nodes %d in Elastic', node_count)
log.debug('Nodes %d will be reindexed in Elastic', node_count)
from pillar.celery.search_index_tasks import prepare_node_data
from pillar.api.search import elastic_indexing
@ -89,7 +89,7 @@ def _reindex_nodes():
to_index = prepare_node_data('', node=node)
elastic_indexing.index_node_save(to_index)
except (KeyError, AttributeError):
log.exception('Field is missing for %s', node)
log.exception('%s is missing Field', node)
continue