用于ElasticSearch的Python客户端

elasticsearch的Python项目详细描述


ElasticSearch的官方低级客户端。它的目标是提供 python中所有与elasticsearch相关的代码的基础;因此它尝试 没有意见,而且很容易扩展。

对于范围更为有限的更高级别客户端库,请查看 elasticsearch-dsl-位于 elasticsearch-py

它提供了一种更方便、更惯用的方式来编写和操作 queries。它与elasticsearch的json dsl很接近,反映了它的 术语和结构,同时公开来自python的dsl的整个范围 直接使用定义的类或类查询集表达式。

它还提供了一个可选的persistence layer用于将文档作为 类似于orm的python对象:定义映射、检索和保存 文档,将文档数据包装到用户定义的类中。

兼容性

库与自0.90.x以来的所有ElasticSearch版本兼容,但是 必须使用匹配的主版本

对于elasticsearch 7.0及更高版本,请使用 图书馆。

对于elasticsearch 6.0及更高版本,请使用 图书馆。

对于elasticsearch 5.0及更高版本,请使用 图书馆。

对于elasticsearch 2.0及更高版本,请使用 图书馆等等。

setup.py中设置需求的推荐方法 requirements.txt是:

# Elasticsearch 7.x
elasticsearch>=7.0.0,<8.0.0

# Elasticsearch 6.x
elasticsearch6>=6.0.0,<7.0.0

# Elasticsearch 5.x
elasticsearch>=5.0.0,<6.0.0

# Elasticsearch 2.x
elasticsearch>=2.0.0,<3.0.0

如果您需要同时安装多个旧版本 版本也发布为elasticsearch2elasticsearch5

安装

使用pip:

安装elasticsearch
pip install elasticsearch

示例使用

简单用例:

>>> from datetime import datetime
>>> from elasticsearch import Elasticsearch

# by default we connect to localhost:9200
>>> es = Elasticsearch()

# create an index in elasticsearch, ignore status code 400 (index already exists)
>>> es.indices.create(index='my-index', ignore=400)
{'acknowledged': True, 'shards_acknowledged': True, 'index': 'my-index'}

# datetimes will be serialized
>>> es.index(index="my-index", id=42, body={"any": "data", "timestamp": datetime.now()})
{'_index': 'my-index',
 '_type': '_doc',
 '_id': '42',
 '_version': 1,
 'result': 'created',
 '_shards': {'total': 2, 'successful': 1, 'failed': 0},
 '_seq_no': 0,
 '_primary_term': 1}

# but not deserialized
>>> es.get(index="my-index", id=42)['_source']
{'any': 'data', 'timestamp': '2019-05-17T17:28:10.329598'}

Full documentation

弹性云(和ssl)用例:

>>> from elasticsearch import Elasticsearch
>>> es = Elasticsearch(cloud_id="<some_long_cloud_id>", http_auth=('elastic','yourpassword'))
>>> es.info()

在自签名证书用例中使用ssl上下文:

>>> from elasticsearch import Elasticsearch
>>> from ssl import create_default_context

>>> context = create_default_context(cafile="path/to/cafile.pem")
>>> es = Elasticsearch("https://elasticsearch.url:port", ssl_context=context, http_auth=('elastic','yourpassword'))
>>> es.info()

功能

客户的功能包括:

  • translating basic Python data types to and from json (datetimes are not decoded for performance reasons)
  • configurable automatic discovery of cluster nodes
  • persistent connections
  • load balancing (with pluggable selection strategy) across all available nodes
  • failed connection penalization (time based - failed connections won’t be retried until a timeout is reached)
  • support for ssl and http authentication
  • thread safety
  • pluggable architecture

许可证

2019 ElasticSearch版权所有

根据apache许可证2.0版(以下简称“许可证”)授权; 除非符合许可证,否则您不能使用此文件。 您可以在

http://www.apache.org/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则软件 根据许可证分发是按“原样”分发的, 无任何明示或默示的保证或条件。 有关管理权限的特定语言和 许可下的限制。

生成状态

https://readthedocs.org/projects/elasticsearch-py/badge/?version=latest&style=flathttps://clients-ci.elastic.co/job/elastic+elasticsearch-py+master/badge/icon

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java允许具有不同父类的类扩展类,而无需多重继承   java如何创建动态化的JScrollPane w/JPanel作为客户端?   java如何组织和命名包   在Java中读取属性文件   java无法解释的Android意图行为   在Java中动态执行多个BPEL文件的部署   ssl Java 6 SNI(服务器名称指示)?   java我们可以使用Robot框架自动化web和移动应用程序来执行并行执行   java for star pettern的循环   java为什么BinaryReader在线程中,从netty读取错误的数据包?   在java中将华氏度转换为摄氏度   使用Spark和java处理空值和引号编写CSV文件   Java中已排序日期到块的列表   visual studio代码VSCode Java不是linting或自动完成局部变量,而是自动完成Java快捷方式,如“sysout”