summaryrefslogtreecommitdiff
path: root/searx/engines/elasticsearch.py
diff options
context:
space:
mode:
Diffstat (limited to 'searx/engines/elasticsearch.py')
-rw-r--r--searx/engines/elasticsearch.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/searx/engines/elasticsearch.py b/searx/engines/elasticsearch.py
index c721114a7..6331a992e 100644
--- a/searx/engines/elasticsearch.py
+++ b/searx/engines/elasticsearch.py
@@ -43,6 +43,8 @@ authentication configured to read from ``my-index`` index.
from json import loads, dumps
from searx.exceptions import SearxEngineAPIException
+from searx.result_types import EngineResults
+from searx.extended_types import SXNG_Response
base_url = 'http://localhost:9200'
@@ -145,23 +147,20 @@ def _custom_query(query):
return custom_query
-def response(resp):
- results = []
+def response(resp: SXNG_Response) -> EngineResults:
+ res = EngineResults()
resp_json = loads(resp.text)
if 'error' in resp_json:
- raise SearxEngineAPIException(resp_json['error'])
-
- for result in resp_json['hits']['hits']:
- r = {key: str(value) if not key.startswith('_') else value for key, value in result['_source'].items()}
- r['template'] = 'key-value.html'
+ raise SearxEngineAPIException(resp_json["error"])
+ for result in resp_json["hits"]["hits"]:
+ kvmap = {key: str(value) if not key.startswith("_") else value for key, value in result["_source"].items()}
if show_metadata:
- r['metadata'] = {'index': result['_index'], 'id': result['_id'], 'score': result['_score']}
-
- results.append(r)
+ kvmap["metadata"] = {"index": result["_index"], "id": result["_id"], "score": result["_score"]}
+ res.add(res.types.KeyValue(kvmap=kvmap))
- return results
+ return res
_available_query_types = {