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

    How to search for username with hyphen

    Scheduled Pinned Locked Moved Q&A
    10 Posts 0 Posters 6.2k Views
    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.
    • M
      malle
      last edited by

      Hello,
      assume having two users
      test-good
      test-better
      Seemingly the hyphen ist like a special char and won't work with asterisk for like-search.
      You can try this in the web UI:
      Search for username:test -> Users will be found
      Search for username:test* -> Users will be found
      Search for username:test-* -> No search result
      Quoting the hyphen with backslash has no effect. Is there a way to achieve this?

      Thank you and regards

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

        Hmmm.

        Which search engine are you using, elasticsearch or the database search engine?

        What version of FusionAuth are you using?

        --
        FusionAuth - Identity Without Constraints
        https://fusionauth.io

        1 Reply Last reply
        Reply Quote 0
        • M
          malle
          last edited by

          Hey @dan
          this seemingly occurs with V1.23.3 and also with V1.17.4.
          And with both search engines, database and elasticsearch.

          1 Reply Last reply
          Reply Quote 0
          • ?
            A Former User
            last edited by

            @malle said in How to search for username with hyphen:

            Search for username:test-* -> No search result

            Does this work?

            Search for username:"test-*"
            
            1 Reply Last reply
            Reply Quote 0
            • danD
              dan
              last edited by

              Hi @malle ,

              Took some time to dig into this a bit more.

              I have a system which has a user with a username test2-name.

              If I use the database search for this user, all of these return the user:

              • test2
              • test2*
              • test2-
              • test2-*
              • test2-n
              • test2-n*

              Note that you don't put the username: prefix on any database searches.

              If on the other hand I use the elasticsearch search engine, and search for the same user, I see the following:

              • username:test2 -> found
              • username:test2* -> found
              • username:test2- -> found
              • username:test2-* -> not found
              • username:test2-n -> found
              • username:test2-n* -> not found

              I'm not quite sure what's going on with the wildcard causing Elastic to not find the value, but don't think it is related to the -.

              --
              FusionAuth - Identity Without Constraints
              https://fusionauth.io

              1 Reply Last reply
              Reply Quote 0
              • ?
                A Former User
                last edited by

                @dan

                Did you try quoting the value?

                • username:"test2-*"
                • username:"test2-n*"
                1 Reply Last reply
                Reply Quote 0
                • danD
                  dan
                  last edited by

                  Running with quotes works in one case:

                  • username:"test2-*" -> found
                  • username:"test2-n*" -> not found

                  --
                  FusionAuth - Identity Without Constraints
                  https://fusionauth.io

                  M 1 Reply Last reply
                  Reply Quote 0
                  • M
                    malle @dan
                    last edited by

                    @dan
                    username:"test2-n*" -> not found ...so still a problem.
                    And I do not really care about the FusionAuth Web UI, the problem actually is that I use the Java client via UserSearchCriteria ...so it is quoted anyways. Unfortunetally there are already a lot of 'hyphen-user' in the system and adjusting these by taking the hyphen out is not an option.

                    1 Reply Last reply
                    Reply Quote 0
                    • ?
                      A Former User
                      last edited by [[global:former-user]]

                      I think the problem is that we are indexing username with the default text analyzer which uses a hyphen (-) as a separating character.

                      This means Elasticsearch has indexed test-good and found two tokens test and good.

                      Without changing the way this field is indexed, I think you can achieve your desired results by modifying your query.

                      For example, to search for test-g*, you would break this into two parts, and structure your search like this: username:"test" AND username:g*. This will find all usernames that include the token test and a have a second token token that begins with g.

                      Try this strategy and see if it works for you.

                      M 1 Reply Last reply
                      Reply Quote 0
                      • M
                        malle @Guest
                        last edited by

                        In the meantime we could implemented it with the mentioned workaround.
                        Late thanks @robotdan !

                        1 Reply Last reply
                        Reply Quote 0
                        • danD dan moved this topic from Q&A on
                        • danD dan moved this topic from Frequently Asked Questions (FAQ) on

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • First post
                          Last post