aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/elasticsearch_tools.py
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2018-01-12 18:05:45 +0300
committerPjotr Prins2018-03-26 09:24:34 +0000
commitd0f071a3871a2bcbb2c5170996a4afb145c21f9c (patch)
tree67551538df284937a9b1a3541e55dc65b9d7ce2f /wqflask/utility/elasticsearch_tools.py
parentccdf9b81147fba35e4df704f39026af6a64e3a20 (diff)
downloadgenenetwork2-d0f071a3871a2bcbb2c5170996a4afb145c21f9c.tar.gz
Add elasticsearch_tools module
* Collect variables and functions for using the elasticsearch system in a separate module.
Diffstat (limited to 'wqflask/utility/elasticsearch_tools.py')
-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