Ahmet Melek fd293b3e78
feat: add elasticsearch destination connector (#2152)
Closes https://github.com/Unstructured-IO/unstructured/issues/1842
Closes https://github.com/Unstructured-IO/unstructured/issues/2202
Closes https://github.com/Unstructured-IO/unstructured/issues/2203

This PR:
- Adds Elasticsearch destination connector to be able to ingest
documents from any supported source, embed them and write the embeddings
/ documents into Elasticsearch.
- Defines an example unstructured elements schema for users to be able
to setup their unstructured elasticsearch indexes easily.
- Includes parallelized upload and lazy processing for elasticsearch
destination connector.
- Rearranges elasticsearch test helpers to source, destination, and
common folders.
- Adds util functions to be able to batch iterables in a lazy way for
uploads
- Fixes a bug where removing the optional parameter `--fields` broke the
connector due to an integer processing error.
- Fixes a bug where using an [elasticsearch
config](8fa5cbf036/unstructured/ingest/connector/elasticsearch.py (L26-L35))
for a destination connector resulted in a serialization issue when
optional parameter `--fields` was not provided.
2023-12-20 01:26:58 +00:00

36 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Processes a the file from local, chunks, embeds, and writes the results to an Elasticsearch index.
# Structured outputs are stored in local-to-elasticsearch/
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
cd "$SCRIPT_DIR"/../../.. || exit 1
# As an example we're using the local connector,
# however ingesting from any supported source connector is possible.
# shellcheck disable=2094
PYTHONPATH=. ./unstructured/ingest/main.py \
local \
--input-path example-docs/book-war-and-peace-1225p.txt \
--output-dir local-to-elasticsearch \
--strategy fast \
--chunk-elements \
--embedding-provider "<an unstructured embedding provider, ie. langchain-huggingface>" \
--num-processes 2 \
--verbose \
--work-dir "<directory for intermediate outputs to be saved>" \
elasticsearch \
--hosts "<List of URLs where elasticsearch index is served>" \
--index-name "<Index name to upload data in>" \
--username "<Username to authenticate into the index>" \
--password "<Password to authenticate into the index>" \
--batch-size-bytes "<Size limit for any batch to be uploaded, in bytes, ie. 15000000>" \
--num-processes "<Number of processes to be used to upload, ie. 2>" \
--cloud-id "<Id used to connect to Elastic Cloud>" \
--es-api-key "<Api key used for authentication>" \
--api-key-id "<Id associated with api key used for authentication: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html>" \
--bearer-auth "<Bearer token used for HTTP bearer authentication>" \
--ca-certs "<path/to/ca/certs>" \
--ssl-assert-fingerprint "<SHA256 fingerprint value>"