Chapter 92. Elasticsearch Component (deprecated)
Available as of Camel version 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>
92.1. URI format
elasticsearch://clusterName[?options]
92.2. Endpoint Options
The Elasticsearch component supports 2 options which are listed below.
Name | Description | Default | Type |
---|---|---|---|
client (advanced) | To use an existing configured Elasticsearch client, instead of creating a client per endpoint. | Client | |
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 Elasticsearch endpoint is configured using URI syntax:
elasticsearch:clusterName
with the following path and query parameters:
92.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
clusterName | Required Name of cluster or use local for local mode | String |
92.2.2. Query Parameters (11 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 |
consistencyLevel (producer) | The write consistency level to use with INDEX and BULK operations (can be any of ONE, QUORUM, ALL or DEFAULT) | DEFAULT | WriteConsistencyLevel |
data (producer) | Is the node going to be allowed to allocate data (shards) to it or not. This setting map to the node.data setting. | 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 | String | |
pathHome (producer) | The path.home property of ElasticSearch configuration. You need to provide a valid path, otherwise the default, $user.home/.elasticsearch, will be used. | ${user.home}/.elasticsearch | String |
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 | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
92.3. Local testing
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.
92.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.
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. Camel 2.15, 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 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 (XContentBuilder, Map, byte[], String) | *Camel 2.14,*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) | Camel 2.15: Adds content to an index and returns the BulkResponse object in the body |
SEARCH | Map or SearchRequest Object | Camel 2.15: search the content with the map of query string |
MULTIGET | List of MultigetRequest.Item object | Camel 2.17: retrieves the specified indexes, types etc. in MultigetRequest and returns a MultigetResponse object in the body |
MULTISEARCH | List of SearchRequest object | Camel 2.17: search for parameters specified in MultiSearchRequest and returns a MultiSearchResponse object in the body |
EXISTS | Index name as header | Camel 2.17: Returns a Boolean object in the body |
UPDATE | Map, String, byte[] or XContentBuilder content to update | Camel 2.17: Updates content to an index and returns the content’s indexId in the body. |
92.5. 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);
92.6. For more information, see these resources
92.7. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started