此内容没有您所选择的语言版本。
Chapter 93. Elasticsearch5 Component (deprecated)
Available as of Camel version 2.19
The ElasticSearch component allows you to interface with an ElasticSearch 5.x API.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-elasticsearch5</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
93.1. URI format
elasticsearch5://clusterName[?options]
93.2. Endpoint Options
The Elasticsearch5 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. This allow to customize the client with specific settings. | TransportClient | |
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 Elasticsearch5 endpoint is configured using URI syntax:
elasticsearch5:clusterName
with the following path and query parameters:
93.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
clusterName | Required Name of the cluster | String |
93.2.2. Query Parameters (16 parameters):
Name | Description | Default | Type |
---|---|---|---|
clientTransportSniff (producer) | Is the client allowed to sniff the rest of the cluster or not. This setting map to the client.transport.sniff setting. | false | 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 | ElasticsearchOperation | |
pingSchedule (producer) | The time(in unit) the client ping the cluster. | 5s | String |
pingTimeout (producer) | The time(in unit) to wait for a ping response from a node too return. | 5s | String |
port (producer) | The TransportClient remote port to use (defaults to 9300) | 9300 | int |
tcpCompress (producer) | true if compression (LZF) enable between all nodes. | false | boolean |
tcpConnectTimeout (producer) | The time( in unit) to wait for connection timeout. | 30s | String |
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 | |
waitForActiveShards (producer) | Index creation waits for the write consistency number of shards to be available | 1 | int |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
enableSSL (security) | Enable SSL. Require XPack client jar on the classpath | false | boolean |
password (authentication) | Password for authenticate against the cluster. Require XPack client jar on the classpath | String | |
user (authentication) | User for authenticate against the cluster. Requires transport_client role for accessing the cluster. Require XPack client jar on the classpath | String |
93.3. 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. 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 name and type of content to delete | Deletes the specified indexName and indexType and returns a DeleteResponse object in the body |
DELETE_INDEX | index name of content to delete | Deletes the specified indexName and returns a DeleteIndexResponse object in the body |
BULK_INDEX | a List or Collection of any type that is already accepted (XContentBuilder, Map, byte[], String) | 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) | Adds content to an index and returns the BulkResponse object in the body |
SEARCH | Map, String or SearchRequest Object | Search the content with the map of query string |
MULTIGET | List of MultigetRequest.Item object | Retrieves the specified indexes, types etc. in MultigetRequest and returns a MultigetResponse object in the body |
MULTISEARCH | List of SearchRequest object | Search for parameters specified in MultiSearchRequest and returns a MultiSearchResponse object in the body |
EXISTS | Index name as header | Checks the index exists or not and returns a Boolean flag in the body |
UPDATE | Map, String, byte[] or XContentBuilder content to update | Updates content to an index and returns the content’s indexId in the body. |
93.4. Index Example
Below is a simple INDEX example
from("direct:index") .to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
<route> <from uri="direct:index" /> <to uri="elasticsearch5://elasticsearch?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);
93.5. For more information, see these resources
93.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started