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 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
Built Distribution
Close
Hashes for easy_elasticsearch-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a00383e325fd62292b635260e312ac848af1afe95e1e14762bc39c6cefc5e3e1 |
|
MD5 | 15966e5538765a418816f6d22aab23b8 |
|
BLAKE2b-256 | a427aa1de15aa5e438b51035d511f5cc126d29f5b2be308c0b39392e9bab8194 |