5.7 Python API(for Elasticsearch)
来源:互联网 发布:金融数据分析师怎么样 编辑:程序博客网 时间:2024/05/21 21:39
5.7 Python API 原文链接 翻译:AbnerGong
概述(Overview)
正式的初级(low-level)客户端。它的目标是为了所有的Elasticsearch相关的Python代码提供基础;为此(because of this)它尝试成为舆论自由的(opinion-free)以及非常容易扩展。完整文档请见
http://elasticsearch-py.rtfd.org/
其中左侧提供搜索功能,左侧下面Read the Docs中提供PDF/HTML/Epub格式的完整文档下载
Elasticsearch DSL
对于更高级的客户端库有更局限的功能(limited scope),看看elasticsearch-dsl-一个更python化的库坐落在elasticsearch-py之上(on the top of) 。
它提供了更方便和惯用(idiomatic)的方式来写和操作查询。它保持接近Elasticsearch JSON DSL,复用它的术语和结构在搬出(expose)整个范围DSL的时候,或者使用已经定义的类或者是像queryset的表达式
它也提供了可选的persistence layer为了把文档当做Python对象来处理,以ORM一样的风格:定义映射,取回并保存文档,把文档数据包在用户定义的类里。
安装 Installation
pip install elasticsearch
版本 Versioning
有两个分支服务于开发——master
和1.x
,Master分支是用于跟踪Elasticsearch2.0的所有改变并超越,而(whereas)1.x跟踪Elasticsearch1.*.
发行主要版本1(1.X.Y)用于Elasticsearch1.并且后来0.4发行版用于与Elasticsearch 0.90..配合(work with)
推荐在你的setup.py
或requirements.txt
中用如下方法:
# Elasticsearch 2.x elasticsearch>=2.0.0,<3.0.0 # Elasticsearch 1.x elasticsearch>=1.0.0,<2.0.0
使用样例 Example use
>>> from datetime import datetime>>> from elasticsearch import Elasticsearch# by default we connect to localhost:9200>>> es = Elasticsearch()# datetimes will be serialized>>> es.index(index="my-index", doc_type="test-type", id=42, body={"any": "data", "timestamp": datetime.now()}){u'_id': u'42', u'_index': u'my-index', u'_type': u'test-type', u'_version': 1, u'ok': True}# but not deserialized>>> es.get(index="my-index", doc_type="test-type", id=42)['_source']{u'any': u'data', u'timestamp': u'2013-05-12T19:45:31.804229'}
【注意】所有的API调用映射原始的REST api尽可能地接近,包括调用时必须的和可选参数之间的区别。这意味着代码造成了位置和关键字参数之间的区别;我们,然而,为了一致性和安全性,更推荐为所有的调用使用关键字参数。
特点 Features
客户端特点包括:
- 转换基本Python数据类型到或从json类型(datetimes不被解码因为performance的原因)
- 集群节点的可配置的自动发现
- 持久连接
- 在所有的可用节点之间负载均衡(以可插拔(pluggable)的选择策略)
- 失败连接处罚(penalization)(基于时间的 —— 失败的连接直到超时才会再次重试(retried))
- 线程安全
- 可插拔的架构(pluggable architecture)
许可 License
版权2013-2015 Elasticsearch
在Apache许可下被许可,版本2.0(许可); ……………………
- 5.7 Python API(for Elasticsearch)
- Python Elasticsearch api
- Python ElasticSearch API
- ElasticSearch API for JAVA 学习笔记
- ElasticSearch API for JAVA 学习笔记
- Kafka API for Python
- GMail API for Python
- Elasticsearch介绍,单机安装,python 写Elasticsearch API
- python for android : 天气预报 API
- Python API for Yum Apply
- ArcGIS API for Python(一)开始准备环境
- ElasticSearch 菜鸟笔记(三)ElasticSearch 常见REST API 操作
- Elasticsearch 5.x (三) Elasticsearch REST API
- Elasticsearch上手——Python API的简单使用
- Elasticsearch - Java API(与集群交互)
- ElasticSearch Java API(一)连接集群
- ElasticSearch的JAVA 客户端(JAVA API)
- elasticsearch-java api之搜索(一)
- UVA11741 轮廓线动态规划(矩阵加速)
- Delphi在DBGridEh改变选中行颜色
- 棋盘覆盖
- VMware 安装 Ubuntu 12 遇到坑 VMware是什么 不是虚拟机
- Delphi通过查找字符定位TADOQuery数据的位置
- 5.7 Python API(for Elasticsearch)
- 前端布局中的几个常见概念(FC、BFC)
- iOS:手把手教你发布代码到CocoaPods(Trunk方式)
- HDU 4549 M斐波那契数列(矩阵快速幂&费马小定理)
- maven 相关命令记录
- 程序员必须知道的10大基础实用算法及其讲解
- cf#ECR 9-B. Alice, Bob, Two Teams-DP
- 边看书边做边发挥-图书软件-3
- cf#ECR 9-C - The Smallest String Concatenation-水题