elasticsearch의 간단한 실천
2436 단어 pythonelasticsearch테스트 개발
#!/usr/bin/env python#encoding:utf-8from elasticsearch import Elasticsearchimport osimport configparser as cparserfrom builtins import intfrom framework.logger import Loggerfrom utils.rcpUtils import rcpUtils
''''============config를 읽습니다.ini 파일에서 redis 설정 ==========''basedir = str(os.path.dirname(os.path.dirname(file)))
file_path = base_dir + "\config\config.ini"cf = cparser.ConfigParser()cf.read(file_path)host = cf.get("uatesconf", "host")port = cf.get("uatesconf", 'port')logger = Logger(logger="esUtils").getlog()
''''==============봉인es 기본 조작 ===========''
rcp = rcpUtils()
class esUtils:
def __init__(self):
''' , es '''
try:
self.es = Elasticsearch([{'host':host,'port':port}])
logger.info('connect to es sevrver %s:%s successfully!'%(host,port))
except BaseException as e:
logger.exception("Failed to get the es Connection,please check the configuration:%s" %e)
def isClusterUP(self):
''' '''
return self.es.ping()
def getServerInfo(self):
''' , , '''
return self.es.info()
def isExist_table(self,table):
''' ( ) es '''
if self.es.indices.exists(index=table) is True:
return True
else:
return False
def getESInfo(self,index,_id):
''' es , , , es '''
logger.info('Search %s contains %s.' %(index,_id))
params = {
'query': {
'match': {
'_id': _id
}
}
}
_searched = self.es.search(index=index, doc_type=index, body=params)
return _searched['hits']['hits'][0]['_source']
if name == 'main':
es = esUtils()
index = 't_order'
order_id = '8019079610268001'
#system_id = '7b6a99f3bce14915863cde5104bdf2c3'
system_id = '7ecedd704a124a91a0d46ca13bda87c1'
_id = rcp.get_id(system_id, order_id)
print(es.getESInfo(index, _id))
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로마 숫자를 정수로 또는 그 반대로 변환그 중 하나는 로마 숫자를 정수로 변환하는 함수를 만드는 것이었고 두 번째는 그 반대를 수행하는 함수를 만드는 것이었습니다. 문자만 포함합니다'I', 'V', 'X', 'L', 'C', 'D', 'M' ; 문자열이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.