Skip to main content

An easy-to-use Elasticsearch BM25 interface

Project description

Easy Elasticsearch

This repository contains a high-level encapsulation for using Elasticsearch with python in just a few lines.

Installation

Via pip:

pip install easy-elasticsearch

Via git repo:

git clone https://github.com/kwang2049/easy-elasticsearch
pip install -e . 

Usage

To utilize the elasticsearch service, one can select from 3 ways:

  • (1) Start an ES service manually and then indicate the host and port_http (please refere to download_and_run.sh);
  • (2) Or leave host=None by default to start a docker container itself;
  • (3) Or leava host=None and setting service_type=executable to download an ES executable and start it in the back end.

Finally, just either call its rank or score function for retrieval or calculating BM25 scores.

from easy_elasticsearch import ElasticSearchBM25

pool = {
    'id1': 'What is Python? Is it a programming language',
    'id2': 'Which Python version is the best?',
    'id3': 'Using easy-elasticsearch in Python is really convenient!'
}
bm25 = ElasticSearchBM25(pool, port_http='9222', port_tcp='9333')  # By default, when `host=None` and `mode="docker"`, a ES docker container will be started at localhost.

query = "What is Python?"
rank = bm25.query(query, topk=10)  # topk should be <= 10000
scores = bm25.score(query, document_ids=['id2', 'id3'])

print(query, rank, scores)
bm25.delete_index()  # delete the one-trial index named 'one_trial'
bm25.delete_container()  # remove the docker container'

Another example for retrieving Quora questions can be found in easy_elasticsearch/examples/quora.py:

python -m easy_elasticsearch.examples.quora  --mode docker

or

python -m easy_elasticsearch.examples.quora  --mode executable

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easy-elasticsearch-0.0.8.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easy_elasticsearch-0.0.8-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file easy-elasticsearch-0.0.8.tar.gz.

File metadata

  • Download URL: easy-elasticsearch-0.0.8.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13

File hashes

Hashes for easy-elasticsearch-0.0.8.tar.gz
Algorithm Hash digest
SHA256 14119ea85a74dede01a567ac99c1c1e432eeb1b56f7e0049c0742146f10e6dd5
MD5 b79d1ffa668cf1e526e8cc2ad5d28049
BLAKE2b-256 d0e2e1bceeb25c4f871830f46af52d79871406ec195b3ef5ebd33b633d29f434

See more details on using hashes here.

File details

Details for the file easy_elasticsearch-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: easy_elasticsearch-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13

File hashes

Hashes for easy_elasticsearch-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7dbcac221f49f13a76b6705735e2631afb4eb72f479adc49917639d9c5a19357
MD5 19c164d43bd70d09ad7ede659ba8084b
BLAKE2b-256 b712c4d8caa6d13ed9d425b85d59517967a61285e0e5df6c8beed30edda0c1ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page