FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    Limit user search fields

    Scheduled Pinned Locked Moved
    Q&A
    2
    3
    2.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tarun.verghis
      last edited by

      I'm using the Java client's searchUsersByQuery method 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!

      1 Reply Last reply Reply Quote 0
      • danD
        dan
        last edited by

        Hiya,

        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:specificusername for a match against a single username (specificusername), or username:*match* to match against any username containing the string match.

        Does this help?

        --
        FusionAuth - Auth for devs, built by devs.
        https://fusionauth.io

        1 Reply Last reply Reply Quote 0
        • T
          tarun.verghis
          last edited by

          @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!

          1 Reply Last reply Reply Quote 2
          • First post
            Last post