You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Solr Component

Available as of Camel 2.9

The Solr component allows you to interface with an Apache Lucene Solr 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-solr</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

solr://host[:port]/solr?[options]

Endpoint Options

The following SolrServer options may be configured on the Solr endpoint.

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

true

server side must support gzip or deflate for this to have any effect

requestHandler

/update (xml)

set the request handler to be used

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.

operation

message body

description

INSERT

n/a

insert a new record based on headers values (headers must be prefixed with "SolrField.")

ADD_BEAN

bean instance

insert a new record based on values in an 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 example in Java and Spring XML.

from("direct:start")
    .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_INSERT))
    .setHeader(SolrConstants.FIELD + "id", body())
    .to("solr://localhost:8983/solr");
<route>
    <from uri="direct:start"/>
    <setHeader headerName="SolrOperation">
        <constant>INSERT</constant>
    </setHeader>
    <setHeader headerName="SolrField.id">
        <simple>${body}</simple>
    </setHeader>
    <to uri="solr://localhost:8983/solr"/>
</route>

A client would simply need to pass a body message to this route as follows.

    template.sendBody("direct:start", "value1");

Querying Solr

Currently, this component doesn't support querying data (will be added later). For now, you can query Solr in a route using HTTP.

TODO: add a simple example to retrieve the data inserted above.

For more information, see these resources...

Solr Query Tutorial

Solr Query Syntax

  • No labels