Install OpenSearch for FusionAuth
On this page
FusionAuth doesn't require a search engine service. Install OpenSearch when you need a feature that the database search engine lacks, such as Elasticsearch queries. For the full list, see Compare the Search Engines.
The Docker install already includes OpenSearch. Follow this guide to add OpenSearch to an install without a search engine, such as a package install.
Prerequisites#
- A FusionAuth instance.
- Docker and Docker Compose on the host that runs OpenSearch. To install OpenSearch without Docker, see the OpenSearch installation guide.
FusionAuth supports OpenSearch 2.x with FusionAuth 1.42.0 and later, and Elasticsearch 7.6.1 through 7.17.x. For a new install, use OpenSearch 2.x. Other versions might work, but FusionAuth doesn't test them.
The memory the search engine needs depends on your login volume and on how many Users and Entities you have. For a few logins per minute and a few thousand Users and Entities, 1GB to 2GB of RAM is enough. For larger installs, run a load test to size the search engine. For more information, see Load Testing.
Install OpenSearch#
-
Create a directory named
opensearch, and save the following file asopensearch/docker-compose.yml:A single-node OpenSearch install for development. services: search: image: opensearchproject/opensearch:2 environment: discovery.type: single-node # development only, see Run OpenSearch in Production DISABLE_INSTALL_DEMO_CONFIG: "true" DISABLE_SECURITY_PLUGIN: "true" bootstrap.memory_lock: "true" OPENSEARCH_JAVA_OPTS: -Xms512m -Xmx512m ulimits: memlock: soft: -1 hard: -1 nofile: soft: 65536 hard: 65536 volumes: - search_data:/usr/share/opensearch/data ports: - 9200:9200 restart: unless-stopped volumes: search_data:The template turns off the OpenSearch security plugin, so anyone who can reach port
9200can read your user data. Use the template on a development machine only. -
Start OpenSearch:
$ docker compose -f opensearch/docker-compose.yml up -d -
Confirm that OpenSearch responds:
$ curl http://localhost:9200OpenSearch returns a JSON document with the cluster name and the version number.
Connect FusionAuth#
-
Stop FusionAuth. For instructions, see Start and Stop FusionAuth.
-
Set
search.typetoelasticsearch, and setsearch.serversto the URL of OpenSearch. Theelasticsearchtype works with both OpenSearch and Elasticsearch.Add the following lines to
fusionauth.properties:search.type=elasticsearch search.servers=http://localhost:9200For the location of the file, see Configuration File.
Set the following environment variables for the FusionAuth process:
SEARCH_TYPE=elasticsearch SEARCH_SERVERS=http://localhost:9200When FusionAuth runs in a Docker container,
localhostpoints to the container. Use a host name that the container can reach, such as the Docker Compose service namesearchwhen both services share a Compose file.For every search setting, see the Configuration Reference.
-
Start FusionAuth.
-
In the Admin UI, navigate to System -> About . The Search row shows
OpenSearchand the OpenSearch version, such asOpenSearch 2.19.8. -
When the instance already has Users or Entities, reindex. Navigate to System -> Reindex , set Select an index to
User, typeREINDEXin Confirm, and click Save . When the instance has Entities, repeat withEntity. FusionAuth copies existing Users and Entities from the database to OpenSearch. Until the reindex finishes, searches miss existing Users and Entities. For more information, see Reindex.
Run OpenSearch in Production#
The template on this page has no security and runs one node. Before you run OpenSearch in production, make the following changes:
- Turn on the OpenSearch security plugin, with TLS and a password. Put the credentials in the URL:
search.servers=https://fusionauth:password@search.example.com:9200. FusionAuth stores the URL in plain text, so protect the configuration the same way you protect the database password. - Use a TLS certificate that FusionAuth trusts. FusionAuth rejects the self-signed demo certificate that OpenSearch generates, and stays in Maintenance Mode with a
PKIX path building failederror in the log. To trust a private certificate authority, see Custom Certificate Authority. - Run three or more nodes, so the cluster survives the loss of a node. For more information, see the OpenSearch cluster formation guide.
- Block access to OpenSearch from the internet. Only FusionAuth nodes need to reach OpenSearch.
- Give OpenSearch enough disk space. OpenSearch makes the index read-only when the disk runs low. For sizing, see System Requirements.
A managed service, such as Amazon OpenSearch Service, handles the nodes, TLS, and backups for you.
FusionAuth can rebuild the index from the database at any time, so you don't need to back up OpenSearch.
Related
Learn about the database and Elasticsearch search engines, which FusionAuth features use each engine, and how to choose one.
Learn how to switch FusionAuth between the database search engine and the Elasticsearch search engine.
API documentation for the Rebuild the Elasticsearch Index API.
Learn how to search for users with queryString and query searches, page through large result sets, and build queries in the Admin UI.