Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interacting with elasticsearch in django

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

  1. Dont use a wrapper and communicate directly with elasticsearch
  2. Use elasticsearch-py
  3. Use elasticsearch-dsl-py

I like solution 1 because it doesn't need dependencies and I can focus on learning the native syntax/api as opposed that of a wrapper as in 2 or 3. Are there any convincing reasons to use 2 or 3 over 1?

Update

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

like image 892
RunLoop Avatar asked Sep 27 '22 07:09

RunLoop


1 Answers

I would suggest that there is no reason to talk directly to Elasticsearch when an official Python client is available. The Python client does a lot of the heavy lifting for you - otherwise you will spend a lot of time/effort in converting Python data to ES and vice versa.

As regards the choice between elasticsearch-dsl-py and elasticsearch-py:

elasticsearch-dsl-py is a wrapper for the Query DSL only (plus a few other things). It doesn't provide access to the whole Elasticsearch API (e.g., Cluster API, Indices API, Bulk API etc.). It says in the docs:

To use the other Elasticsearch APIs (eg. cluster health) just use the underlying client.

It is highly 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 - it's Elasticsearch backend leaves a lot to be desired.

like image 73
solarissmoke Avatar answered Oct 03 '22 15:10

solarissmoke