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

73 lines
1.7 KiB

# ElasticSearch Search
2 years ago
*author: Jael*
<br />
## 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](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html).
To use this operator, you need to [set up ElasticSearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html) in advance.
<br />
## 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.
```python
from towhee import pipe, ops, DataCollection
query = {'match_all': {}}
es_search = (
pipe.input('index_name', 'query')
2 years ago
.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
```
<br />
## 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.
<br />
**Returns:**
Search results wrapped by `elastic_transport.ObjectApiResponse`.