当前位置: 移动技术网 > IT编程>脚本编程>Python > python 实现提取某个索引中某个时间段的数据方法

python 实现提取某个索引中某个时间段的数据方法

2019年03月18日  | 移动技术网IT编程  | 我要评论

作文雨,青岛中能足球俱乐部,宝宝毛衣编织视频

如下所示:

from elasticsearch import elasticsearch
import datetime
import time
import dateutil.parser

class app(object):
 def __init__(self):
  pass

 def _es_conn(self):
  es = elasticsearch()
  return es

 def get_data(self, day,start,end):
  index_ = "gather-apk-20180330"
  query_dsl = {
   "size": 10000,
   "query": {
    "bool": {
     "must": [
      {"range": {
       "receivetime": {
        "gte": start.strftime('%y-%m-%d %h:%m:%s'),
        "lte": end.strftime('%y-%m-%d %h:%m:%s'),
        "format": "yyyy-mm-dd hh:mm:ss",
        "time_zone": "+08:00"
       }
      }},
      {
       "term": {
        "obd2_localnet_id": {
         "value": "101000"
        }
       }
      },
      {
       "term": {
        "obd2_substation_name": {
         "value": "石羊支局"
        }
       }
      }
     ]
    }
   },
   "_source": ["mac", "iptvaccount", "obd2_substation_name", "obd2_company_name", "obd2_grid_name",
      "receivetime","streambreak","kanum"]
  }
  rs = self._es_conn().search(
   index=index_,
   body=query_dsl
  )
  

if __name__ == '__main__':
 day = datetime.datetime.now()
 # the_day = day.strftime('%y%m%d')
 start = datetime.datetime.strptime('20180330 09:53:00','%y%m%d %h:%m:%s')
 end = datetime.datetime.strptime('20180330 15:44:00','%y%m%d %h:%m:%s')
 app = app()
 app.get_data(day,start,end)

以上这篇python 实现提取某个索引中某个时间段的数据方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网