- 1,000 operations
- 5mb of updates
- 5 seconds since the last flush (assuming new actions are queued)
Prerequisites
- Ensure the Elasticsearch cluster (version 7.x or 8.x) is accessible from RisingWave.
- If you are running RisingWave locally from binaries, make sure that you have JDK 11 or later versions installed in your environment.
Create an Elasticsearch sink
Use the following syntax to create an Elasticsearch sink. Once a sink is created, any insert or update to the sink will be streamed to the specified Elasticsearch endpoint.Parameters
For versions under 8.x, there was once a parameter
type. In Elasticsearch 6.x, users could directly set the type, but starting from 7.x, it is set to not recommended and the default value is unified to _doc. In version 8.x, the type has been completely removed. See Elasticsearch’s official documentation for more details.
So, if you are using Elasticsearch 7.x, we set it to the official’s recommended value, which is _doc. If you are using Elasticsearch 8.x, this parameter has been removed by the Elasticsearch official, so no setting is required.
Auto schema change
Elasticsearch sinks support auto schema change to automatically adapt their output schema according to changes in the upstream table. This feature is supported only whensink_decoupling is disabled.
Once auto schema change is enabled, if you add new columns to the source table, the sink will automatically update to match the new schema. This reduces manual intervention and makes your data pipelines more robust to schema evolution.
To enable it, set the following option when creating the sink:
Notes about primary keys and Elasticsearch IDs
The Elasticsearch sink defaults to theupsert sink type. It does not support the append-only sink type.
The Elasticsearch sink detects column-level changes during upserts and sends only the modified columns, helping reduce the load on Elasticsearch.
If you want to customize your Elasticsearch ID, please specify it via the primary_key parameter. RisingWave will combine multiple primary key values into a single string with the delimiter you set, and use it as the Elasticsearch ID.
If you don’t want to customize your Elasticsearch ID, RisingWave will use the first column in the sink definition as the Elasticsearch ID.
Data type mapping
ElasticSearch uses a mechanism called dynamic field mapping to dynamically create fields and determine their types automatically. It treats all integer types as long and all floating-point types as float. To ensure data types in RisingWave are mapped to the data types in Elasticsearch correctly, we recommend that you specify the mapping via index templates or dynamic templates before creating the sink.
Elasticsearch doesn’t require users to explicitly
CREATE TABLE. Instead, it infers the schema on-the-fly based on the first record ingested. For example, if a record contains a jsonb {v1: 100}, v1 will be inferred as a long type. However, if the next record is {v1: "abc"}, the ingestion will fail because "abc" is inferred as a string and the two types are incompatible.
This behavior should be noted, or your data may be less than it should be. In terms of monitoring, you can check out Grafana, where there is a panel for all sink write errors.