ElasticSearch Component
Available as of Camel 2.11
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:
<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
elasticsearch://clusterName[?options]
if you want to run against a local (in JVM/classloader) ElasticSearch server, just set the clusterName
value in the URI to local
. See the client guide for more details.
Endpoint Options
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)
Name | Description |
---|---|
| Required. The operation to perform. |
| The name of the index. |
| The type of the index. |
| From Camel 2.12. |
| From Camel 2.12. |
| From Camel 2.16. Options |
| From Camel 2.16. Can be one of:
|
| From Camel 2.16. Can be one of:
From Camel 2.17 the option |
| From Camel 2.16.1 / 2.17.0 Optionally used with |
| From Camel 2.17 Define if the client is allowed to sniff the rest of the cluster. |
| From Camel 2.17.2 Define the Default: |
Message Operations
The following ElasticSearch operations are currently supported. Simply set an endpoint URI option or an exchange header with 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 | Message body | Description |
---|---|---|
|
| Adds content to an index and returns the content's From Camel 2.15: you can set the |
| Index id of content to retrieve. | Retrieves the specified index and returns a |
| Index id of content to delete. | Deletes the specified |
| A | From Camel 2.14: Adds content to an index and return a |
| A | From Camel 2.15: Adds content to an index and returns the |
|
| From Camel 2.15: Search the content with the |
|
| From Camel 2.17: Retrieves the specified indexes type's specified in |
|
| From Camel 2.17: Search for parameters specified in |
| Index name as a header. | From Camel 2.17: Returns a |
|
| From Camel 2.17: Updates content to an index and returns the content's |
Index Example
Below is a simple INDEX
example:
from("direct:index") .to("elasticsearch://local?operation=INDEX&indexName=twitter&indexType=tweet");
<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 indexId
created:
Map<String, String> map = new HashMap<String, String>(); map.put("content", "test"); String indexId = template.requestBody("direct:index", map, String.class);