Skip to main content
Version: Next

Typesense

Description

Writes SeaTunnel rows to a Typesense collection. The connector can create the target collection when needed, clear existing documents before writing, and generate document id values from one or more primary key fields.

Key Features

Options

NameTypeRequiredDefaultDescription
hostsarrayYes-Typesense node addresses in host:port format. Multiple hosts are supported.
collectionstringYes-Target collection name.
schema_save_modestringYesCREATE_SCHEMA_WHEN_NOT_EXISTHow to handle the target collection schema before writing.
data_save_modestringYesAPPEND_DATAHow to handle existing documents before writing.
primary_keysarrayNo-Source fields used to build the Typesense document id.
key_delimiterstringNo_Delimiter used when primary_keys contains more than one field.
api_keystringYes-Typesense API key.
max_retry_countintNo3Maximum retry count for one bulk request.
max_batch_sizeintNo10Maximum number of documents sent in one bulk request.
multi_table_sink_replicaintNo-Number of sink replicas used by the common multi-table sink routing mechanism.
common-optionsNo-Common sink options.

hosts [array]

The access address for Typesense, formatted as host:port, e.g., ["typesense-01:8108"].

collection [string]

The name of the collection to write to, e.g., "seatunnel".

primary_keys [array]

Primary key fields used to generate the document id. When more than one field is configured, the connector joins their values with key_delimiter.

key_delimiter [string]

Sets the delimiter for composite keys (default is _).

api_key [string]

The api_key for secure access to Typesense.

max_retry_count [int]

The maximum number of retry attempts for one batch request.

max_batch_size [int]

The maximum number of documents sent in one batch.

multi_table_sink_replica [int]

Common multi-table sink option. Configure it when a multi-table job needs more sink replicas for the Typesense writer.

common options

Common parameters for Sink plugins. Refer to Common Sink Options for more details.

schema_save_mode

Choose how to handle the target-side schema before starting the synchronization task:

  • RECREATE_SCHEMA: Creates the table if it doesn’t exist, and deletes and recreates it if it does.
  • CREATE_SCHEMA_WHEN_NOT_EXIST: Creates the table if it doesn’t exist, skips creation if it does.
  • ERROR_WHEN_SCHEMA_NOT_EXIST: Throws an error if the table doesn’t exist.

Typesense collection creation uses the upstream SeaTunnel schema. Configure primary_keys when the generated document id must be stable across repeated writes.

data_save_mode

Choose how to handle existing data on the target side before starting the synchronization task:

  • DROP_DATA: Retains the database structure but deletes the data.
  • APPEND_DATA: Retains both the database structure and the data.
  • ERROR_WHEN_DATA_EXISTS: Throws an error if data exists.

Task Example

Write Documents With Primary Keys

env {
parallelism = 1
job.mode = "BATCH"
}

source {
FakeSource {
row.num = 5
plugin_output = "typesense_test_table"
schema {
fields {
company_name = string
num = long
id = string
num_employees = int
flag = boolean
}
}
}
}

sink {
Typesense {
plugin_input = "typesense_test_table"
hosts = ["localhost:8108"]
collection = "typesense_test_collection"
api_key = "xyz"
primary_keys = ["num_employees", "num"]
key_delimiter = "="
max_retry_count = 3
max_batch_size = 10
schema_save_mode = "CREATE_SCHEMA_WHEN_NOT_EXIST"
data_save_mode = "APPEND_DATA"
}
}

Read From Typesense And Write To Another Collection

env {
parallelism = 1
job.mode = "BATCH"
}

source {
Typesense {
hosts = ["localhost:8108"]
collection = "typesense_source_collection"
api_key = "xyz"
query = "q=*&filter_by=c_row.c_int:>10"
plugin_output = "typesense_test_table"
schema = {
fields {
company_name_list = array<string>
company_name = string
num_employees = long
country = string
id = string
c_row = {
c_int = int
c_string = string
c_array_int = array<int>
}
}
}
}
}

sink {
Typesense {
plugin_input = "typesense_test_table"
hosts = ["localhost:8108"]
collection = "typesense_sink_collection"
api_key = "xyz"
primary_keys = ["num_employees", "id"]
key_delimiter = "="
max_retry_count = 3
max_batch_size = 10
schema_save_mode = "CREATE_SCHEMA_WHEN_NOT_EXIST"
data_save_mode = "APPEND_DATA"
}
}

Changelog

Change Log
ChangeCommitVersion
[Improve][API] Optimize the enumerator API semantics and reduce lock calls at the connector level (#9671)https://github.com/apache/seatunnel/commit/9212a771402.3.12
[improve] typesense options (#9398)https://github.com/apache/seatunnel/commit/bf20a3e6a82.3.12
[Feature][Checkpoint] Add check script for source/sink state class serialVersionUID missing (#9118)https://github.com/apache/seatunnel/commit/4f5adeb1c72.3.11
[Fix] Fix error log name for SourceSplitEnumerator implements class (#8817)https://github.com/apache/seatunnel/commit/55ed90ecaf2.3.10
[Improve] restruct connector common options (#8634)https://github.com/apache/seatunnel/commit/f3499a6eeb2.3.10
[Feature]Check Chinese comments in the code (#8319)https://github.com/apache/seatunnel/commit/d58fce1caf2.3.9
[Improve][dist]add shade check rule (#8136)https://github.com/apache/seatunnel/commit/51ef8000162.3.9
[Feature][Restapi] Allow metrics information to be associated to logical plan nodes (#7786)https://github.com/apache/seatunnel/commit/6b7c53d03c2.3.9
[Fix][Connector-V2] Fix known directory create and delete ignore issues (#7700)https://github.com/apache/seatunnel/commit/e2fb6795772.3.8
[Feature][Connector-V2] Support typesense connector (#7450)https://github.com/apache/seatunnel/commit/138d2a4eb22.3.8