ElasticSearch 智障 使用模板

from elasticsearch import Elasticsearch from elasticsearch import helpers class ESutill(): def __init__(self,hosts,index,doc_type,body): self.index = index self.body = body self.doc_type = doc_type self.hosts = hosts self.es = Elasticsearch(hosts=self.hosts) if not self.es.indices.exists(index=self.index): self.es.indices.create(index=self.index) self.es.indices.put_mapping(index=self.index,doc_type=self.doc_type,body=self.body) # mapping 示例 """ self.es.indices.put_mapping( index=self.index, doc_type="spider_status", body={ "_all": { "enabled": True #准许动态插入 }, "properties": { "table_name": { "type": "keyword" }, "source": { "type": "keyword" }, "monitoring_time": { "type": "date", "format": "epoch_second" }, "total_count": { "type": "long" }, "new_count": { "type": "long" } } }) """ #批量插入 def put_data(self, inputdata): """ 批量传入数据---写入数据库 :param inputdata: [] 列表数据 :return: 无 """ helpers. [Read More]

python elasticsearch

from elasticsearch import Elasticsearch
from elasticsearch import helpers

class ESutill():
    def __init__(self,hosts,index,doc_type,body):
        self.index = index
        self.body = body
        self.doc_type = doc_type
        self.hosts = hosts
        self.es = Elasticsearch(hosts=self.hosts)
        if not self.es.indices.exists(index=self.index):
            self.es.indices.create(index=self.index)
            self.es.indices.put_mapping(index=self.index,doc_type=self.doc_type,body=self.body)