Chapter 94. Elasticsearch5 Component (deprecated)


Available as of Camel version 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>

94.1. URI format

elasticsearch5://clusterName[?options]

94.2. Endpoint Options

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

NameDescriptionDefaultType

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:

94.2.1. Path Parameters (1 parameters):

NameDescriptionDefaultType

clusterName

Required Name of the cluster

 

String

94.2.2. Query Parameters (16 parameters):

NameDescriptionDefaultType

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

94.3. Spring Boot Auto-Configuration

The component supports 3 options, which are listed below.

NameDescriptionDefaultType

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

94.4. 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.

operationmessage bodydescription

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

a 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

a 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.

94.5. 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);

94.6. For more information, see these resources

Elastic Main Site

ElasticSearch Java API

94.7. See Also

  • Configuring Camel
  • Component
  • Endpoint
  • Getting Started
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.