Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The ElasticSearch component allows you to interface with an ElasticSearch server. Maven users will need to add the following dependency to their pom.xml for this component:

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

URI

...

Format

Code Block
elasticsearch://clusterName[?options]
Tip
clusterNamelocal

if you want to run against a local (in JVM/classloader) ElasticSearch server, just set the the clusterName value in the URI to "local". See the client guide for more details.

...

The following options may be configured on the ElasticSearch endpoint. All are required to be set as either an endpoint URI parameter or as a header (headers override endpoint properties)

12

nameName

descriptionDescription

operationrequired

Required.

The , indicates the operation to perform.

indexName

the The name of the index to act against.

indexType

the The type of the index to act against.

ipthe

From Camel 2.12.
The TransportClient remote host ip IP address to use.

port

From Camel 2.12.

port

the The TransportClient remote port to use (defaults to to 9300).

transportAddresses

From Camel 2.16.


transportAddresses

comma Comma separated list with ipIP:portPORT formatted remote transport addresses to useCamel 2.16

Options IP and PORT Options ip and port must be left blank for for transportAddresses to be considered instead.

consistencyLevel

From Camel 2.16.
The the write consistency level to use with with INDEX and and BULK operations (can be any of ONE, QUORUM, ALL or DEFAULT) .

Can be one of:

  • ONE
  • QUORUM
  • ALL
  • DEFAULT

replicationType

From Camel 2.16.

replicationType

the The replication type to use with with INDEX and and BULK operations (can be any of SYNC, ASYNC or DEFAULT) Camel 2.16From version 2.17 replicationType option has been removed, since from elasticsearch .

Can be one of:

  • SYNC
  • ASYNC
  • DEFAULT
Warning

From Camel 2.17 the option replicationType has been removed, as the async replication was removed in Elasticsearch 2.0.0

the async replication has been removed

.

parent

From Camel 2.16.1 / 2.17.0

Optionally used with optionally used with INDEX operations for Elasticsearch Parent-Child relationships to specify the the ID of the parent recordCamel 2.16.1 / 2.17.0

clientTransportSniff

From Camel 2.17

Define if the client is allowed to sniff the rest of the cluster.

pathHome

From Camel 2.17.2 

Define the path.home property inside settings of ElasticSearch node.  

Default: /usr/share/elasticsearch

Message Operations

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

of retrieves  , types etc. in

operationOperation

message Message body

descriptionDescription

INDEX

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

adds Adds content to an index and returns the content's indexId in the body.

From Camel 2.15,: you can set the the indexId by setting the message header with the key "indexId".

GET_BY_ID

index Index id of content to retrieve.

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

DELETE

index Index id of content to delete.

deletes Deletes the specified specified indexId and returns a DeleteResult object in the body.

BULK_INDEX

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

From Camel 2.14, adds : Adds content to an index and return a List List of the id of id's of the successfully indexed documents in the body.

BULK

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

From Camel 2.15: Adds content to an index and returns the the BulkResponse object in the body.

SEARCH

Map or  or SearchRequest Object object.

From Camel 2.15:

 search

Search the content with

the map of

the Map or query string.

MULTIGET

List

 of MultigetRequest.Item object.

From Camel 2.17:

Retrieves the specified indexes

type's specified in MultigetRequest and returns MultigetResponse object in the body.

MULTISEARCH

List of SearchRequest object.

From Camel 2.17:Search for parameters specified in MultiSearchRequest and returns a MultiSearchResponse

a MultigetResponse

object in the body.

EXISTS

Index name as a header.

From Camel 2.17:Returns

a

Boolean object in the body.

UPDATE

Map, String, byte[]

or

or XContentBuilder

content

 content to update.

From Camel 2.17: Updates content to an index and returns the content'

s

indexId in the body.

Index Example

Below is a simple simple INDEX example:

Code Block
java
java
from("direct:index")
  .to("elasticsearch://local?operation=INDEX&indexName=twitter&indexType=tweet");
Code Block
xml
xml
<route>
    <from uri="direct:index" />
    <to uri="elasticsearch://local?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 the indexId created.:

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

...