mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-25 09:28:23 +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
|
client: REST
|
||||||
|
|
||||||
email_search = (
|
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__]
|
+ ES_INDEX_MAP[User.__name__]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class OMetaUserMixin:
|
|||||||
self,
|
self,
|
||||||
email: Optional[str],
|
email: Optional[str],
|
||||||
from_count: int = 0,
|
from_count: int = 0,
|
||||||
size: int = 10,
|
size: int = 1,
|
||||||
fields: Optional[list] = None,
|
fields: Optional[list] = None,
|
||||||
) -> Optional[User]:
|
) -> Optional[User]:
|
||||||
"""
|
"""
|
||||||
|
@ -56,7 +56,13 @@ USER_ELASTICSEARCH_INDEX_MAPPING = textwrap.dedent(
|
|||||||
"type": "text"
|
"type": "text"
|
||||||
},
|
},
|
||||||
"email": {
|
"email": {
|
||||||
"type": "text"
|
"type": "text",
|
||||||
|
"fields": {
|
||||||
|
"keyword": {
|
||||||
|
"type": "keyword",
|
||||||
|
"ignore_above": 256
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"isAdmin": {
|
"isAdmin": {
|
||||||
"type": "text"
|
"type": "text"
|
||||||
|
@ -78,6 +78,10 @@ class OMetaUserTest(TestCase):
|
|||||||
data=CreateUserRequest(name="Levy", email="user2.1234@getcollate.io"),
|
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
|
# Leave some time for indexes to get updated, otherwise this happens too fast
|
||||||
cls.check_es_index()
|
cls.check_es_index()
|
||||||
|
|
||||||
@ -112,6 +116,13 @@ class OMetaUserTest(TestCase):
|
|||||||
self.metadata.get_user_by_email(email="idonotexist@random.com")
|
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
|
# I can get User 1, who has the name equal to its email
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.user_1.id,
|
self.user_1.id,
|
||||||
|
@ -39,7 +39,13 @@
|
|||||||
"type": "text"
|
"type": "text"
|
||||||
},
|
},
|
||||||
"email": {
|
"email": {
|
||||||
"type": "text"
|
"type": "text",
|
||||||
|
"fields": {
|
||||||
|
"keyword": {
|
||||||
|
"type": "keyword",
|
||||||
|
"ignore_above": 256
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"isAdmin": {
|
"isAdmin": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user