圆月山庄资源网 Design By www.vgjia.com
#!/usr/bin/env python # -*- coding:utf-8 -*- # ************************************* # @Time : 2019/8/12 # @Author : Zhang Fan # @Desc : Library # @File : MyDatabases.py # @Update : 2019/8/23 # ************************************* import elasticsearch import phoenixdb import pysolr import pymysql class MyELS(object): """ =================================================================== ===================== MyELS ========================= =================================================================== """ def __init__(self): self.els_conn = None def connect_to_els(self, host, port): """ 连接到ElasticSearch服务器. """ self.els_conn = elasticsearch.Elasticsearch([{'host': host, 'port': port}]) print('Executing : Connect To Elastic Search | %s' % self.els_conn) def get_els_data(self, query, index): """ 获取ElasticSearch数据 """ print('Executing : Search | %s' % query) try: rst = self.els_conn.search(index=index, q=query) return rst['hits'] except Exception as e: print('Elastic Search Error | %s' % e) raise Exception(e) class MyPhoenix(object): """ =================================================================== ===================== MyPhoenix ====================== =================================================================== """ def __init__(self): self.phoenix_conn = None self.phoenix_cursor = None def connect_to_phoenix(self, host, port=8765): """ 连接到phoenix服务器 """ address = 'http://{0}:{1}/'.format(host, port) print('Executing : Connect To Phoenix | %s' % address) self.phoenix_conn = phoenixdb.connect(address, autocommit=True) self.phoenix_cursor = self.phoenix_conn.cursor() def set_schema(self, sql, schema): """ 设置schema """ pre_sub, sub, fol_sub = sql.upper().partition('FROM') fol_sub = ' ' + schema + '.' + fol_sub.strip() new_sql = ''.join([pre_sub, sub, fol_sub]) return new_sql def execute_phoenix_sql(self, sql): """ 执行sql语句 """ # sql = self.set_schema(sql, schema) print('Executing : Execute | %s' % sql) self.phoenix_cursor.execute(sql) def get_from_phoenix(self, sql): """ 获取phoenix数据 """ # sql = self.set_schema(sql, schema) print('Executing : Query | %s' % sql) try: self.phoenix_cursor.execute(sql) except Exception as e: print('Phoenix Error | %s' % e) raise Exception(e) return self.phoenix_cursor.fetchall() def disconnect_from_phoenix(self): """ 断开phoenix连接 """ print('Executing : Disconnect From HBase') self.phoenix_cursor.close() self.phoenix_conn.close() class MySolr(object): """ =================================================================== ===================== MySolr ========================= =================================================================== """ def __init__(self): self.solr_conn = None self.base_url = None def connect_to_solr(self, address, selector): """连接到solr服务器. """ self.base_url = 'http://{0}/solr/{1}/'.format(address, selector) self.solr_conn = pysolr.Solr(self.base_url) print('Executing : Connect To Solr | %s' % self.base_url) def get_solr_data(self, query): """ 获取solr数据 """ results = list() print('Executing : Search | %s' % query) try: items = self.solr_conn.search(query) for item in items: results.append(item) except Exception as e: print('Solr Error | %s' % e) raise Exception(e) return results def add_solr_data(self, data): """ 添加solr数据 """ print('Executing : add | %s' % data) try: self.solr_conn.add([data]) self.solr_conn.commit() except Exception as e: print('Solr Error | %s' % e) raise Exception(e) def del_solr_byId(self, data): """ 删除solr数据 """ print('Executing : del | %s' % data) try: self.solr_conn.delete(id=data) self.solr_conn.commit() except Exception as e: print('Solr Error | %s' % e) raise Exception(e) if __name__ == '__main__': print('This is test.') ms = MySolr() me = MyELS() mp = MyPhoenix()
以上就是Python 调用 ES、Solr、Phoenix的示例代码的详细内容,更多关于Python 调用 ES、Solr、Phoenix的资料请关注其它相关文章!
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
更新日志
2024年11月01日
2024年11月01日
- 孟庭苇《情人的眼泪》开盘母带[低速原抓WAV+CUE]
- 孙露《谁为我停留HQCD》[低速原抓WAV+CUE][1.1G]
- 孙悦《时光音乐会》纯银CD[低速原抓WAV+CUE][1.1G]
- 任然《渐晚》[FLAC/分轨][72.32MB]
- 英雄联盟新英雄安蓓萨上线了吗 新英雄安蓓萨技能介绍
- 魔兽世界奥杜尔竞速赛什么时候开启 奥杜尔竞速赛开启时间介绍
- 无畏契约CGRS准星代码多少 CGRS准星代码分享一览
- 张靓颖.2012-倾听【少城时代】【WAV+CUE】
- 游鸿明.1999-五月的雪【大宇国际】【WAV+CUE】
- 曹方.2005-遇见我【钛友文化】【WAV+CUE】
- Unity6引擎上线:稳定性提升、CPU性能最高提升4倍
- 人皇Sky今日举行婚礼!电竞传奇步入新篇章
- 国风与电竞的奇妙邂逅 “电竞北京2024·国风电竞奇妙夜”引领文化新潮流
- 群星《辉煌滚石30男人篇》开盘母带[低速原抓WAV+CUE]
- 群星《藏迷情歌》紫银合金AQCD[低速原抓WAV+CUE]