Skip to main content

Full-text search over large volumes,
with indexes distributed across the cluster.

Solr is a search server that indexes documents and answers queries, from simple keyword searches to multi-field queries with results organized into facets. The index is divided into shards and replicas, coordinated by ZooKeeper, to scale beyond a single machine. Follow a document into the index and a query to its response.

Apache Solr is a search server built on top of Apache Lucene that stores documents in a searchable index and, in SolrCloud, distributes that index across shards and replicas.

Queries and updates reach any node in the cluster over HTTP.

Search

From keyword to complex query

The query syntax and parsers range from simple keyword search to queries on multiple fields, with results organized into facets.

Scale

Indexes that split and replicate

When a single machine cannot handle the data or the queries, the index is divided into shards and replicated, for performance and reliability.

Interfaces

HTTP, JSON and XML

Queries are simple HTTP requests, and the response is a structured document, usually JSON. Any platform capable of HTTP can talk to Solr.

On this page

Watch a document reach the index​

Press Play or step through. Underlined names link to the Glossary.

ZooKeeperConfiguration and topology
ZooKeeperStores the cluster topology
ClientApplication that indexes
DocumentFields with a name and content
Solr nodesReceive and forward
NodeReceives the update
Leader replicaOf the document's shard
Other replicasOf the same shard
Inside the replicaWhere the document is stored
AnalysisOf each field's text
Transaction logRecord of the writes
IndexTerms and documents
Step 1 of 7

1 The client sends the document

A document is a set of fields, each with a name and content. The client sends it over HTTP to any node in the cluster, and the update request handler processes the request.

  1. The client sends the document. A document is a set of fields, each with a name and content. The client sends it over HTTP to any node in the cluster, and the update request handler processes the request.
  2. The node consults ZooKeeper. The node uses the information in ZooKeeper to find out which servers must handle the request: it first determines which shard the document belongs to and then which node hosts that shard's leader.
  3. The document goes to the leader. The document is forwarded to the shard leader, which forwards it to all the other replicas. If the leader goes down, one of the other replicas is automatically elected in its place.
  4. Analysis builds the terms. If the field is defined in the schema, the analysis associated with it is applied to the content when the text is broken into tokens. It can, for example, convert all words to lowercase and strip accent marks, so that a search for ketchup also finds Ketchup.
  5. The transaction log records the write. Each replica keeps a transaction log, an append-only record of write operations. If indexing is interrupted, it makes it possible to replay the updates that had not yet been committed.
  6. The index receives the document. The terms enter the index, which lists each word and the documents that contain it, like the index at the back of a book, which lists words and the pages where they appear.
  7. The commit makes the document searchable. After a commit, the added document can be searched. In SolrCloud, it is usually automatic commits that make updates visible, rather than commits sent by the client. Documents become searchable at nearly the same time on the replicas, but without strict guarantees.
Figure 1 - Indexing a document in SolrCloud. The node that receives the document finds out from ZooKeeper where the shard leader is, and the leader writes the document and forwards it to the other replicas.

Architecture​

The client talks to any node; each node hosts shard replicas; ZooKeeper coordinates; HDFS can store the files.

Apache Solr architecture: client, Solr nodes with shards and replicas, ZooKeeper and HDFSThe client sends queries and updates over HTTP to any Solr node, where the request handler receives them. Each node hosts cores, and each core is a replica of a shard, with its own index and transaction log. In each shard, one replica is the leader and forwards updates to the others. ZooKeeper stores the cluster configuration and topology, and the index and transaction log files can be kept on HDFS.Client applicationIndexes and queries over HTTPZooKeeperCluster configuration and topologySolr nodeRequest handlerLeader replicaof shard 1Index and transaction logSolr nodeRequest handlerReplicaof shard 1Index and transaction logLeader replicaof shard 2Index and transaction logSolr nodeRequest handlerReplicaof shard 2Index and transaction logHDFSIndex and transaction log files, when Solr uses HDFSQuery or updateThe leader forwards the update to the replicasCoordination by ZooKeeperFiles on HDFS
Figure 2 - Solr architecture: client, nodes with replicas of two shards, ZooKeeper and HDFS. The example shows one shard per row, with the leader replica forwarding updates. Underlined terms link to the Glossary.

What the figure shows:

  1. The client application indexes and queries over HTTP and sends queries and updates to any node.
  2. ZooKeeper stores the configuration files and node names, as a record of the cluster topology.
  3. The nodes: a cluster is made up of nodes, and each node can host several cores.
  4. The request handler on each node receives queries and updates, which can be sent to any node.
  5. The replicas: each core is a replica of a shard, with its own index and its own transaction log.
  6. The leader replica: in each shard, one replica is the leader and forwards updates to the others.
  7. HDFS: Solr is also able to write the index and transaction log files to it.

From cluster to replica​

From the broadest level to the most concrete: each level contains the next.

Level 1 of 5

Cluster

A set of Solr nodes that operate in coordination through ZooKeeper and are managed as a unit. A cluster can contain several collections.

  • NodeA running instance of the Solr server. Each node can host several cores.
  • ZooKeeperStores the cluster's configuration files and node names, and is the topology registry.
  1. Cluster. A set of Solr nodes that operate in coordination through ZooKeeper and are managed as a unit. A cluster can contain several collections.
    • Node. A running instance of the Solr server. Each node can host several cores.
    • ZooKeeper. Stores the cluster's configuration files and node names, and is the topology registry.
  2. Collection. One or more documents grouped into a single logical index, with a single configuration and a single schema. The number of shards defines the collection's theoretical document limit and the parallelism possible in a query.
    • Schema. Defines the fields to index and the type of each one, and with that how Solr builds the index from the documents.
    • Document. The basic unit of information: a set of fields, each with a name and content.
  3. Shard. A logical partition of the collection, with a subset of the documents: each document lives in exactly one shard. Each shard has at least one physical replica.
    • Routing prefix. The initial part of the document ID, whose hash selects the shard.
  4. Replica (core). A core that is a physical copy of the shard. All replicas of a collection use its configuration, and the number of replicas per shard defines the cluster's redundancy and fault tolerance.
    • Leader. The shard replica that coordinates updates and forwards them to the others. It is chosen by election.
    • Core. An individual Solr instance, which represents a logical index.
    • Transaction log. The append-only record of the replica's writes.
  5. Index. The replica's inverted index: it lists each word and the documents that contain it. A query first finds the term and then the document.
    • Analyzer. The chain that turns a field's text into the terms that enter the index.
    • Commit. The operation that makes changes permanent and makes the added documents searchable.
Figure 3 - The levels of a Solr cluster. The terms beside each level go with that level.

Replicas come in three types: NRT, which keeps the transaction log and indexes locally, TLOG, which keeps the log but copies the index from the leader, and PULL, which only copies the index from the leader and cannot become a leader.

Without an indication at creation, the replica is NRT. See Replica.

The address of a document​

In Solr, a document's ID can carry a prefix that decides which shard it lands on. In the example, the documents of a single customer stay together.

Click each part of the ID.

Routing prefix

Used to compute the hash that Solr uses to choose the shard in which the document is indexed. To keep a customer's documents together, the customer name or ID can be used as the prefix. The exclamation mark separates the prefix from the rest of the ID.

See in the Glossary
IBM — Routing prefix
Used to compute the hash that Solr uses to choose the shard in which the document is indexed. To keep a customer's documents together, the customer name or ID can be used as the prefix. The exclamation mark separates the prefix from the rest of the ID.
12345 — Document ID
The document's unique identifier, analogous to a database primary key. When there is no need to influence how documents are stored, no prefix is required.

In a query, the route parameter directs the search only to the prefix's shards, which can improve performance by avoiding the network latency of querying all shards.

The compositeId router, the default, accepts prefixes with more than one level, such as region and then customer: USA!IBM!12345.

A query, from question to response​

Any node receives the query. One replica aggregates the responses from all shards.

ClientApplication that queries
ClientSends the query over HTTP
Node and aggregator replicaReceive and gather
NodeReceives the query
Chosen replicaAggregates the responses
Shard replicasEach with its own index
Shard 1 replicaSearches the index
Shard 2 replicaSearches the index
Step 1 of 7

1 The client sends the query

The query is an HTTP request to a request handler, whose name goes in the request, usually as a path. The q parameter carries the search terms.

  1. The client sends the query. The query is an HTTP request to a request handler, whose name goes in the request, usually as a path. The q parameter carries the search terms.
  2. The query parser reads the terms. The query parser processes the terms typed by the user. Solr's syntax and parsers range from simple keyword search to complex queries on multiple fields.
  3. The request goes to a replica. When a node receives a query, it is forwarded, behind the scenes, to a replica of a shard of the queried collection.
  4. The chosen replica asks all shards. That replica acts as an aggregator: it creates internal requests to randomly chosen replicas of each shard in the collection. A query without the shards parameter applies to all shards.
  5. Each shard searches the index. Each replica queries its own index, which lists each word and the documents that contain it, and returns what it found to the aggregator. Finding the term first and then the document saves processing and time.
  6. The aggregator builds the response. The aggregator coordinates the responses, issues any additional internal requests that are needed, for example to refine facet values or to request extra stored fields, and builds the final response for the client.
  7. The response returns to the client. The response is a structured document, usually a list of document descriptors, and the default format is JSON. It can also be XML, CSV or optimized binary, through response writers.
Figure 4 - A query in SolrCloud. The request goes to a replica of a shard of the collection, which forwards it to a replica of each shard, gathers the responses and returns the final response to the client.

Why Solr​

Search

From keyword to complex query

The query syntax and parsers range from simple search to queries on multiple fields, with faceted results.

Relevance

Configurable text analysis

Solr provides access to nearly all of Lucene's text analysis features, such as tokenization, stemming and synonyms, to tune relevance to what is known about the users and the domain.

Scale

Shards and replicas

Indexes can be split and replicated for performance and reliability, using ZooKeeper to coordinate cluster activities.

Availability

Automatic failover

Queries have automatic load balancing and failover, and, if a shard leader goes down, another replica is elected in its place.

Open interfaces

HTTP and multiple formats

JSON is the default response format, and XML, CSV and optimized binary are also possible. Client APIs exist for the common programming languages.

Ingestion

Data from many sources

The index accepts data from JSON, XML and CSV files, from database tables and from common files, such as Word and PDF, the latter through Solr Cell, built on Apache Tika.

Where it comes from

Solr is a search server built on top of Apache Lucene, an open source information retrieval library. It is open source software under the Apache 2.0 license, designed for extensibility.

In the TDP editions​

Available in the TDP editions
EditionVersionDocumentation
TDP Datacenter8.11.1TDP Datacenter components

In TDP Datacenter​

In TDP Datacenter, Solr is the SOLR service, installed and managed by Ambari.

Service components

SOLR_SERVER (master, one or more). The SOLR_SERVER requires ZOOKEEPER_SERVER (ZooKeeper). Component category.

Where the data lives

The stack configures Solr to write the index and the transaction log to HDFS, from a root that is configurable in solr_hdfs_home_dir. The Solr directory on the machine, where Solr creates the index files, is configurable in solr_datadir (solr-env).

Coordination

Solr runs with ZooKeeper: the connection uses the ZooKeeper quorum and the Solr znode, configurable in solr_znode (solr-env).

Process

The Solr user, port, JMX port and log directory are configurable in solr_user, solr_port, solr_jmx_port and solr_log_dir, and the JVM minimum and maximum memory in solr_minmem and solr_maxmem (solr-env).

Security

SSL can be enabled in solr_ssl_enabled, with the keystore and truststore files in solr_keystore_location and solr_truststore_location. With the cluster under Kerberos, the service principal and keytab are configurable in solr_kerberos_principal and solr_kerberos_keytab, and those of the web interface in solr_web_kerberos_principal and solr_web_kerberos_keytab.

Authorization

The Ranger plugin can be enabled in ranger-solr-plugin-enabled, and the Solr authorizer class is configurable in authorizer.class.name (solr-env). See Security in TDP Datacenter.

Dependencies

Ambari requires in the cluster ZooKeeper and HDFS.

Who uses it

Superset has the sqlalchemy-solr driver installed, and NiFi has the nifi-solr-nar for ingestion into Solr.

Next steps​

Sources​

Apache Solr

Apache Solr - Reference Guide

Apache Solr - Features

Apache Lucene