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
- Architecture
- From cluster to replica
- The address of a document
- A query, from question to response
- Why Solr
- In the TDP editions
Watch a document reach the index
Press Play or step through. Underlined names link to the Glossary.
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.
In the Glossary: Document · Node · Field · Request handler
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Architecture
The client talks to any node; each node hosts shard replicas; ZooKeeper coordinates; HDFS can store the files.
What the figure shows:
- The client application indexes and queries over HTTP and sends queries and updates to any node.
- ZooKeeper stores the configuration files and node names, as a record of the cluster topology.
- The nodes: a cluster is made up of nodes, and each node can host several cores.
- The request handler on each node receives queries and updates, which can be sent to any node.
- The replicas: each core is a replica of a shard, with its own index and its own transaction log.
- The leader replica: in each shard, one replica is the leader and forwards updates to the others.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
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 GlossaryIBM— 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.
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.
In the Glossary: Node · Request handler
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
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.
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
| Edition | Version | Documentation |
|---|---|---|
| TDP Datacenter | 8.11.1 | TDP Datacenter components |
In TDP Datacenter
In TDP Datacenter, Solr is the SOLR service, installed and managed by Ambari.
SOLR_SERVER (master, one or more). The SOLR_SERVER requires ZOOKEEPER_SERVER (ZooKeeper). Component category.
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).
Solr runs with ZooKeeper: the connection uses the ZooKeeper quorum and the Solr znode, configurable in solr_znode (solr-env).
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).
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.
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.
Next steps
TDP Datacenter
TDP Datacenter Architecture
The services of the Ambari-managed cluster and how they relate.