我查看了我能找到的关于执行完全匹配、不区分大小写的查询的每一篇文章和帖子,但在实现后,它们并没有执行我正在寻找的内容。
在将此问题标记为重复之前,请阅读整篇文章。
给定一个用户名,我想查询我的 Elasticsearch 数据库以仅返回与用户名完全匹配的文档,但也不区分大小写。
我尝试指定一个lowercase
分析仪为我的username
财产和使用match
查询来实现此行为。虽然这解决了不区分大小写的匹配问题,但它无法精确匹配。
我研究过使用lowercase
标准化器,但这会使我的所有用户名在索引之前变为小写,因此当我聚合用户名时,它们将以小写形式返回,这不是我想要的。我需要保留用户名中每个字母的原始大小写。
我想要的是以下行为:
插入用户
POST {elastic}/users/_doc
{
"email": "[email protected] /cdn-cgi/l/email-protection",
"username": "UsErNaMe",
"password": "1234567"
}
该文档将存储在名为的索引中users
就是这样。
通过用户名获取用户
GET {frontend}/user/UsErNaMe
应该返回
{
"email": "[email protected] /cdn-cgi/l/email-protection",
"username": "UsErNaMe",
"password": "1234567"
}
and
GET {frontend}/user/username
应该返回
{
"email": "[email protected] /cdn-cgi/l/email-protection",
"username": "UsErNaMe",
"password": "1234567"
}
and
GET {frontend}/user/USERNAME
应该返回
{
"email": "[email protected] /cdn-cgi/l/email-protection",
"username": "UsErNaMe",
"password": "1234567"
}
and
GET {frontend}/user/UsErNaMe $RaNdoM LeTteRs
should NOT返回任何东西。
谢谢。