anysearch¶
AnySearch
is a Elasticsearch
and OpenSearch
compatibility library.
It provides utility functions for smoothing over the differences between the
Python libraries with the goal of writing Python code that is compatible on
both (including the *search
and *search-dsl
packages).
See the documentation for more information on what is provided.
Documentation¶
Documentation is available on Read the Docs.
Prerequisites¶
Python 3.6, 3.7, 3.8, 3.9 and 3.10.
Installation¶
Install latest stable version from PyPI:
pip install anysearch
or latest stable version from GitHub:
pip install https://github.com/barseghyanartur/anysearch/archive/main.tar.gz
Configuration¶
AnySearch
automatically detects whether you use Elasticsearch
or
OpenSearch
by looking at which packages are installed.
However, if you have both packages installed, you can instruct AnySearch
which one do you actually want to use. The way to do that is to set the
ANYSEARCH_PREFERRED_BACKEND
environment variable to either
Elasticsearch
or OpenSearch
.
For Elasticsearch
:
import os
os.environ.setdefault("ANYSEARCH_PREFERRED_BACKEND", "Elasticsearch")
For OpenSearch
:
import os
os.environ.setdefault("ANYSEARCH_PREFERRED_BACKEND", "OpenSearch")
Usage¶
elasticsearch
/opensearch
¶
How-to¶
With elasticsearch
you would do:
from elasticsearch import Connection, Elasticsearch
With opensearch
you would do:
from opensearch_py import Connection, OpenSearch
With anysearch
you would change that to:
from anysearch.search import Connection, AnySearch
elasticsearch-dsl
/opensearch-dsl
¶
How-to¶
With elasticsearch-dsl
you would do:
from elasticsearch_dsl import AggsProxy, connections, Keyword
from elasticsearch_dsl.document import Document
With opensearch-dsl
you would do:
from opensearch_dsl import AggsProxy, connections, Keyword
from opensearch_dsl.document import Document
With anysearch
you would change that to:
from anysearch.search_dsl import AggsProxy, connections, Keyword
from anysearch.search_dsl.document import Document
Testing¶
Project is covered with tests.
To test with all supported Python versions type:
tox
To test against specific environment, type:
tox -e py39
To test just your working environment type:
pytest
To run a single test in your working environment type:
pytest test_anysearch.py
To run a single test class in a given test module in your working environment type:
pytest test_anysearch.py::AnySearchTestCase
It’s assumed that you have either elasticsearch-dsl
or opensearch-dsl
installed. If not, install the requirements first.
Writing documentation¶
Keep the following hierarchy.
=====
title
=====
header
======
sub-header
----------
sub-sub-header
~~~~~~~~~~~~~~
sub-sub-sub-header
^^^^^^^^^^^^^^^^^^
sub-sub-sub-sub-header
++++++++++++++++++++++
sub-sub-sub-sub-sub-header
**************************
License¶
MIT
Support¶
For any security issues contact me at the e-mail given in the Author section. For overall issues, go to GitHub.
Documentation¶
Contents:
Release history and notes¶
Sequence based identifiers are used for versioning (schema follows below):
major.minor[.revision]
It’s always safe to upgrade within the same minor version (for example, from 0.3 to 0.3.4).
Minor version changes might be backwards incompatible. Read the release notes carefully before upgrading (for example, when upgrading from 0.3.4 to 0.4).
All backwards incompatible changes are mentioned in this document.
0.2.2¶
2022-12-28
Added more attributes to the
search_dsl
module.Tested against Python 3.11.
Stop testing against Python 3.6 (due to GitHub CI difficulties).
0.2.1¶
2022-07-31
Added some of the missing attributes to the
search_dsl
module.
0.2¶
2022-07-27
Dropped support for
Django
integration packages. Support for bothElasticsearch
andOpenSearch
will either be built in thedjango-elasticsearch-dsl
package or a (rebranded) fork of it.
0.1.7¶
2022-07-26
Improved
elasticsearch-py
/opensearch-py
support.
0.1.6¶
2022-07-25
Documentation fixes.
More tests.
0.1.5¶
2022-07-24
Loosen Python requirements to allow Python 3.6 installations. Note, that although package is not “officially” tested with Python 3.6, it has been tested locally.
0.1.4¶
2022-07-24
Improved Django support.
0.1.3¶
2022-07-22
Better support of
elasticsearch
/opensearch
.
0.1.2¶
2022-07-21
Minor Python 3.7 and 3.8 fixes.
0.1.1¶
2022-07-21
Minor improvements.
Add docs.
0.1¶
2022-07-21
Initial beta release.