Files
pillar/pillar/api/search/elastic_indexing.py

44 lines
914 B
Python
Raw Normal View History

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