mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-24 08:58:06 +00:00
Fix search by email index keyword (#10698)
* Fix search by email index keyword * Fix search by email index keyword
This commit is contained in:
parent
9f99296ea0
commit
e2a2bcc8da
@ -35,7 +35,7 @@ class OMetaUserMixin:
|
||||
client: REST
|
||||
|
||||
email_search = (
|
||||
"/search/query?q=email:{email}&from={from_}&size={size}&index="
|
||||
"/search/query?q=email.keyword:{email}&from={from_}&size={size}&index="
|
||||
+ ES_INDEX_MAP[User.__name__]
|
||||
)
|
||||
|
||||
@ -44,7 +44,7 @@ class OMetaUserMixin:
|
||||
self,
|
||||
email: Optional[str],
|
||||
from_count: int = 0,
|
||||
size: int = 10,
|
||||
size: int = 1,
|
||||
fields: Optional[list] = None,
|
||||
) -> Optional[User]:
|
||||
"""
|
||||
|
@ -56,7 +56,13 @@ USER_ELASTICSEARCH_INDEX_MAPPING = textwrap.dedent(
|
||||
"type": "text"
|
||||
},
|
||||
"email": {
|
||||
"type": "text"
|
||||
"type": "text",
|
||||
"fields": {
|
||||
"keyword": {
|
||||
"type": "keyword",
|
||||
"ignore_above": 256
|
||||
}
|
||||
}
|
||||
},
|
||||
"isAdmin": {
|
||||
"type": "text"
|
||||
|
@ -78,6 +78,10 @@ class OMetaUserTest(TestCase):
|
||||
data=CreateUserRequest(name="Levy", email="user2.1234@getcollate.io"),
|
||||
)
|
||||
|
||||
cls.user_3: User = cls.metadata.create_or_update(
|
||||
data=CreateUserRequest(name="Lima", email="random.lima@getcollate.io"),
|
||||
)
|
||||
|
||||
# Leave some time for indexes to get updated, otherwise this happens too fast
|
||||
cls.check_es_index()
|
||||
|
||||
@ -112,6 +116,13 @@ class OMetaUserTest(TestCase):
|
||||
self.metadata.get_user_by_email(email="idonotexist@random.com")
|
||||
)
|
||||
|
||||
# Non existing email returns, even if they have the same domain
|
||||
# To get this fixed, we had to update the `email` field in the
|
||||
# index as a `keyword` and search by `email.keyword` in ES.
|
||||
self.assertIsNone(
|
||||
self.metadata.get_user_by_email(email="idonotexist@getcollate.io")
|
||||
)
|
||||
|
||||
# I can get User 1, who has the name equal to its email
|
||||
self.assertEqual(
|
||||
self.user_1.id,
|
||||
|
@ -39,7 +39,13 @@
|
||||
"type": "text"
|
||||
},
|
||||
"email": {
|
||||
"type": "text"
|
||||
"type": "text",
|
||||
"fields": {
|
||||
"keyword": {
|
||||
"type": "keyword",
|
||||
"ignore_above": 256
|
||||
}
|
||||
}
|
||||
},
|
||||
"isAdmin": {
|
||||
"type": "boolean"
|
||||
|
Loading…
x
Reference in New Issue
Block a user