Page MenuHome

queries.py
No OneTemporary

queries.py

import logging
import json
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, Q
from elasticsearch_dsl.connections import connections
from pillar import current_app
#elk_hosts = current_app.config['ELASTIC_SEARCH_HOSTS']
#
#connections.create_connection(
# hosts=elk_hosts,
# sniff_on_start=True,
# timeout=20)
#
client = Elasticsearch()
log = logging.getLogger(__name__)
def do_search(query: str) -> dict:
"""
Given user input search for node/stuff
"""
should = [
Q('match', name=query),
Q('match', user_name=query),
Q('match', project_name=query),
Q('match', description=query),
Q('term', media=query),
Q('term', tags=query),
]
bool_query = Q('bool', should=should)
search = Search(using=client)
search.query = bool_query
if current_app.config['DEBUG']:
log.debug(json.dumps(search.to_dict(), indent=4))
response = search.execute()
return response.to_dict()

File Metadata

Mime Type
text/x-python
Expires
Tue, Sep 21, 11:16 PM (2 d)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f9/01/40165a937c668d6c13abc4cd0583

Event Timeline