[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
|
.. code:: yaml
|
||||||
|
|
||||||
- name: elasticsearch
|
- name: elasticsearch
|
||||||
shortcut: es
|
shortcut: els
|
||||||
engine: elasticsearch
|
engine: elasticsearch
|
||||||
base_url: http://localhost:9200
|
base_url: http://localhost:9200
|
||||||
username: elastic
|
username: elastic
|
||||||
@ -46,16 +46,26 @@ from searx.exceptions import SearxEngineAPIException
|
|||||||
from searx.result_types import EngineResults
|
from searx.result_types import EngineResults
|
||||||
from searx.extended_types import SXNG_Response
|
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'
|
base_url = 'http://localhost:9200'
|
||||||
username = ''
|
username = ''
|
||||||
password = ''
|
password = ''
|
||||||
index = ''
|
index = ''
|
||||||
search_url = '{base_url}/{index}/_search'
|
|
||||||
query_type = 'match'
|
query_type = 'match'
|
||||||
custom_query_json = {}
|
custom_query_json = {}
|
||||||
show_metadata = False
|
show_metadata = False
|
||||||
categories = ['general']
|
page_size = 10
|
||||||
|
|
||||||
|
|
||||||
def init(engine_settings):
|
def init(engine_settings):
|
||||||
@ -73,9 +83,16 @@ def request(query, params):
|
|||||||
if username and password:
|
if username and password:
|
||||||
params['auth'] = (username, 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['method'] = 'GET'
|
||||||
params['data'] = dumps(_available_query_types[query_type](query))
|
params['data'] = dumps(data)
|
||||||
params['headers']['Content-Type'] = 'application/json'
|
params['headers']['Content-Type'] = 'application/json'
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
@ -789,17 +789,18 @@ engines:
|
|||||||
results: HTML
|
results: HTML
|
||||||
|
|
||||||
# - name: elasticsearch
|
# - name: elasticsearch
|
||||||
# shortcut: es
|
# shortcut: els
|
||||||
# engine: elasticsearch
|
# engine: elasticsearch
|
||||||
# base_url: http://localhost:9200
|
# base_url: http://localhost:9200
|
||||||
# username: elastic
|
# username: elastic
|
||||||
# password: changeme
|
# password: changeme
|
||||||
# index: my-index
|
# index: my-index
|
||||||
|
# enable_http: true
|
||||||
# # available options: match, simple_query_string, term, terms, custom
|
# # available options: match, simple_query_string, term, terms, custom
|
||||||
# query_type: match
|
# query_type: match
|
||||||
# # if query_type is set to custom, provide your query here
|
# # if query_type is set to custom, provide your query here
|
||||||
# #custom_query_json: {"query":{"match_all": {}}}
|
# # custom_query_json: {"query":{"match_all": {}}}
|
||||||
# #show_metadata: false
|
# # show_metadata: false
|
||||||
# disabled: true
|
# disabled: true
|
||||||
|
|
||||||
- name: wikidata
|
- name: wikidata
|
||||||
|
Loading…
x
Reference in New Issue
Block a user