title: Elasticsearch sidebar_position: 4

import {siteVariables} from ‘../../version’;

Overview

The Elasticsearch Load Node allows for writing into an index of the Elasticsearch engine. This document describes how to setup the Elasticsearch Load Node to run SQL queries against Elasticsearch.

The Load Node can operate in upsert mode for exchanging UPDATE/DELETE messages with the external system using the primary key defined on the DDL.

If no primary key is defined on the DDL, the Load Node can only operate in append mode for exchanging INSERT only messages with external system.

Supported Version

Load NodeVersion
elasticsearchElasticsearch: 5.x, 6.x, 7.x

Dependencies

In order to use the Elasticsearch Load Node the following dependencies are required for both projects using a build automation tool (such as Maven or SBT) and SQL Client with Sort Connectors JAR bundles.

  • Elasticsearch 6
  • Elasticsearch 7

How to create an Elasticsearch Load Node

Usage for SQL API

The example below shows how to create an Elasticsearch Load Node with Flink SQL :

CREATE TABLE myUserTable (
  user_id STRING,
  user_name STRING,
  uv BIGINT,
  pv BIGINT,
  PRIMARY KEY (user_id) NOT ENFORCED
) WITH (
  'connector' = 'elasticsearch-7-inlong',
  'hosts' = 'http://localhost:9200',
  'index' = 'users'
);

Usage for InLong Dashboard

TODO: It will be supported in the future.

Usage for InLong Manager Client

TODO: It will be supported in the future.

Elasticsearch Load Node Options

Features

Key Handling

Elasticsearch sink can work in either upsert mode or append mode, it depends on whether primary key is defined. If primary key is defined, Elasticsearch sink works in upsert mode which can consume queries containing UPDATE/DELETE messages. If primary key is not defined, Elasticsearch sink works in append mode which can only consume queries containing INSERT only messages.

In Elasticsearch connector, the primary key is used to calculate the Elasticsearch document id, which is a string of up to 512 bytes. It cannot have whitespaces. The Elasticsearch connector generates a document ID string for every row by concatenating all primary key fields in the order defined in the DDL using a key delimiter specified by document-id.key-delimiter. Certain types are not allowed as primary key field as they do not have a good string representation, e.g. BYTES, ROW, ARRAY, MAP, etc. If no primary key is specified, Elasticsearch will generate a document id automatically.

See CREATE TABLE DDL for more details about PRIMARY KEY syntax.

Dynamic Index

Elasticsearch Load Node supports both static index and dynamic index.

If you want to have a static index, the index option value should be a plain string, e.g. 'myusers', all the records will be consistently written into “myusers” index.

If you want to have a dynamic index, you can use {field_name} to reference a field value in the record to dynamically generate a target index. You can also use '{field_name|date_format_string}' to convert a field value of TIMESTAMP/DATE/TIME type into the format specified by the date_format_string. The date_format_string is compatible with Java's DateTimeFormatter. For example, if the option value is 'myusers-{'{log_ts|yyyy-MM-dd}'}', then a record with log_ts field value 2020-03-27 12:25:55 will be written into “myusers-2020-03-27” index.

Data Type Mapping