官方文档来源:http://elasticsearch-py.rtfd.org/ 网站左侧提供PDF的下载
参考博客:(还是google靠谱,能搜出几篇相关文章来)
1. 2015-08-21 http://www.cnblogs.com/letong/p/4749234.html
2. http://rfyiamcool.blog.51cto.com/1030776/1420811
3. 2016-2-22 http://www.jianshu.com/users/2ea4b65c0f30/latest_articles
安装见:http://blog.csdn.net/abnergong/article/details/50776947
用法样例:
from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()
doc = {
'author': 'kimchy',
'text': 'Elasticsearch: cool. bonsai cool.',
'timestamp': datetime.now(),
}
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
print(res['created'])
res = es.get(index="test-index", doc_type='tweet', id=1)
print(res['_source'])
es.indices.refresh(index="test-index")
res = es.search(index="test-index", body={"query": {"match_all": {}}})
print("Got %d Hits:" % res['hits']['total'])
for hit in res['hits']['hits']:
print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])
其中使用前必须的代码是:
from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()
【注意】为了适应Python的生态系统(ecosystem),我们使用from_代替from,doc_type代替type作为变量名
class elasticsearch.Elasticsearch(hosts=None, transport_class=<class ‘elasticsearch.transport.Transport’>, **kwargs)
Elasticsearch低级客户端提供从Python到ES REST端点(endpoint)的直接映射。这个实例(即指es = Elasticsearch())有属性cat, cluster, indices, nodes和snapshot分别提供到CatClient, ClusterClient, IndicesClient, NodesClient and SnapshotClient的实例的访问(即用es.cat表示CatClient的实例),这是更好的也是目前仅支持的访问那些Client的函数方法的途径。
下面的函数是类class elasticsearch.client.IndicesClient(client)的方法。函数func的调用方法为es.indices.func
下面的函数是类class elasticsearch.client.ClusterClient(client)的方法。函数func的调用方法为es.cluster.func
get_settings(flat_settings=True, timeout=1)
health()
pending_tasks()
put_settings
reroute
state
stats
下面的函数是类class elasticsearch.client.NodesClient(client)的方法。
方法名func的调用方法为es.nodes.func()
hot_threads
info
stats
下面的函数是类class elasticsearch.client.CatClient(client)的方法。
方法名func的调用方法为es.cat.func()
aliases
allocation
count
fielddata
health
help
indices
….
thread_pool
下面的函数是类class elasticsearch.client.SnapshotClient(client)的方法。
方法名func的调用方法为es.snapshot.func()