Elasticsearch5 Component

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>

URI format

elasticsearch5://clusterName[?options]

Endpoint Options

The Elasticsearch5 component has no options.

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 (9 parameters):

Name Description Default Type

clientTransportSniff (producer)

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

true

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

port (producer)

The TransportClient remote port to use (defaults to 9300)

9300

int

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

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