Limit user search fields
I'm using the Java client's
searchUsersByQuerymethod to search for users. As documented, the search is executed across several fields (username, firstname, lastname, etc). Is there a way to limit this search to just the username field? Thanks!
dan last edited by
This depends on which search engine you are using. If you are using the database engine, you can't control the elements you search on. From https://fusionauth.io/docs/v1/tech/core-concepts/users/#user-search
This configuration is lightweight, simplifies installation and system complexity, but comes with the trade offs of limited search capabilities and performance implications.
You can switch your search engine by following the steps in this tutorial: https://fusionauth.io/docs/v1/tech/tutorials/switch-search-engines/
If you are running the elasticsearch engine, there are some examples in the doc. From https://fusionauth.io/docs/v1/tech/apis/users/#request-parameters-13 :
You may search against specific fields like so:
email:*fusionauth.io. This will match only users with a fusionauth.io email address. You may find the available fields for matching by retrieving the Elasticsearch mapping.
In your case, you'd want to use
username:specificusernamefor a match against a single username (
username:*match*to match against any username containing the string
Does this help?
@dan Gotcha! Thanks for pointing that out in the docs. I think for now I will handle limiting the search in my app's business logic because I can't justify the Elasticsearch overhead just yet - but I'll keep the option in mind. Thank you!