码迷,mamicode.com
首页 > 编程语言 > 详细

Python创建ES索引

时间:2018-03-02 14:53:52      阅读:1839      评论:0      收藏:0      [点我收藏+]

标签:blog   bsp   last   query   install   rom   color   time   ref   

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

 

Python创建ES索引

标签:blog   bsp   last   query   install   rom   color   time   ref   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!