Skip to main content

ElasticSearch Handler

Project description

exec_es

exec_es 对ElasticSearch进行了二次开发,针对多开发环境数据写入,以及bulk进行了优化。

Installation

1.使用python包管理工具 pip 进行安装。

pip install exec-es

Usage

from execelasticsearch.handler import ExecES

choose_config = 0
dt_config = [dict(hosts=[{'host': "172.28.0.1"}]), dict(hosts=[{'host': "172.28.0.1"}], doc_type='tags')][choose_config]
dp_config = [dict(hosts=[{'host': "172.28.0.2"}]), dict(hosts=[{'host': "172.28.0.2"}], doc_type='tags')][choose_config]
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": "{}"}}}}}

def es_search(body_args: tuple = ('id',)):
    res = es_clients.search(index, 'exists', 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

MIT

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

exec-es-0.0.4.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

exec_es-0.0.4-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file exec-es-0.0.4.tar.gz.

File metadata

  • Download URL: exec-es-0.0.4.tar.gz
  • Upload date:
  • Size: 8.0 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

Hashes for exec-es-0.0.4.tar.gz
Algorithm Hash digest
SHA256 37d0170845f6ab85357376b4f063857e06ebfa81d64ad5a305a089efa1d0ad79
MD5 16f67b1079d718940bccb752b8aee516
BLAKE2b-256 f6e53365a4be9d4de5b2069a08685713a5851fa494a91e75f01783dde47ba9ae

See more details on using hashes here.

File details

Details for the file exec_es-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: exec_es-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 2.9 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

Hashes for exec_es-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 279f79dd85180d33267174ccfd03b1c3244c1b8b40aa35a36ed0d714870c5dc1
MD5 e3ca7a731cde22c3daba7c226ca2e8af
BLAKE2b-256 8117a7ade00def1fe14b935f48e008cac4901bdc7b01e93111d98114ca496f34

See more details on using hashes here.

Supported by

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