drop elastic
This commit is contained in:
@@ -2,29 +2,22 @@ from http import HTTPStatus
|
||||
|
||||
from aws_lambda_powertools.event_handler import Response, content_types
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from elasticsearch import Elasticsearch
|
||||
from elasticsearch_dsl import Search
|
||||
from glom import glom
|
||||
from layercake.funcs import pick
|
||||
from meilisearch import Client as Meilisearch
|
||||
|
||||
from config import ELASTIC_CONN, USER_TABLE
|
||||
from config import MEILISEARCH_API_KEY, MEILISEARCH_HOST, USER_TABLE
|
||||
|
||||
router = Router()
|
||||
elastic_client = Elasticsearch(**ELASTIC_CONN)
|
||||
meili_client = Meilisearch(MEILISEARCH_HOST, MEILISEARCH_API_KEY)
|
||||
|
||||
|
||||
@router.get('/<username>', include_in_schema=False)
|
||||
def lookup(username: str):
|
||||
s = Search(using=elastic_client, index=USER_TABLE).query(
|
||||
'bool',
|
||||
should=[
|
||||
{'term': {'email.keyword': username}},
|
||||
{'term': {'cpf.keyword': username}},
|
||||
],
|
||||
minimum_should_match=1,
|
||||
)
|
||||
r = meili_client.index(USER_TABLE).search(f'"{username}"')
|
||||
|
||||
for hit in s.execute():
|
||||
return pick(('id', 'name', 'email', 'cognito:sub'), hit.to_dict())
|
||||
if user := glom(r, 'hits.0', default=None):
|
||||
return pick(('id', 'name', 'email', 'cognito__sub'), user)
|
||||
|
||||
return Response(
|
||||
content_type=content_types.APPLICATION_JSON,
|
||||
|
||||
Reference in New Issue
Block a user