I have looked at every article and post I could find about performing exact-match, case-insensitive queries, but upon implementation, they do not perform what I am looking for.
Before you mark this question as a duplicate, please read the entire post.
Given a username, I want to query my Elasticsearch database to only return a document that exactly matches the username, but is also case insensitive.
I have tried specifying a lowercase
analyzer for my username
property and use a match
query to implement this behavior. While this solves the problem of case insensitive matching, it fails at exact matching.
I looked into using a lowercase
normalizer, but that would make all of my usernames lowercase before indexing, so when I aggregate the usernames, they would return in lowercase form, which is not what I want. I need to preserve the original case of each letter in the username.
What I want is the following behavior:
Inserting Users
POST {elastic}/users/_doc
{
"email": "[email protected]",
"username": "UsErNaMe",
"password": "1234567"
}
This document will be stored in an index called users
exactly the way it is.
Getting a User by Username
GET {frontend}/user/UsErNaMe
should return
{
"email": "[email protected]",
"username": "UsErNaMe",
"password": "1234567"
}
and
GET {frontend}/user/username
should return
{
"email": "[email protected]",
"username": "UsErNaMe",
"password": "1234567"
}
and
GET {frontend}/user/USERNAME
should return
{
"email": "[email protected]",
"username": "UsErNaMe",
"password": "1234567"
}
and
GET {frontend}/user/UsErNaMe $RaNdoM LeTteRs
should NOT return anything.
Thank you.