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 either start an ES service manually and then indicate the host and port_http; or leave host=None by default to start a docker container itself. 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`, 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 example/quora.py:

python -m easy_elasticsearch.examples.quora

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.5.tar.gz (5.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.5-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: easy-elasticsearch-0.0.5.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13

File hashes

Hashes for easy-elasticsearch-0.0.5.tar.gz
Algorithm Hash digest
SHA256 cd46410b86acabfcc44b51be5977f39f1ae9eef8636223e2d74b8d1490104cba
MD5 8ee12fbe151e033b051f94d54f02e3b5
BLAKE2b-256 7fdedcd8c5e5a07c720a6b130e8c13ae126be2c3bef1d55eee48cf8a31b7a6b4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easy_elasticsearch-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13

File hashes

Hashes for easy_elasticsearch-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3a0c2767bbd56c51508733abec8eda3fd0fd816e3d4928c40d22db1e9d5dd73a
MD5 6950fc5588b7c10ead84cc7adbc73f0a
BLAKE2b-256 de54ad93fac98a354eefcccaae9e0f8f92c80e162a0c9b076dc42c4ff86f7cfb

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