下载所需模块
python安装好的情况下,通过pip install elasticsearch进行es模块的安装
安装完成后通过pip list命中查询
python之elasticsearch查询

 

导入模块

1 from elasticsearch import  Elasticsearch
2 #用于将数据封装成dataframe格式
3 import pandas

 

连接es集群

1 # 以列表的形式存放各节点的IP地址
2 ip=["11.158.2.24","11.158.2.25","11.158.2.26"]
3 es=Elasticsearch(ip)
 
查询操作
#字段形式设置es查询body,根据相应的索引进行查询
b={ "query": {"match": {"email": "00011100001" }}}
data=es.search(index="xxx-2020-03-12",doc_type='angelLog',body=b)
#打印查询结果
data1=data['test001']['test001'][0]['_source']
print(data1)
 
python之elasticsearch查询

 

 

封装结果
#将查询报文封装成dataframe格式,可用于数据解析
df = pandas.DataFrame(data,index=[0])
print(type(df))
print(df)

 python之elasticsearch查询

 

 

 

相关文章:

  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2021-07-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2023-01-12
  • 2021-06-11
相关资源
相似解决方案