[engine] elasticsearch: add pagination support
This commit is contained in:
parent
84636ef49a
commit
bbb2894b04
@ -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
|
||||
|
@ -789,12 +789,13 @@ 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user