summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2025-02-26 21:29:22 +0100
committerBnyro <bnyro@tutanota.com>2025-03-16 22:10:05 +0100
commitbbb2894b049254a44faaa9393114129fb4030c4b (patch)
tree94969c2ae383d2e095bb033aa1da57c0506d794b
parent84636ef49acc6e74421c23a80f6f63aa4ccc93c7 (diff)
[engine] elasticsearch: add pagination support
-rw-r--r--searx/engines/elasticsearch.py27
-rw-r--r--searx/settings.yml7
2 files changed, 26 insertions, 8 deletions
diff --git a/searx/engines/elasticsearch.py b/searx/engines/elasticsearch.py
index 6331a992e..c4992b02f 100644
--- a/searx/engines/elasticsearch.py
+++ b/searx/engines/elasticsearch.py
@@ -29,7 +29,7 @@ authentication configured to read from ``my-index`` index.
.. code:: yaml
- name: elasticsearch
- shortcut: es
+ shortcut: els
engine: elasticsearch
base_url: http://localhost:9200
username: elastic
@@ -46,16 +46,26 @@ from searx.exceptions import SearxEngineAPIException
from searx.result_types import EngineResults
from searx.extended_types import SXNG_Response
+categories = ['general']
+paging = True
+
+about = {
+ 'website': 'https://www.elastic.co',
+ 'wikidata_id': 'Q3050461',
+ 'official_api_documentation': 'https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html',
+ 'use_official_api': True,
+ 'require_api_key': False,
+ 'format': 'JSON',
+}
base_url = 'http://localhost:9200'
username = ''
password = ''
index = ''
-search_url = '{base_url}/{index}/_search'
query_type = 'match'
custom_query_json = {}
show_metadata = False
-categories = ['general']
+page_size = 10
def init(engine_settings):
@@ -73,9 +83,16 @@ def request(query, params):
if username and password:
params['auth'] = (username, password)
- params['url'] = search_url.format(base_url=base_url, index=index)
+ args = {
+ 'from': (params['pageno'] - 1) * page_size,
+ 'size': page_size,
+ }
+ data = _available_query_types[query_type](query)
+ data.update(args)
+
+ params['url'] = f"{base_url}/{index}/_search"
params['method'] = 'GET'
- params['data'] = dumps(_available_query_types[query_type](query))
+ params['data'] = dumps(data)
params['headers']['Content-Type'] = 'application/json'
return params
diff --git a/searx/settings.yml b/searx/settings.yml
index ec6f4c1c5..770f80ea7 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -789,17 +789,18 @@ engines:
results: HTML
# - name: elasticsearch
- # shortcut: es
+ # shortcut: els
# engine: elasticsearch
# base_url: http://localhost:9200
# username: elastic
# password: changeme
# index: my-index
+ # enable_http: true
# # available options: match, simple_query_string, term, terms, custom
# query_type: match
# # if query_type is set to custom, provide your query here
- # #custom_query_json: {"query":{"match_all": {}}}
- # #show_metadata: false
+ # # custom_query_json: {"query":{"match_all": {}}}
+ # # show_metadata: false
# disabled: true
- name: wikidata