ElasticSearch Handler
Project description
exec_es
exec_es 对ElasticSearch进行了二次开发,针对多开发环境数据写入,以及bulk进行了优化。
Installation
1.使用python包管理工具 pip 进行安装。
pip install exec-es
Usage
from execelasticsearch import ExecES, ClientConfig
dt_config = ClientConfig(hosts=[{'host': "172.28.0.1"}])
dp_config = ClientConfig(hosts=[{'host': "172.28.0.2"}], doc_type='your_tags')
es_clients = ExecES(dt=dt_config, dp=dp_config)
index = 'exec_es_test'
hosts = ["dt", "dp"]
def es_create(data_, dex=0):
data_ = data_[dex]
print(es_clients.create(index, data_['id'], data_, hosts))
def es_update(data_, dex=0):
data_ = data_[dex]
data_['account_score'] = 10
print(es_clients.update(index, data_['id'], data_, hosts))
def es_delete(id_):
print(es_clients.delete(index, id_, hosts))
def es_update_or_ignore(data_, dex=0):
data_ = data_[dex]
print(es_clients.update_or_ignore(index, data_['id'], data_, hosts))
def es_upsert(data_, dex=0):
data_ = data_[dex]
print(es_clients.upsert(index, data_['id'], data_, hosts))
def es_bulk_upsert(data_):
data_[0]['account_score'] = 10
print(es_clients.bulk_upsert(index, data_, hosts))
def es_bulk_delete(data_):
ids = [i['id'] for i in data_]
print(es_clients.bulk_delete(index, ids, hosts))
def es_mget(data_, _source_includes=None):
ids = [i['id'] for i in data_]
print(es_clients.mget(index, ids, hosts, _source_includes=_source_includes))
def es_exists(ids: list):
print(es_clients.exists_ids(index, ids, hosts))
search_b = es_clients.search_body
search_b.update(body_type1={"query": {"bool": {"must": {"exists": {"field": "{}"}}}}})
search_b["body_type2"] = {"query": {"bool": {"must": {"exists": {"field": "{}"}}}}}
print(search_b.body_type_list) # show default body_type list
def es_search(body_type= 'exists', body_args: tuple = ('id',)):
res = es_clients.search(index, body_type, body_args, 'dt')
for i in res:
print(i)
def es_original_func():
print(es_clients['dt'].ping())
if __name__ == '__main__':
es_original_func()
Contributing
使用前请做适当的测试,以确定跟您的项目完全兼容。
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
exec-es-0.0.7.tar.gz
(8.2 kB
view details)
Built Distribution
File details
Details for the file exec-es-0.0.7.tar.gz
.
File metadata
- Download URL: exec-es-0.0.7.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 168fd8608da3d3c1c349262ecbdbf9487a364fdf7748e5e3b9bfd1779526036b |
|
MD5 | fe78b901f7127db85ac91f7e3b3381a1 |
|
BLAKE2b-256 | 36e96a96a45ecb3676df0c9603f8fcaa599a7129c5e03ba4c637be4b3b4a53a4 |
File details
Details for the file exec_es-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: exec_es-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cc17bc9c3974a91665fdda647a7db09a50480a574a73aa2ee861338d42f1b61 |
|
MD5 | fac755f99f1f05c96ff1d2b30e23f759 |
|
BLAKE2b-256 | 63f9f1f0382019c1f8ea0b3ad0ac47d92c975224db82cb753a11ee01ddae5a2d |