2017-11-03 18:18:12 +01:00
|
|
|
import logging
|
2017-11-17 18:04:29 +01:00
|
|
|
|
2017-11-10 16:05:12 +01:00
|
|
|
from elasticsearch_dsl.connections import connections
|
|
|
|
|
2017-11-17 18:04:29 +01:00
|
|
|
from pillar import current_app
|
2017-11-10 16:05:12 +01:00
|
|
|
from . import documents
|
|
|
|
|
|
|
|
|
|
|
|
elk_hosts = current_app.config['ELASTIC_SEARCH_HOSTS']
|
|
|
|
|
|
|
|
connections.create_connection(
|
|
|
|
hosts=elk_hosts,
|
|
|
|
sniff_on_start=True,
|
|
|
|
timeout=20)
|
2017-11-03 18:18:12 +01:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def push_updated_user(user_to_index: dict):
|
2017-11-10 16:05:12 +01:00
|
|
|
"""
|
|
|
|
Push an update to the Elastic index when
|
|
|
|
a user item is updated.
|
|
|
|
"""
|
2017-11-17 16:05:22 +01:00
|
|
|
doc = documents.create_doc_from_user_data(user_to_index)
|
2017-12-08 13:12:39 +01:00
|
|
|
log.debug('UPDATE USER %s', doc._id)
|
2017-11-17 16:05:22 +01:00
|
|
|
doc.save()
|
|
|
|
|
2017-11-03 18:18:12 +01:00
|
|
|
|
|
|
|
def index_node_save(node_to_index: dict):
|
|
|
|
|
2017-12-08 13:12:39 +01:00
|
|
|
if not node_to_index:
|
|
|
|
return
|
2017-11-10 16:05:12 +01:00
|
|
|
|
|
|
|
doc = documents.create_doc_from_node_data(node_to_index)
|
|
|
|
|
2017-12-08 13:12:39 +01:00
|
|
|
log.debug('CREATED ELK NODE DOC %s', doc._id)
|
2017-11-10 16:05:12 +01:00
|
|
|
doc.save()
|
|
|
|
|
2017-11-03 18:18:12 +01:00
|
|
|
|
|
|
|
def index_node_delete(delete_id: str):
|
|
|
|
|
2017-12-08 13:12:39 +01:00
|
|
|
log.debug('NODE DELETE INDEXING %s', delete_id)
|
2017-11-10 16:05:12 +01:00
|
|
|
documents.Node(id=delete_id).delete()
|