logo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions

Updated 8 months ago

elasticsearch

ElasticSearch Search

author: Jael


Description

The search operator runs a search via ElasticSearch client given a query. It takes a dictionary as input, which should be written in Query DSL. To use this operator, you need to set up ElasticSearch in advance.


Code Example

With an example ElasticSearch client 'localhost:9200', search across the index 'test_index' using an example query {'match_all': {}} to get all documents.

from towhee import pipe, ops, DataCollection


query = {'match_all': {}}
es_search = (
    pipe.input('index_name', 'query')
        .map(('index_name', 'query'), 'res', ops.elasticsearch.osschat_search(
            host='localhost', port=9200
        ))
        .output('query', 'res')
)

res = es_search('test_index', query)
DataCollection(res).show() # Optional: display output data


Factory Constructor

Create the operator via the following factory method:

elasticsearch.search(host='localhost', port=9200, user=None, password=None, ca_certs=None)

Parameters:

host: str

The host to connect ElasticSearch client.

port: int

The port to connect ElasticSearch client.

user: str

The username to connect ElasticSearch client if needed, defaults to None.

password: str

The user password to connect ElasticSearch client if needed, defaults to None.

ca_certs: str

The path to CA certificates to connect ElasticSearch client if needed, defaults to None.


Returns:

Search results wrapped by elastic_transport.ObjectApiResponse.

More Resources

Jael Gu 1729ce3d20 Add more resources 8 Commits
file-icon .gitattributes
1.1 KiB
download-icon
Initial commit 2 years ago
file-icon README.md
4.2 KiB
download-icon
Add more resources 8 months ago
file-icon __init__.py
106 B
download-icon
Add osschat-search 2 years ago
file-icon es_search.py
1.5 KiB
download-icon
Change es connection 2 years ago