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 2 years ago

elasticsearch

ElasticSearch Index

author: Jael


Description

The index operator index the given documents in ElasticSearch to get ready for retrieval. It accepts a single document in dictionary or a list of documents (dictionaries) as input. For each document, the index automatically generates a unique id. To use this operator, you need to set up ElasticSearch in advance.


Code Example

Insert an example document into ElasticSearch with address of localhost:9200 and index of 'test_index'.

from datetime import datetime
from towhee import pipe, ops, DataCollection


example_doc = {
    'title': 'Test Title',
    'author': 'Towhee',
    'content': 'This is an example.',
    'timestamp': datetime.now()
    }

es_insert = (
    pipe.input('index_name', 'doc')
        .map(('index_name', 'doc'), 'res', ops.elasticsearch.index_client(
            host='localhost', port=9200
        ))
        .output('doc', 'res')
)

res = es_insert('test_index', example_doc) # OR: es_insert('test_index', [example_doc])
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:

Index response wrapped by elastic_transport.ObjectApiResponse.

shiyu22 0cc7a5a6a6 Add osschat-milvus 2 Commits
file-icon .gitattributes
1.1 KiB
download-icon
Initial commit 2 years ago
file-icon README.md
1.9 KiB
download-icon
Add osschat-milvus 2 years ago
file-icon __init__.py
102 B
download-icon
Add osschat-milvus 2 years ago
file-icon es_index.py
3.5 KiB
download-icon
Add osschat-milvus 2 years ago