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

Chapter 135. Solr


Solr Component

Available as of Camel 2.9
The Solr component allows you to interface with an Apache Lucene Solr server (based on SolrJ 3.5.0).
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-solr</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
Copy to Clipboard Toggle word wrap

URI format

The URI format is as follows:
solr://host[:port]/solr?[options]
solrs://host[:port]/solr ?[options]
solrCloud://host[:port]/solr?[options]
Copy to Clipboard Toggle word wrap

Endpoint Options

The following SolrServer options may be configured on the Solr endpoint.
Expand
name default value description
maxRetries 0 maximum number of retries to attempt in the event of transient errors
soTimeout 1000 read timeout on the underlying HttpConnectionManager. This is desirable for queries, but probably not for indexing
connectionTimeout 100 connectionTimeout on the underlying HttpConnectionManager
defaultMaxConnectionsPerHost 2 maxConnectionsPerHost on the underlying HttpConnectionManager
maxTotalConnections 20 maxTotalConnection on the underlying HttpConnectionManager
followRedirects false indicates whether redirects are used to get to the Solr server
allowCompression false server side must support gzip or deflate for this to have any effect
requestHandler /update (xml) set the request handler to be used
streamingThreadCount 2 Camel 2.9.2 set the number of threads for the StreamingUpdateSolrServer
streamingQueueSize 10 Camel 2.9.2 set the queue size for the StreamingUpdateSolrServer
zkhost
null
Camel 2.14.0 set the zoo keeper host information which the solrCloud could use, such as "zkhost=localhost:8123".
collection
null
Camel 2.14.0 set the collection name which the solrCloud server could use

Message Operations

The following Solr operations are currently supported. Simply set an exchange header with a key of SolrOperation and a value set to one of the following. Some operations also require the message body to be set.
Expand
operation message body description
INSERT/INSERT_STREAMING n/a adds an index using message headers (must be prefixed with "SolrField.")
INSERT/INSERT_STREAMING File adds an index using the given File (using ContentStreamUpdateRequest)
INSERT/INSERT_STREAMING SolrInputDocument Camel 2.9.2 updates index based on the given SolrInputDocument
INSERT/INSERT_STREAMING String XML Camel 2.9.2 updates index based on the given XML (must follow SolrInputDocument format)
ADD_BEAN bean instance adds an index based on values in an annotated bean
ADD_BEANS collection<bean> Camel 2.15 adds index based on a collection of annotated bean
DELETE_BY_ID index id to delete delete a record by ID
DELETE_BY_QUERY query string delete a record by a query
COMMIT n/a performs a commit on any pending index changes
ROLLBACK n/a performs a rollback on any pending index changes
OPTIMIZE n/a performs a commit on any pending index changes and then runs the optimize command

Example

Below is a simple INSERT, DELETE and COMMIT example
from("direct:insert")
    .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_INSERT))
    .setHeader(SolrConstants.FIELD + "id", body())
    .to("solr://localhost:8983/solr");

from("direct:delete")
    .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_DELETE_BY_ID))
    .to("solr://localhost:8983/solr");

from("direct:commit")
    .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_COMMIT))
    .to("solr://localhost:8983/solr");
Copy to Clipboard Toggle word wrap
<route>
    <from uri="direct:insert"/>
    <setHeader headerName="SolrOperation">
        <constant>INSERT</constant>
    </setHeader>
    <setHeader headerName="SolrField.id">
        <simple>${body}</simple>
    </setHeader>
    <to uri="solr://localhost:8983/solr"/>
</route>
<route>
    <from uri="direct:delete"/>
    <setHeader headerName="SolrOperation">
        <constant>DELETE_BY_ID</constant>
    </setHeader>
    <to uri="solr://localhost:8983/solr"/>
</route>
<route>
    <from uri="direct:commit"/>
    <setHeader headerName="SolrOperation">
        <constant>COMMIT</constant>
    </setHeader>
    <to uri="solr://localhost:8983/solr"/>
</route>
Copy to Clipboard Toggle word wrap
A client would simply need to pass a message body to the insert route or to the delete route, and then call the commit route.
    template.sendBody("direct:insert", "1234");
    template.sendBody("direct:commit", null);
    template.sendBody("direct:delete", "1234");
    template.sendBody("direct:commit", null);
Copy to Clipboard Toggle word wrap

Querying Solr

Currently, this component doesn't support querying data natively (may be added later). For now, you can query Solr using HTTP as follows:
//define the route to perform a basic query
from("direct:query")
    .recipientList(simple("http://localhost:8983/solr/select/?q=${body}"))
    .convertBodyTo(String.class);
...
//query for an id of '1234' (url encoded)
String responseXml = (String) template.requestBody("direct:query", "id%3A1234");
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