aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2018-01-12 18:05:45 +0300
committerMuriithi Frederick Muriuki2018-01-12 18:05:45 +0300
commit3e70cab812e29e504f714c782c71bc4b79793686 (patch)
tree529921bc6b21f8db5332ef4346b171582eb763eb
parent76299c30c265919fd4025e11017b687c2b63fd82 (diff)
downloadgenenetwork2-3e70cab812e29e504f714c782c71bc4b79793686.tar.gz
Add elasticsearch_tools module
* Collect variables and functions for using the elasticsearch system in a separate module.
-rw-r--r--wqflask/utility/elasticsearch_tools.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
new file mode 100644
index 00000000..bc7bb240
--- /dev/null
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -0,0 +1,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