FusionAuth / fusionauth-issues

FusionAuth issue submission project
https://fusionauth.io
90 stars 12 forks source link

Username field can't be reliably queried using the query param against the User Search resource #602

Closed patrickvalle closed 7 months ago

patrickvalle commented 4 years ago

Username field can't be reliably queried using the query param against the User Search resource

Description

FusionAuth allows for usernames with spaces, but the username field is setup in ElasticSearch as a text field using the standard analyzer. In short, the standard analyzer tokenizes strings using the space character.

This means that I can add a user with the username tiger king into the system, but I won't be able to do any exact match lookups of tiger king using the query param as documented in the User Search API docs.

Is this an intentional decision? What's a prescribed, reliable way for developers to look up multiple users via the username?

Related

trex commented 4 years ago

@patrickvalle that is correct, given that the username field is mapped as a text field, the username field cannot reliably be matched.

Therefor a query string username:'tiger king' may return users with the username tiger king and tiger kong (and other close matches).

Under the current mapping, you would need to make your search request by username to the User Search API, then filter the results in a post-processing operation.

patrickvalle-transloc commented 4 years ago

Thanks for the timely answer @trex, that is helpful information. Does this seem like something that would be changed at some point in the future (in order to support exact matches)? I say this out of ignorance, but it feels like the username should allow for exact matching.

robotdan commented 4 years ago

I think you guys are correct, it seems like we should support exact match on this field.

Does this query work for you? username:"tiger king" (instead of username:'tiger king')

We'll need to do some additional investigation on our end if that is not working for you.

You could also optionally use the User API and retrieve by Login Id which would allow for an exact match lookup by email or username.

Or write a more sophisticated query like username:'tiger king' AND username:'tiger' AND username:'king'.

robotdan commented 8 months ago

Under this issue https://github.com/FusionAuth/fusionauth-issues/issues/2455 - we'll be adding a sub field for username to do exact matching.

andrewpai commented 7 months ago

Note that in 1.49.0, we will support username.exact and fullName.exact fields for more precise searching of these properties.