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 . 

To get the backend server program as the very last step, one also needs to download official Elasticsearch: (please find the suitable version for your OS if not using Linux x86/64)

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.1-linux-x86_64.tar.gz
tar -xf elasticsearch-7.12.1-linux-x86_64.tar.gz

Usage

Just first create an ElasticSearchBM25 object while indicating the text pool to be indexed and your local path to elasticsearch-xx.xx.xx/bin; then 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, 'elasticsearch-7.12.1/bin')  # remember to use your local path of elasticsearh/bin

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)

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: easy-elasticsearch-0.0.2.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 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.2.tar.gz
Algorithm Hash digest
SHA256 66aa32aef5436a0a3d0bba85a2d38fecc7c097bd8adc84eba10c237cc2e1eef4
MD5 b5864a2293103bf1b44fb340de8fdde2
BLAKE2b-256 71c99eb98813c415fe4ca4f574155daa2e5efaec3e8e0f770f88658127d912cc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easy_elasticsearch-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b019fba8d5125a28e80ebb5d6b65ef5b22bac1ed0eaf470f0a3223dc00af6a3b
MD5 028fc45f9855beccafffb01dbaa01cf5
BLAKE2b-256 97090197a4287b2627e4bd81754812657c0074a2e2c0491936a8efe542f339dc

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