Skip to main content

ht_es

介绍

python es的再封装

主要借鉴SQLAlchemy的方式

使用说明

简单使用

"""
搜索测试工具,数据填充脚本
"""
import random, time
from elasticsearch_tool.elements.document import Doc, Fields
from elasticsearch_tool.base_element.operate import datetime_tool, NOT, OR
from datetime import datetime

from elasticsearch_tool.config import Config


# 配置es服务器地址信息
Config.set_host('localhost', port='9200')


words = ['单词', '词汇', '检索', '我了', '艾克', '维护费', '没理解', '接是', '咯怕', '那么', '行风', '奶茶店', '全网通', '雨天',
         '末尾', '已收到', '就好撒大家看法', '是你们', '你们', '舞女', '不', '容易', '一样', '是你的', '玩儿一天']


def insert_indices():
    text = ''
    word = []
    id = int(time.time() * 1000)
    num = random.randint(000, 999)
    for _ in range(100):
        n = random.randint(0, len(words) - 1)
        text += words[n]
    for _ in range(5):
        n = random.randint(0, len(words) - 1)
        word.append(words[n])

    return {
        'text': text,
        'word': word,
        'id': id,
        'num': num,
        'date': datetime.today(),
        'has_go': num % 2 == 1,
        'height': time.time()
    }


class DocTry(Doc):
    # 配置文档的索引值,类型值,以及文档id的字段
    __indices__ = 'fifth'
    __types__ = 'docs'
    __pk__ = 'id'

    # 设定文档字段和类型
    text = Fields.String
    word = Fields.List
    id = Fields.Integer
    num = Fields.Integer
    date = Fields.Datetime
    has_go = Fields.Boolean
    height = Fields.Float


if __name__ == '__main__':

    for _ in range(15):
        time.sleep(0.01)
        data = insert_indices()
        doc = DocTry()
        for k, v in data.items():
            doc.__setattr__(k, v)

        top = doc.text > 'str'
        nop = doc.num > 20

        doc.save()

    DocTry().search(text='检索').all()
    all_re = DocTry().filter(DocTry.num > 50,
                             DocTry.text=='单词',
                             DocTry.text!='一样',
                             OR(DocTry.text == '知识',
                                DocTry.id > 100,
                                DocTry.word.in_(['你们', '那么', '已收到', '一样']),),
                             NOT(DocTry.has_go == False)).all()
    for result in all_re:
        print(result.query_to_dict())

更多使用方法,请见:

参与贡献

联系642641850@qq.com

Metadata

Release files for elasticsearch-tool 0.9.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for elasticsearch-tool 0.9.9
File Size Uploaded Provenance Actions
elasticsearch_tool-0.9.9.tar.gz 14.5 kB Without provenance Details for elasticsearch_tool-0.9.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for elasticsearch-tool 0.9.9
File Interpreter ABI Platform Actions
elasticsearch_tool-0.9.9-py3-none-any.whl Python 3 none any Details for elasticsearch_tool-0.9.9-py3-none-any.whl

Total release size: 43.0 kB

Release files / elasticsearch_tool-0.9.9.tar.gz

Download URL elasticsearch_tool-0.9.9.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
89a3ee7306e94cd55882d3840f0a996093e507e2b3d773488635352935594a1d
BLAKE2b-256 checksum
How to use checksums
f4ea10282f935cb2ea00816e3a6115ce4c1606ed07cd0e6fa7616a5d86f85b2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

Release files / elasticsearch_tool-0.9.9-py3-none-any.whl

Download URL elasticsearch_tool-0.9.9-py3-none-any.whl
Size 28.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66feeca2cad6c7bf3bd7240ee6eacd4c8f5637a9706104ae679319cc4208329f
BLAKE2b-256 checksum
How to use checksums
6f0eb8428819f396330541814928aea85cc86762edc22c2c7ab42fbd36bf9b91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

Security for elasticsearch-tool 0.9.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page