vitalik / django-ninja

💨 Fast, Async-ready, Openapi, type hints based framework for building APIs
https://django-ninja.dev
MIT License
7.06k stars 422 forks source link

[Question] Integration with Elasticsearch? #566

Open scheung38 opened 2 years ago

scheung38 commented 2 years ago

Trying to integrate into Django with Elasticsearch

Are there any examples of such usage, as currently I understand its usage from making APIs but not sure within the context of Elasticsearch, how does it work in making queries to Elasticsearch?

vitalik commented 2 years ago

@scheung38 well you can take any library that already integrated with django (like elastic-search-dsl or haystack ) and just use it - usually they return dict-like responses (or querysets ) that you can just return with django-ninja

scheung38 commented 2 years ago

Hi @vitalik. This is the elasticsearch URL to query elasticsearch:

localhost:9200/address*/_search

Screenshot 2022-10-03 at 18 43 39

But the Django-Ninja URL

@api.get("/address*/_search")
def query_all(request: HttpRequest, response: HttpResponse):
    return response

urlpatterns = [
    path('', include(router.urls)),
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),

    path("api/", api.urls),
] 

produces URL: http://127.0.0.1:8000/paf/api/address*/_search'

where my app is called 'paf', so how do we generate an API from within Ninja:

http://127.0.0.1:8000/address*/_search'

instead of the generated URL

i.e without the paf/api as that is not needed in elasticsearch

baseplate-admin commented 1 year ago

Hi @scheung38

So let me get this straight you want to have http://127.0.0.1:8000/address*/_search instead of http://127.0.0.1:8000/paf/api/address*/_search