django-es / django-elasticsearch-dsl

This is a package that allows indexing of django models in elasticsearch with elasticsearch-dsl-py.
Other
1.02k stars 264 forks source link

how to use existing index on elasticsearch in my django rest api directly from the elasticsearch server #247

Open rishi1804 opened 4 years ago

rishi1804 commented 4 years ago

I have some indexes on elasticsearch I want them to use in my API so I don't want to create any model because there already exists a mapping. I know I can get data and print it in my console using elasticsearch_dsl but I m not able to do something like this in API because there I need to serialize the data and create views for that. @safwanrahman @alexgarel please help

alexgarel commented 4 years ago

Hi @rishi1804 I think that if you don't need to link models to indexes, you should better use elasticsearch-dsl (the library, django-elasticsearch-dsl is based upon).

The documentation should be good enough for you to use it.

alexgarel commented 4 years ago

As for connecting it to your REST API, I think it's the job of the framework you use for the API. For example in Django Rest Framework you are free to use generic classes (not model classes) to implement it.

alexgarel commented 4 years ago

https://github.com/barseghyanartur/django-elasticsearch-dsl-drf this may be of interest.

rishi1804 commented 4 years ago

thanks, @alexgarel actually yesterday I tried using elasticsearch_dsl to avoid making models and it's working fine anyway thank you for the help I will definitely go through the links you have provided.