[[elasticsearch-component]]
= Elasticsearch Component (deprecated)
:page-source: components/camel-elasticsearch/src/main/docs/elasticsearch-component.adoc

*Available as of Camel version 2.11*


The ElasticSearch component allows you to interface with an
http://elasticsearch.org[ElasticSearch] server.

Maven users will need to add the following dependency to their `pom.xml`
for this component:

[source,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

[source,java]
-------------------------------------
elasticsearch://clusterName[?options]
-------------------------------------


== Endpoint Options



// component options: START
The Elasticsearch component supports 2 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| 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
|===
// component options: END





// endpoint options: START
The Elasticsearch endpoint is configured using URI syntax:

----
elasticsearch:clusterName
----

with the following path and query parameters:

=== Path Parameters (1 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *clusterName* | *Required* Name of cluster or use local for local mode |  | String
|===


=== Query Parameters (11 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| 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
|===
// endpoint options: END
// spring-boot-auto-configure options: START
== Spring Boot Auto-Configuration

When using Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

[source,xml]
----
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-elasticsearch-starter</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>
----


The component supports 3 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *camel.component.elasticsearch.client* | To use an existing configured Elasticsearch client, instead of creating a client per endpoint. The option is a org.elasticsearch.client.Client type. |  | String
| *camel.component.elasticsearch.enabled* | Enable elasticsearch component | true | Boolean
| *camel.component.elasticsearch.resolve-property-placeholders* | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean
|===
// spring-boot-auto-configure options: END


== 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
http://www.elasticsearch.org/guide/reference/java-api/client.html[client
guide] for more details.


== 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.

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|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.
|=======================================================================

== Index Example

Below is a simple INDEX example

[source,java]
-------------------------------------------------------------------------------
from("direct:index")
.to("elasticsearch://local?operation=INDEX&indexName=twitter&indexType=tweet");
-------------------------------------------------------------------------------

[source,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 indexId created.

[source,java]
-------------------------------------------------------------------------
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

http://elasticsearch.org[ElasticSearch Main Site]

http://www.elasticsearch.org/guide/reference/java-api/[ElasticSearch
Java API]