1. 程式人生 > >Python創建ES索引

Python創建ES索引

ref arc %d -i 創建 type ast time etime

# 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索引