The [Apache Solr](https://lucene.apache.org/solr/)
[optional component](https://docs.cloud.google.com/managed-spark/docs/concepts/components/overview.md.txt#available_optional_components)
lets you deploy an open source enterprise search platform on Managed Service for Apache Spark clusters. This integration provides distributed search and indexing
capabilities, hosting the Solr server and Web UI on port `8983` on the cluster master nodes.

By default, Solr stores index and transaction log files in
[HDFS](https://hadoop.apache.org/docs/r1.2.1/hdfs_design.html). To persist your
Solr files beyond the cluster lifecycle, you can specify a Cloud Storage path as
the Solr home directory by setting the `dataproc:solr.gcs.path`
[cluster property](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/cluster-properties.md.txt#dataproc-properties)
when you [install the component](https://docs.cloud.google.com/managed-spark/docs/concepts/components/solr.md.txt#install_the_component).

## Install the component

Install the component when you create a Managed Service for Apache Spark cluster.
Components can be added to clusters created with
Managed Service for Apache Spark [version 1.3](https://docs.cloud.google.com/managed-spark/docs/concepts/versioning/dataproc-release-1.3)
and later.

See
[Supported Managed Service for Apache Spark versions](https://docs.cloud.google.com/managed-spark/docs/concepts/versioning/dataproc-versions#supported_cloud_dataproc_versions)
for the component version included in each Managed Service for Apache Spark image release.

### Google Cloud console

1. In the Google Cloud console, open the [**Create cluster**](https://console.cloud.google.com/dataproc/clusters/create) page.
2. Click **Additional configuration** to expand that section.
3. Edit **Optional components**.
4. In the panel that opens, select the checkbox for **Solr** , then click **Save**.

### gcloud CLI

To create a Managed Service for Apache Spark cluster that includes the Solr component,
use the
[gcloud dataproc clusters create](https://docs.cloud.google.com/sdk/gcloud/reference/dataproc/clusters/create.md.txt) <var translate="no">cluster-name</var>
command with the `--optional-components` flag. The sample command below uses the optional `properties`
flag to set a Cloud Storage path as the Solr home directory.

> [!IMPORTANT]
> When creating the cluster, use [gcloud dataproc clusters create](https://docs.cloud.google.com/sdk/gcloud/reference/dataproc/clusters/create.md.txt) command with the `--enable-component-gateway` flag, as shown below, to enable connecting to the Solr Web UI using the [Component Gateway](https://docs.cloud.google.com/managed-spark/docs/concepts/accessing/gateways.md.txt).

```
gcloud dataproc clusters create cluster-name \
    --region=region \
    --optional-components=SOLR \
    --enable-component-gateway \
    ... other flags
```
Add the `--properties="dataproc:solr.gcs.path=gs://bucket-name/"` [cluster property](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/cluster-properties.md.txt#service_properties) to the `gcloud dataproc clusters create` command to set a Cloud Storage bucket where Solr documents will be stored (Solr home directory).

### REST API

The Solr component can be specified through the Dataproc API using
[SoftwareConfig.Component](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/ClusterConfig.md.txt#Component)
as part of a
[clusters.create](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/projects.regions.clusters/create.md.txt)
request.

> [!IMPORTANT]
> As part of your `clusters.create` request, you can:
>
> 1. Set the [EndpointConfig.enableHttpPortAccess](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/ClusterConfig.md.txt#EndpointConfig.description) property to `true` to enable connecting to the Solr Web UI using the [Component Gateway](https://docs.cloud.google.com/managed-spark/docs/concepts/accessing/gateways.md.txt).
> 2. Set the `"dataproc:solr.gcs.path=gs://bucket-name"` [cluster property](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/cluster-properties.md.txt#service_properties) in the [SoftwareConfig.Component.properties](https://docs.cloud.google.com/static/managed-spark/docs/reference/rest/v1/ClusterConfig#SoftwareConfig.FIELDS.properties) field to set a Cloud Storage bucket where Solr documents will be stored (Solr home directory).