이 콘텐츠는 선택한 언어로 제공되지 않습니다.

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

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
ip
the TransportClient remote host ip to use Camel 2.12

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.

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

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat