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[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)

of the index to act against

name Name

descriptionDescription

operationrequired

Required.

The , indicates the operation to perform.

indexName

the The name of the index to act against.

indexType

The type of the index.

ip

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

port

From Camel 2.12.
The TransportClient remote port to use (defaults to 9300).

transportAddresses

From Camel 2.16.
Comma separated list with IP:PORT formatted remote transport addresses to use.

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

consistencyLevel

From Camel 2.16.
The write consistency level to use with INDEX and BULK operations.

Can be one of:

  • ONE
  • QUORUM
  • ALL
  • DEFAULT

replicationType

From Camel 2.16.
The replication type

to use with INDEX and BULK operations.

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.

parent

From Camel 2.16.1 / 2.17.0

Optionally used with INDEX operations for Elasticsearch Parent-Child relationships to specify the ID of the parent record.

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.

operation Operation

message Message body

descriptionDescription

INDEX

Map of content keys/values, Stringbyte[] 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 indexId by setting the message header with the key "indexId".

GET_BY_ID

index Index id of content to retrieve.

Retrieves the specified index and returns a GetResult object in the body based on the specified indexIdGetResult object in the body.

DELETE

Index id of content to delete.

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

BULK_INDEX

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

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

BULK

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

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

SEARCH

Map or SearchRequest object.

From Camel 2.15: Search the content with 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 a MultigetResponse object in the body.

MULTISEARCH

List of SearchRequest object.

From Camel 2.17: Search for parameters specified in MultiSearchRequest and returns a MultiSearchResponse object in the body.

EXISTS

Index name as a header.

From Camel 2.17: Returns a Boolean object in the body.

UPDATE

Map, Stringbyte[] or XContentBuilder 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);

...

ElasticSearch Main Site

ElasticSearch Java API

Include Page

...

Endpoint See Also

...

Endpoint See Also