python连接elasticsearch获取数据
2017-02-10 17:05
453 查看
# -*- encoding: utf-8 -*- import sys import json from elasticsearch import Elasticsearch reload(sys) sys.setdefaultencoding("utf8") ###################################################### # 用于连接ES环境,查询检索小区信息,返回排名靠前10的小区信息。 # http_auth=('es_username', 'es_passwd') # es_search(city,name):es_search(深圳,登科花园) ###################################################### es = Elasticsearch( ['xxx.xxx.xxx.xxx'], http_auth=('elastic', 'passwd'), port=9200 ) def es_search(city, name): query_json = { "bool": { "must": { "term": { "city": city } }, "must_not":{ "term": { "base_inf.kind":'商铺' } }, "should": [ { "match": { "message": name } } ] } } source_arr = ["name", "Long_lat.lon", "Long_lat.lat", "detail_inf", "avg_price", "base_inf.kind", "base_inf.build_time"] res = es.search(index="st_soufang", body={"query": query_json, "_source": source_arr}) # 获取所有数据 # 获取第一条数据,得分最高。 top_10_recodes = res['hits']['hits'] # print json.dumps(top_10_recodes) return [top_10_recodes] # # for item in best_recode: # if item != '_source': # print item,best_recode[item] if __name__ == "__main__": # 测试单例 city = '深圳' name = '东方星大厦' es_search(city, name)
相关文章推荐
- Python Elasticsearch api,组合过滤器,term过滤器,正则查询 ,match查询,获取最近一小时的数据
- 树莓派3b连接GPS+BD模块并用python获取数据(USB版)
- Python连接impala并获取数据
- Python Elasticsearch api,组合过滤器,term过滤器,正则查询 ,match查询,获取最近一小时的数据
- 树莓派3b连接GPS+BD模块并用python获取数据(USB版)
- 树莓派3b连接GPS+BD模块并用python获取数据(串口版)
- Python连接JIRA获取送测项目数据
- Python 通过thrift接口连接Hbase读取存储数据
- 简单方法获取数据连接的字符串(UDL文件)
- 简单方法获取数据连接的字符串(UDL文件)
- python获取变量的数据类型
- ASP.NET连接数据库并获取数据
- Python实现获取当前公网ip并且自动断开宽带连接功能
- ASP.NET2.0里轻松获取数据库连接统计数据
- Python 获取豆瓣用户电影收藏数据
- python+fastcgi+flup获取请求的数据和环境变量
- Windows+Python2.7+MySQL5.5+MySQL-python-1.2.3配置数据连接失败
- 【python实战】获取双色球开奖数据之简易版
- 删除数据时,获取ID为空。注意检查请求时候的id能否获取到,或者是请求连接是否有误。
- 3个java类:连接数据库类,获取文件后缀类,从数据库中读入数据生成XML文件