Python创建ES索引

时间:2018-03-02 13:09:25   收藏:0   阅读:441
# pip install elasticsearch
from datetime import datetime
from elasticsearch import Elasticsearch

es_servers = [{
    "host": "10.10.6.225",
    "port": "9200"
}]

es = Elasticsearch(es_servers)

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)

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"])

 

原文:https://www.cnblogs.com/littlehb/p/8492462.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!