Interaction with elasticsearch in django

I want to use elasticsearch for a new project, and from my research there seem to be 3 viable solutions:

  • Do not use a wrapper and communicate directly with elasticsearch
  • Use elasticsearch-py
  • Using elasticsearch-dsl-py

I like solution 1 because it doesn’t need dependencies, and I can focus on learning the native / api syntax rather than a wrapper like in 2 or 3. Are there any compelling reasons to use 2 or 3 over 1?

Update

I ended up using elasticsearch-py as it offers various benefits such as pooling and persistence. I found elasticsearch-dsl-py too abstract and verbose

+5
source share
1 answer

I would suggest that there is no reason to speak directly with Elasticsearch when the official Python client is available. The Python client does a lot of hard work for you - otherwise you will spend a lot of time and effort converting Python data to ES and vice versa.

Regarding the choice between elasticsearch-dsl-py and elasticsearch-py :

elasticsearch-dsl-py is a wrapper only for Query DSL (plus a few other things). It does not provide access to the entire Elasticsearch API (e.g., Cluster API , Index APIs , Bulk APIs , etc.). The docs say:

To use other Elasticsearch APIs (such as cluster health), simply use the primary client.

It is very likely that you will need to use both libraries in any large application. elasticsearch-dsl-py itself uses elasticsearch-py .

I agree with your comment about Haystack - this Elasticearch backend is poor.

+3
source

Source: https://habr.com/ru/post/1235295/


All Articles