Este contenido no está disponible en el idioma seleccionado.

Chapter 43. ElasticSearch


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>
Copy to Clipboard Toggle word wrap

Camel on EAP deployment

This component is supported by the Camel on EAP (Wildfly Camel) framework, which offers a simplified deployment model on the Red Hat JBoss Enterprise Application Platform (JBoss EAP) container. For details of this model, see chapter "Apache Camel on JBoss EAP" in "Deploying into a Web Server".

URI format

elasticsearch://clusterName?[options]
Copy to Clipboard Toggle word wrap
Tip
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)
Expand
name description
operation Required, indicates the operation to perform.
indexName
The name of the index to act against.
indexType
The type of the index to act against.
ip
The TransportClient remote host IP address to use Camel 2.12.
port
The TransportClient remote port to use (defaults to 9300) Camel 2.12.
transportAddresses
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
Camel 2.16: The write consistency level to use with INDEX and BULK operations (can be any of ONE, QUORUM, ALL or DEFAULT).
replicationType
Camel 2.16: The replication type to use with INDEX and BULK operations (can be any of SYNC, ASYNC or DEFAULT). Camel 2.17: replicationType option has been removed, since from Elasticsearch 2.0.0 the async replication has been removed..
parent
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
Camel 2.17: Specifies whether the client is allowed to sniff the rest of the cluster.

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.
Expand
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.
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[], or 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[], or String)
Camel 2.15, Adds content to an index and returns the BulkResponse object in the body.
SEARCH Map or SearchRequest
Camel 2.15: Search the content with the map of query string.
MULTIGET List of MultigetRequest.Item
Camel 2.17: Retrieves the specified indexes, types etc. in MultigetRequest and returns a MultigetResponse object in the body.
MULTISEARCH List of SearchRequest
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
from("direct:index")
    .to("elasticsearch://local?operation=INDEX&indexName=twitter&indexType=tweet");
Copy to Clipboard Toggle word wrap
<route>
    <from uri="direct:index" />
    <to uri="elasticsearch://local?operation=INDEX&indexName=twitter&indexType=tweet"/>
</route>
Copy to Clipboard Toggle word wrap
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);
Copy to Clipboard Toggle word wrap

Java Example

The following example shows how to use the ElasticSearch component from a Camel route defined in Java:
CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new RouteBuilder() {
    @Override
    public void configure() throws Exception {
        from("direct:index")
          .to("elasticsearch://local?operation=INDEX&indexName=twitter&indexType=tweet");
    }
});

Map<String, String> indexedData = new HashMap<>();
indexedData.put("content", "test");

ProducerTemplate template = camelContext.createProducerTemplate();
template.sendBody("direct:index", indexedData);
Copy to Clipboard Toggle word wrap

For more information, see these resources

Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat