elasticsearch의 간단한 실천

Elasticsearch, 매우 우수한 분포식 검색 프로그램, 다음은 간단한 응용 방법의 봉인입니다. 여러분께 도움이 되었으면 합니다
#!/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))

좋은 웹페이지 즐겨찾기