#!/usr/bin/env python
#coding=utf-8 from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search class ES(object):
def __init__(self):
self.es = Elasticsearch(hosts="localhost:9200",timeout=60) def get_es_data(self, query = ""):
resp = self.es.search(index="test", body=query, scroll="1m",size=10000)
scroll_id = resp['_scroll_id']
resp_docs = resp["hits"]["hits"]
total = resp['hits']['total']
print total
count = len(resp_docs)
datas = resp_docs
while len(resp_docs) > 0:
scroll_id = resp['_scroll_id']
resp = self.es.scroll(scroll_id=scroll_id, scroll="1m")
resp_docs = resp["hits"]["hits"]
datas.extend(resp_docs)
count += len(resp_docs)
if count >= total:
break
return datas def get_ip_data(self, start_time, end_time, ip):
query = {"query":
{ "bool":{
"filter":{"range":{"timestamp":{"gte":start_time, "lt":end_time}}},
"must":{"match_phrase":{"src_ip": ip}}
}
}
}
data = self.get_es_data(query)
print len(data)
data = [d["_source"] for d in data]
print len(data)
print data[0:5]
return data def get_ips(self, start_time, end_time):
query = {
"query":{
"bool":{
"filter":{"range":{"timestamp":{"gte":start_time, "lt":end_time}}},
"must":{"exists":{"field":"src_ip"}}
}
}
}
data = self.get_es_data(query)
ips = [d["_source"]["src_ip"] for d in data]
print len(ips)
ips = list(set(ips))
print len(ips)
print ips
return ips if __name__ == "__main__":
es_obj = ES()
#es_obj.get_ips("2017-06-01T00:00:00", "2017-06-01T01:00:00")
es_obj.get_ip_data("2016-11-14T00:00:00", "2016-11-15T00:00:00","192.168.0.45")

最新文章

  1. shared_ptr
  2. Sublime Text 3 快捷键整理
  3. 51nod1006(lcs)
  4. 了解C++默认编写并调用哪些函数
  5. Stockbroker Grapevine(floyd)
  6. MYSQL主键自动增加的配置及auto_increment注意事项
  7. jgroups 常见概念
  8. 字符串聚合技术(String Aggregation Techniques)
  9. crm操作观点
  10. JS事件流理解
  11. Web in Linux小笔记001
  12. wireshark抓包图解 TCP三次握手/四次挥手详解[转]
  13. 如何提高windows的性能
  14. c语言中realloc()函数解析
  15. 图数据库项目DGraph的前世今生
  16. 好程序员web前端开发测验之css部分
  17. Luogu P2048 [NOI2010]超级钢琴
  18. python接口自动化测试二十二:文件下载
  19. ubuntu 14.04 忘记密码怎么办?
  20. [翻译] OrigamiEngine

热门文章

  1. pyglet----画一个矩形
  2. Meavn项目中log4j的使用
  3. Vagrant工具的安装
  4. curl模拟http发送get或post接口测试
  5. 解决logstash启动缓慢问题
  6. POJ - 1836 Alignment (动态规划)
  7. SSM-1第一章 认识SSM框架和Redis
  8. 前序遍历and中序遍历and后序遍历
  9. Flask最强攻略 - 跟DragonFire学Flask - 第七篇 Flask 中路由系统
  10. HashMap、ArrayMap、SparseArray分析比较