aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/elasticsearch_tools.py
blob: bc7bb24087ca58d51f25578e6d8727f7b8b5d5ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from elasticsearch import Elasticsearch, TransportError
from utility.tools import ELASTICSEARCH_HOST, ELASTICSEARCH_PORT

es = Elasticsearch([{
    "host": ELASTICSEARCH_HOST
    , "port": ELASTICSEARCH_PORT
}]) 

def get_user_by_unique_column(column_name, column_value):
    user_details = None
    try:
        response = es.search(
            index = "users"
            , doc_type = "local"
            , body = { 
                "query": { "match": { column_name: column_value } } 
            })
        if len(response["hits"]["hits"]) > 0:
            user_details = response["hits"]["hits"][0]["_source"]
    except TransportError as te: 
        pass
    return user_details