Elasticsearch5

Since Camel 2.19

The ElasticSearch component allows you to interface with an ElasticSearch 5.x API.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-elasticsearch5</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

elasticsearch5://clusterName[?options]

Endpoint Options

The Elasticsearch5 component supports 2 options, which are listed below.

Name Description Default Type

client (advanced)

To use an existing configured Elasticsearch client, instead of creating a client per endpoint. This allow to customize the client with specific settings.

TransportClient

resolveProperty Placeholders (advanced)

Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.

true

boolean

The Elasticsearch5 endpoint is configured using URI syntax:

elasticsearch5:clusterName

with the following path and query parameters:

Path Parameters (1 parameters):

Name Description Default Type

clusterName

Required Name of the cluster

String

Query Parameters (16 parameters):

Name Description Default Type

clientTransportSniff (producer)

Is the client allowed to sniff the rest of the cluster or not. This setting map to the client.transport.sniff setting.

false

boolean

indexName (producer)

The name of the index to act against

String

indexType (producer)

The type of the index to act against

String

ip (producer)

The TransportClient remote host ip to use

String

operation (producer)

What operation to perform

ElasticsearchOperation

pingSchedule (producer)

The time(in unit) the client ping the cluster.

5s

String

pingTimeout (producer)

The time(in unit) to wait for a ping response from a node too return.

5s

String

port (producer)

The TransportClient remote port to use (defaults to 9300)

9300

int

tcpCompress (producer)

true if compression (LZF) enable between all nodes.

false

boolean

tcpConnectTimeout (producer)

The time( in unit) to wait for connection timeout.

30s

String

transportAddresses (producer)

Comma separated list with ip:port formatted remote transport addresses to use. The ip and port options must be left blank for transportAddresses to be considered instead.

String

waitForActiveShards (producer)

Index creation waits for the write consistency number of shards to be available

1

int

synchronous (advanced)

Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).

false

boolean

enableSSL (security)

Enable SSL. Require XPack client jar on the classpath

false

boolean

password (authentication)

Password for authenticate against the cluster. Require XPack client jar on the classpath

String

user (authentication)

User for authenticate against the cluster. Requires transport_client role for accessing the cluster. Require XPack client jar on the classpath

String

Spring Boot Auto-Configuration

When using Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-elasticsearch5-starter</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>

The component supports 3 options, which are listed below.

Name Description Default Type

camel.component.elasticsearch5.client

To use an existing configured Elasticsearch client, instead of creating a client per endpoint. This allow to customize the client with specific settings. The option is a org.elasticsearch.client.transport.TransportClient type.

String

camel.component.elasticsearch5.enabled

Enable elasticsearch5 component

true

Boolean

camel.component.elasticsearch5.resolve-property-placeholders

Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.

true

Boolean

Message Operations

The following ElasticSearch operations are currently supported. Simply set an endpoint URI option or exchange header with a key of "operation" and a value set to one of the following. Some operations also require other parameters or the message body to be set.

operation message body description

INDEX

Map, String, byte[] or XContentBuilder content to index

Adds content to an index and returns the content’s indexId in the body. You can set the indexId by setting the message header with the key "indexId".

GET_BY_ID

index id of content to retrieve

Retrieves the specified index and returns a GetResult object in the body

DELETE

index name and type of content to delete

Deletes the specified indexName and indexType and returns a DeleteResponse object in the body

DELETE_INDEX

index name of content to delete

Deletes the specified indexName and returns a DeleteIndexResponse object in the body

BULK_INDEX

List or Collection of any type that is already accepted (XContentBuilder, Map, byte[], String)

Adds content to an index and return a List of the id of the successfully indexed documents in the body

BULK

List or Collection of any type that is already accepted (XContentBuilder, Map, byte[], String)

Adds content to an index and returns the BulkResponse object in the body

SEARCH

Map, String or SearchRequest Object

Search the content with the map of query string

MULTIGET

List of MultigetRequest.Item object

Retrieves the specified indexes, types etc. in MultigetRequest and returns a MultigetResponse object in the body

MULTISEARCH

List of SearchRequest object

Search for parameters specified in MultiSearchRequest and returns a MultiSearchResponse object in the body

EXISTS

Index name as header

Checks the index exists or not and returns a Boolean flag in the body

UPDATE

Map, String, byte[] or XContentBuilder content to update

Updates content to an index and returns the content’s indexId in the body.

Index Example

Below is a simple INDEX example

from("direct:index")
.to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
<route>
    <from uri="direct:index" />
    <to uri="elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet"/>
</route>

A client would simply need to pass a body message containing a Map to the route. The result body contains the indexId created.

Map<String, String> map = new HashMap<String, String>();
map.put("content", "test");
String indexId = template.requestBody("direct:index", map, String.class);

For more information, see these resources