此内容没有您所选择的语言版本。

Chapter 90. 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>

90.1. URI format

elasticsearch://clusterName[?options]

90.2. Endpoint Options

The Elasticsearch component supports 2 options which are listed below.

NameDescriptionDefaultType

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:

90.2.1. Path Parameters (1 parameters):

NameDescriptionDefaultType

clusterName

Required Name of cluster or use local for local mode

 

String

90.2.2. Query Parameters (11 parameters):

NameDescriptionDefaultType

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

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

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

operationmessage bodydescription

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

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

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.

90.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);

90.6. For more information, see these resources

ElasticSearch Main Site

ElasticSearch Java API

90.7. See Also

  • Configuring Camel
  • Component
  • Endpoint
  • Getting Started
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.