Search Engines

On this page

FusionAuth uses a search engineThe system that FusionAuth uses to search for Users and Entities: the database, or Elasticsearch with OpenSearch or Elasticsearch. A search engine service is optional. to find Users and Entities in the Admin UI, the User Search API, and the Entity Search API. FusionAuth supports the following search engines:

  • The database search engine runs inside FusionAuth and needs no other service.
  • The Elasticsearch search engine connects to an OpenSearch or Elasticsearch cluster that you run. Despite the name, the Elasticsearch search engine works the same way with OpenSearch.

A search engine service is optional. Login, registration, and every other feature that doesn't search for Users or Entities work the same with either engine. FusionAuth Cloud deployments use the Elasticsearch search engine.

Compare the Search Engines#

Feature Database Elasticsearch
Extra service to run None OpenSearch or Elasticsearch
User and Entity search by Id Yes Yes
Search by queryString Single terms in a few fields Full query string syntax on any indexed field
Search by query (Elasticsearch query DSL) No Yes
Search custom data fields No Yes
Search across Registrations, Group memberships, and Entity grants No Yes
Advanced search in the Admin UI No Yes
Bulk Delete Users API userIds and single-term queryString All parameters
SCIM list Users with a filter No Yes
Page past 10,000 results Yes Yes, with nextResults tokens
Search results after a User changes Immediate After an index refresh, usually about one second

Choose the database search engine for development, embedded installs, and installs that find Users by Id, email address, or name. With a large number of Users, load test the database search engine with your typical searches, because FusionAuth doesn't test that case. Provision the database with enough resources for search.

Choose the Elasticsearch search engine when you need any feature in the Elasticsearch column, or when you search a large number of Users often. For a new install, use OpenSearch 2.x.

Default Search Engine#

The search engine depends on how you install FusionAuth:

  • The Docker install uses the Elasticsearch search engine, and runs OpenSearch in a container.
  • The fusionauth/fusionauth-app Docker image, without a SEARCH_TYPE environment variable, uses the database search engine.
  • The FusionAuth App package and the Fast Path install use the database search engine.
  • The FusionAuth Search package sets the Elasticsearch search engine, and runs Elasticsearch on the same server.

To see the search engine an instance uses, navigate to System -> About in the Admin UI. The Search row shows Database, or the name and version of OpenSearch or Elasticsearch, such as OpenSearch 2.19.8.

The System panel of the About page, showing the search engine.
The System panel of the About page, showing the search engine.

To change the search engine, see Switch Search Engines. For the search settings, see the Configuration Reference.

Database Search Engine#

The database search engine matches a single term against the following User fields:

  • firstName
  • lastName
  • fullName
  • email
  • phoneNumber Available since 1.59.0
  • username

A search matches part of a field, without regard to case. Add a * wildcard to match any characters, including none: *piedpiper matches piedpiper and thepiedpiper. You can put the wildcard anywhere in the term. The database search engine doesn't support regular expressions, ranges, or compound queries. For the Entity fields the engine matches, see the Entity Search API.

Elasticsearch Search Engine#

The Elasticsearch search engine keeps an index of Users and Entities in OpenSearch or Elasticsearch. FusionAuth writes to the index whenever a User or an Entity changes. FusionAuth indexes the following data:

  • Users, with Registrations, Group memberships, and the user.data and registration.data fields. For the field list, see Indexed User Fields.
  • Entities, with grants and the entity.data field. For the field list, see Indexed Entity Fields.

With the index, you can search any indexed field with the full Elasticsearch query string syntax and query DSL. For examples, see Search Users With OpenSearch or Elasticsearch.

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.

To install OpenSearch, see Install a Search Engine. For memory and disk sizing, see System Requirements.

What Uses the Search Engine#

With the Elasticsearch search engine, the following features read from the search engine:

  • The User Search API and the Entity Search API, with queryString, query, or nextResults. A search with ids reads from the database.
  • The Bulk Delete Users API, with queryString or query.
  • SCIM requests that list Users with a filter.
  • User and Entity search in the Admin UI.

The following changes write to the search engine:

  • Creating, updating, and deleting Users, including through the Import Users API.
  • Creating, updating, verifying, and deleting Registrations.
  • Adding Users to Groups and removing Users from Groups.
  • Creating, updating, and deleting Entities.
  • Logins, which update the last login time of the User. FusionAuth writes login times in batches in the background.

Login, passwordless login, and retrieving a User or an Entity by Id don't read from the search engine.

When the Search Engine Is Unavailable#

When OpenSearch or Elasticsearch is down, FusionAuth keeps running, and users can still log in. Other requests behave as follows:

Request Result while the search engine is down
Login and passwordless login Succeeds.
Retrieve a User or an Entity, or search with ids Succeeds.
Search with queryString or query, or Bulk Delete Users Fails with a 503 response.
Create or update a User, or create a Registration Succeeds, but the change doesn't reach the index.
Delete a User, or add a User to a Group Fails with a 503 response. FusionAuth makes no change.
Create, update, or delete an Entity Fails with a 503 response. FusionAuth makes no change.

A failed request returns the [SearchEngineUnavailableException] error code. After the search engine recovers, searches miss the changes that succeeded during the outage. To bring the index up to date, reindex.

A search engine that accepts connections but doesn't respond causes longer delays than one that is down. In testing with an unresponsive OpenSearch node, searches returned the 503 response after 30 seconds, a User update took 60 seconds, and the System Status API took 30 seconds. When User API calls slow down, check the health of the search engine cluster.

Index Delay#

The index is eventually consistent. After a User changes, the change appears in search results once the search engine refreshes the index, usually after about one second. For more information, see Limitations.

To make changes visible to search right away, for example in tests, call the Flush the Search Engine API.

Data Field Types#

FusionAuth provides data fields on many types of objects, including Applications, Tenants, Groups, Users, Registrations, Entities, and Consents.

When you use the Elasticsearch search engine, Elasticsearch indexes the user.data, registration.data, and entity.data fields. Elasticsearch requires a field to have the same data type across all indexed objects. After Elasticsearch indexes a field as one type, Elasticsearch expects every later value of the field to have the same type.

For example, you might store a boolean in user.data.migrated. If you later set user.data.migrated to an object for one User, searches no longer find that User. Searches still find other Users, as long as user.data.migrated holds a boolean or no value.

Keep the data type of each field consistent across objects. FusionAuth doesn't enforce the type, so the software that updates data fields must enforce the type. For the request to add enforcement to FusionAuth, see GitHub issue 1149.

Keep a consistent schema in every data field, even when you use the database search engine:

  • Elasticsearch may index other data fields in future versions of FusionAuth.
  • When you switch from the database search engine to the Elasticsearch search engine, Elasticsearch indexes your existing data. Inconsistent types then hide objects from searches.

Store only valid dates in data fields. Elasticsearch fails to parse a date such as 0000-00-00, which some databases return for an invalid timestamp. Set an invalid date to null instead.

When the types in data fields are inconsistent, searches silently skip objects, and Elasticsearch can throw a MapperParsingException.

Reindex#

A reindex rebuilds the search index from the database. Reindex in the following cases:

  • You switch from the database search engine to the Elasticsearch search engine.
  • You restore FusionAuth from a database backup, or start FusionAuth on a copy of the database.
  • The search engine was unavailable while Users or Entities changed. Changes made during the outage don't reach the index after the search engine recovers, so searches return stale results until you reindex.
  • FusionAuth support asks you to reindex.

To reindex in the Admin UI, navigate to System -> Reindex . Set Select an index to User or Entity, type REINDEX in Confirm, and click Save . The menu item appears only with the Elasticsearch search engine. To reindex from code, call the Rebuild the Elasticsearch Index API, and track progress with the Retrieve the Status of an Index Rebuild API.

Caution

A reindex reads every User and Entity from the database. On a large install, a reindex takes a long time and adds load to the database and the search engine. Run a reindex only when you need one.

Pagination#

Both search engines page through results with startRow and numberOfResults. The Elasticsearch search engine also returns a nextResults token, which pages past the first 10,000 results. For more information, see Pagination and Extended Pagination.