minor documentation / annotation fixes
This commit is contained in:
parent
2ed2aaf58f
commit
2433a1b981
@ -28,7 +28,7 @@ def push_updated_user(user_to_index: dict):
|
|||||||
if not doc:
|
if not doc:
|
||||||
return
|
return
|
||||||
|
|
||||||
log.debug('index update user elasticsearch %s', doc._id)
|
log.debug('Index update user doc elasticsearch %s.', doc._id)
|
||||||
doc.save()
|
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.
|
Push an update to the Elastic index when a node item is saved.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not node_to_index:
|
if not node_to_index:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -45,7 +44,7 @@ def index_node_save(node_to_index: dict):
|
|||||||
if not doc:
|
if not doc:
|
||||||
return
|
return
|
||||||
|
|
||||||
log.debug('index created node elasticsearch %s', doc._id)
|
log.debug('Index created node doc elasticsearch %s.', doc._id)
|
||||||
doc.save()
|
doc.save()
|
||||||
|
|
||||||
|
|
||||||
@ -53,8 +52,7 @@ def index_node_delete(delete_id: str):
|
|||||||
"""
|
"""
|
||||||
Delete node document from Elastic index useing a node id
|
Delete node document from Elastic index useing a node id
|
||||||
"""
|
"""
|
||||||
|
log.debug('Index node doc delete %s', delete_id)
|
||||||
log.debug('index node delete %s', delete_id)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
doc = documents.Node.get(id=delete_id)
|
doc = documents.Node.get(id=delete_id)
|
||||||
|
@ -14,11 +14,12 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class ResetIndexTask(object):
|
class ResetIndexTask(object):
|
||||||
""" Clear and build index / mapping """
|
""" 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
|
# List of elastic document types
|
||||||
doc_types = []
|
doc_types: List = []
|
||||||
name = 'remove index'
|
name = 'remove index'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
from elasticsearch import Elasticsearch
|
from elasticsearch import Elasticsearch
|
||||||
from elasticsearch_dsl import Search, Q
|
from elasticsearch_dsl import Search, Q
|
||||||
import logging
|
|
||||||
|
|
||||||
from pillar import current_app
|
from pillar import current_app
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -12,7 +13,9 @@ user_agg_terms = ['roles', ]
|
|||||||
|
|
||||||
class TheELKClient():
|
class TheELKClient():
|
||||||
"""
|
"""
|
||||||
current_app is not available when on import
|
Elastic-client singleton.
|
||||||
|
|
||||||
|
`current_app` is not available when on import
|
||||||
"""
|
"""
|
||||||
client: Elasticsearch = None
|
client: Elasticsearch = None
|
||||||
|
|
||||||
@ -23,6 +26,7 @@ class TheELKClient():
|
|||||||
else:
|
else:
|
||||||
return self.client
|
return self.client
|
||||||
|
|
||||||
|
|
||||||
elk = TheELKClient()
|
elk = TheELKClient()
|
||||||
|
|
||||||
|
|
||||||
@ -89,6 +93,7 @@ def do_search(query: str, terms: dict) -> dict:
|
|||||||
add_aggs_to_search(search, node_agg_terms)
|
add_aggs_to_search(search, node_agg_terms)
|
||||||
|
|
||||||
if log.isEnabledFor(logging.DEBUG):
|
if log.isEnabledFor(logging.DEBUG):
|
||||||
|
# logging removes readable indendation.
|
||||||
print(json.dumps(search.to_dict(), indent=4))
|
print(json.dumps(search.to_dict(), indent=4))
|
||||||
|
|
||||||
response = search.execute()
|
response = search.execute()
|
||||||
|
@ -79,7 +79,7 @@ def _reindex_nodes():
|
|||||||
nodes_coll = nodes_coll.find({'project': {'$in': _public_project_ids()}})
|
nodes_coll = nodes_coll.find({'project': {'$in': _public_project_ids()}})
|
||||||
node_count = nodes_coll.count()
|
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.celery.search_index_tasks import prepare_node_data
|
||||||
from pillar.api.search import elastic_indexing
|
from pillar.api.search import elastic_indexing
|
||||||
@ -89,7 +89,7 @@ def _reindex_nodes():
|
|||||||
to_index = prepare_node_data('', node=node)
|
to_index = prepare_node_data('', node=node)
|
||||||
elastic_indexing.index_node_save(to_index)
|
elastic_indexing.index_node_save(to_index)
|
||||||
except (KeyError, AttributeError):
|
except (KeyError, AttributeError):
|
||||||
log.exception('Field is missing for %s', node)
|
log.exception('%s is missing Field', node)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user