Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
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:
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]
elasticsearch://clusterName?[options]
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)
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.
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");
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>
<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);
Map<String, String> map = new HashMap<String, String>();
map.put("content", "test");
String indexId = template.requestBody("direct:index", map, String.class);
Java Example 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The following example shows how to use the ElasticSearch component from a Camel route defined in Java:
For more information, see these resources 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!