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#

  1. Create a directory named opensearch, and save the following file as opensearch/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 9200 can read your user data. Use the template on a development machine only.

  2. Start OpenSearch:

    $ docker compose -f opensearch/docker-compose.yml up -d
    
  3. Confirm that OpenSearch responds:

    $ curl http://localhost:9200
    

    OpenSearch returns a JSON document with the cluster name and the version number.

Connect FusionAuth#

  1. Stop FusionAuth. For instructions, see Start and Stop FusionAuth.

  2. Set search.type to elasticsearch, and set search.servers to the URL of OpenSearch. The elasticsearch type works with both OpenSearch and Elasticsearch.

    Add the following lines to fusionauth.properties:

    search.type=elasticsearch
    search.servers=http://localhost:9200
    

    For the location of the file, see Configuration File.

    Set the following environment variables for the FusionAuth process:

    SEARCH_TYPE=elasticsearch
    SEARCH_SERVERS=http://localhost:9200
    

    When FusionAuth runs in a Docker container, localhost points to the container. Use a host name that the container can reach, such as the Docker Compose service name search when both services share a Compose file.

    For every search setting, see the Configuration Reference.

  3. Start FusionAuth.

  4. In the Admin UI, navigate to System -> About . The Search row shows OpenSearch and the OpenSearch version, such as OpenSearch 2.19.8.

  5. When the instance already has Users or Entities, reindex. Navigate to System -> Reindex , set Select an index to User, type REINDEX in Confirm, and click Save . When the instance has Entities, repeat with Entity. 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 failed error 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.