废话不多说直接上干货!
# ES相关包
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
class ElasticSearchClient(object): # 启动ES
@staticmethod
def get_es_servers():
es_servers = [{
"host": "localhost",
"port": "9200"
}]
es_client = Elasticsearch(hosts=es_servers)
return es_client
class LoadElasticSearch(object): # 在ES中加载、存储和处理数据
def __init__(self):
#self.index = 'my-index-cleaned' #"my-index-yzm-1"
self.index = "my-index-yzm-1"
#self.doc_type = "test-type" #"test-type-yzm-1"
self.doc_type = "test-type-yzm-1"
self.es_client = ElasticSearchClient.get_es_servers()
self.set_mapping()
def set_mapping(self):
"""
设置mapping