-
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
-
Hmmm.
Which search engine are you using, elasticsearch or the database search engine?
What version of FusionAuth are you using?
-
Hey @dan
this seemingly occurs with V1.23.3 and also with V1.17.4.
And with both search engines, database and elasticsearch. -
@malle said in How to search for username with hyphen:
Search for username:test-* -> No search result
Does this work?
Search for username:"test-*" -
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:
test2test2*test2-test2-*test2-ntest2-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-> foundusername:test2*-> foundusername:test2--> foundusername:test2-*-> not foundusername:test2-n-> foundusername: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
-. -
-
Running with quotes works in one case:
username:"test2-*"-> foundusername:"test2-n*"-> not found
-
@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. -
I think the problem is that we are indexing
usernamewith the defaulttextanalyzer which uses a hyphen (-) as a separating character.This means Elasticsearch has indexed
test-goodand found two tokenstestandgood.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 tokentestand a have a second token token that begins withg.Try this strategy and see if it works for you.
-
In the meantime we could implemented it with the mentioned workaround.
Late thanks @robotdan ! -
D dan moved this topic from Q&A on
-
D 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