ES入门【python版】

143 阅读1分钟

1. 创建索引

import requests

from datetime import datetime
from elasticsearch import Elasticsearch

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

es = Elasticsearch(es_servers)

# 1. 创建索引
doc_create = {
    'author': 'zbj',
    'text': 'Elasticsearch:cool',
    'timestamp': datetime.now(),
    "settings":{
        "index":{
            "number_of_shards":"2",
            "number_of_replicas":0
        }
    }
}

res = es.index(index="haoke",doc_type='tweet',body=doc_create)