es数据二次开发统计展示
案例1
在es查询中按照多列分组的时候 分组列的count值会越来越少 es默认隐藏了没有被分组匹配到的记录数 需要在查询的时候开启

2.开启显示没有被分组成功的记录
分组成功的记录加上分组missing的记录数就等于总的记录数 26932+2666=29598

3.当实际的总数和es分组统计的条数对不上的时候 需要考虑是不是分组列的值有可能被丢失了 这个时候可以开启显示丢失

4.查看es的原始日志内容确实有10001条记录不存在CHANNEL字段

实例统计
#!/usr/bin/env python
# -*- coding: utf-8 -*- from elasticsearch6 import Elasticsearch
import datetime
import time
import re es = Elasticsearch("http://10.000.142.88:9200") #每小时定时执行统计前一个小时的数据
def formartTime(startTime):
try:
startTime = datetime.datetime.strptime(startTime, '%Y-%m-%dT%H:%M:%S.%f')
except Exception as e:
startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M:%S')
startTime = startTime.strftime('%Y-%m-%d %H:%M:%S.%f')[:-13]
return startTime+":00:00" def strtime_to_datetime(timestr):
"""将字符串格式的时间 (含毫秒) 转为 datetime 格式
:param timestr: {str}'2016-02-25 20:21:04.242'
:return: {datetime}2016-02-25 20:21:04.242000
"""
local_datetime = datetime.datetime.strptime(timestr, "%Y-%m-%d %H:%M:%S.%f")
return local_datetime def datetime_to_timestamp(datetime_obj):
"""将本地(local) datetime 格式的时间 (含毫秒) 转为毫秒时间戳
:param datetime_obj: {datetime}2016-02-25 20:21:04.242000
:return: 13 位的毫秒时间戳 1456402864242
"""
local_timestamp = int(time.mktime(datetime_obj.timetuple()) * 1000.0 + datetime_obj.microsecond / 1000.0)
return local_timestamp def strtime_to_timestamp(local_timestr):
"""将本地时间 (字符串格式,含毫秒) 转为 13 位整数的毫秒时间戳
:param local_timestr: {str}'2016-02-25 20:21:04.242'
:return: 1456402864242
"""
local_datetime = strtime_to_datetime(local_timestr)
timestamp = datetime_to_timestamp(local_datetime)
return timestamp today=datetime.date.today()
tnow=datetime.datetime.now() startTime=(datetime.datetime.now()+datetime.timedelta(hours=-3)).replace(minute=0,second=0).strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
endTime=(datetime.datetime.now()+datetime.timedelta(hours=-3)).replace(minute=59,second=59).strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] stime=str(strtime_to_timestamp(startTime))[:-3]+""
etime=str(strtime_to_timestamp(endTime))[:-3]+"" def getindex():
if tnow.hour>2:
indexname=today.strftime("%Y-%m-%d")
else:
indexname=(tnow+datetime.timedelta(days=-1)).strftime("%Y-%m-%d")
return indexname indexname="sage-send-"+str(today)
findexname="as*"+getindex() body={"aggs":{"":{"terms":{"field":"APP_ID","size":5000,"order":{"_count":"desc"}},"aggs":{"":{"terms":{"field":"CHANNEL","size":5000,"order":{"_count":"desc"}},"aggs":{"":{"terms":{"field":"CHANNEL_ID","size":5000,"order":{"_count":"desc"}},"aggs":{"":{"terms":{"field":"SWJG_DM","size":5000,"order":{"_count":"desc"}},"aggs":{"":{"terms":{"field":"MESSAGE_TYPE","size":5000,"order":{"_count":"desc"}},"aggs":{"":{"date_histogram":{"field":"mydate","interval":"1h","time_zone":"Asia/Shanghai","min_doc_count":1}}}}}}}}}}}}},"size":0,"_source":{"excludes":[]},"stored_fields":["*"],"script_fields":{},"docvalue_fields":[{"field":"@timestamp","format":"date_time"},{"field":"mydate","format":"date_time"}],"query":{"bool":{"must":[{"match_phrase":{"metricsName":{"query":"消息发送量统计"}}},{"match_all":{}},{"range":{"mydate":{"gte":stime,"lte":etime,"format":"epoch_millis"}}}],"filter":[],"should":[],"must_not":[]}},"timeout":"30000ms"} if es.indices.exists(index=findexname):
res = es.search(body=body,index=findexname)
outlist=[]
dnow=datetime.datetime.now().strftime('%Y-%m-%d %H')+":00:00"
for i2 in res["aggregations"][""]["buckets"]:
for i3 in i2[""]["buckets"]:
for i4 in i3[""]["buckets"]:
for i5 in i4[""]["buckets"]:
for i6 in i5[""]["buckets"]:
for i7 in i6[""]["buckets"]:
timestr = i7["key_as_string"][:-6]
newtime = formartTime(timestr)
outlist.append({"appId":i2["key"],"count":i7["doc_count"],"channel":i3["key"],"channelId":i4["key"],"swjgDm":i5["key"],"messageType":i6["key"],"creatTime":newtime,"statisticalTime":dnow}) if es.indices.exists(index=indexname):
pass
else:
es.indices.create(index=indexname) for data in outlist:
res = es.index(index=indexname, doc_type="doc", body=data)
discover面板

如何查看指定索引名称的创建时间
1.命令行查询
curl -XGET http://192.168.80.10:9200/zhouls/_settings?pretty
{
"zhouls" : {
"settings" : {
"index" : {
"creation_date" : "1488203759467", //表示索引的创建时间
"uuid" : "Sppm-db_Qm-OHptOC7vznw",
"number_of_replicas" : "1",
"number_of_shards" : "5",
"version" : {
"created" : "2040399"
}
}
2.通过kibana查看索引的创建时间

es数据二次开发统计展示的更多相关文章
- 分享泛微公司OA系统用于二次开发的sql脚本
本单位用的oa系统就是泛微公司的oa协同办公平台,下面是我对他进行二次开发统计用到的写数据库脚本,只做开发参考使用,对于该系统的二次开发技术交流可以加我q:2050372586 [仪表盘]格式sql编 ...
- TFS二次开发系列:七、TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)
在TFS二次开发中,我们可能会根据某一些情况对各个项目的PBI.BUG等工作项进行统计.在本文中将大略讲解如果进行这些数据统计. 一:连接TFS服务器,并且得到之后需要使用到的类方法. /// < ...
- TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)
TFS二次开发的数据统计以PBI.Bug.Sprint等为例(一) 在TFS二次开发中,我们可能会根据某一些情况对各个项目的PBI.BUG等工作项进行统计.在本文中将大略讲解如果进行这些数据统计. 一 ...
- (5)微信二次开发 之 XML格式数据解析
1.首先理解一下html html的全名是:HyperText Transfer markup language 超级文本标记语言,html本质上是一门标记(符合)语言,在html里,这些标记是事先定 ...
- spss C# 二次开发 学习笔记(六)——Spss统计结果的输出
Spss的二次开发可以很简单,实例化一个对象,然后启用服务,接着提交命令,最后停止服务. 其中重点为提交命令,针对各种统计功能需求,以及被统计分析的数据内容等,命令的内容可以很复杂,但也可以简单的为一 ...
- PHP+Mysql+jQuery实现地图区域数据统计-展示数据
我们要在地图上有限的区块内展示更多的信息,更好的办法是通过地图交互来实现.本文将给大家讲解通过鼠标滑动到地图指定省份区域,在弹出的提示框中显示对应省份的数据信息.适用于数据统计和地图区块展示等场景. ...
- 数据层交换和高性能并发处理(开源ETL大数据治理工具--KETTLE使用及二次开发 )
ETL是什么?为什么要使用ETL?KETTLE是什么?为什么要学KETTLE? ETL是数据的抽取清洗转换加载的过程,是数据进入数据仓库进行大数据分析的载入过程,目前流行的数据进入仓库的 ...
- Qt+QGis二次开发:打开S-57格式(*.000)电子海图数据,并设置多边形要素的显示风格
不过多的废话了,直接上源码: addChartlayers()方法时“打开海图”按钮的triggered()信号所绑定的槽函数. //添加海图数据小按钮槽函数 void MainWindow::add ...
- [大数据可视化]-saiku的源码打包运行/二次开发构建
Saiku构建好之后,会将项目的各个模块达成jar包,整个项目也会打成war包 saiku目录结构: 我们选中saiku-server/target/ 下面的zip压缩包.这是个打包后的文件,进行 ...
随机推荐
- django -- ORM实现图书增删改查
表结构设计 上篇我们实现了出版社的增删改查,出版社数据表有两个字段id和name,那图书的表结构怎么设计呢?图书也要有一个主键id,还要有一个名称title,是哪个出版社的,要有个字段press和Pr ...
- [THUPC2019]过河卒二(组合数学,容斥原理)
以后都懒得写题目大意和数据范围了. hz学长的题其实也不那么毒瘤吗.比CDW的好多了 先考虑没有障碍怎么做. 首先发现,答案相当于一个左下角是 $(1,1)$,右上角是 $(n+1,m+1)$ 的棋盘 ...
- TensorFlow分布式训练MNIST分类器
http://c.biancheng.net/view/2004.html 本节以分布式方式训练完整的 MNIST 分类器. 该案例受到下面博客文章的启发:http://ischlag.github. ...
- MybatisPlus使用代码生成器遇到的小问题
MyBatisPlus 在3.0.3版本之前使用代码生成器因为存在默认依赖,所以不需要其他的依赖,项目中使用的是3.0.1的版本,所以不用添加其他依赖,添加之后反倒是会报错,实际上MP官网上已经说明了 ...
- 【BigData】Java基础_HashSet
HashSet简介 HashSet是一个集合数据类型,具有以下三个特性: (1)可以存储过个数据对象 (2)HashSet中的数据不能重复 (3)HashSet的数据存储是无序的 HashSet的几个 ...
- java web开发入门四(spring)基于intellig idea
spring 1.spring简介 Spring框架,可以解决对象创建以及对象之间依赖关系的一种框架. 且可以和其他框架一起使用:Spring与Struts, Spring与hibernate (起 ...
- Go:为何带来泛型
中文版 English version 介绍 [这是在Gophercon 2019上发表的演讲版本.视频链接可供使用.] 这篇文章是关于向Go添加泛型的意义,以及为什么我认为我们应该这样做.我还将介绍 ...
- 安装-consul服务发现集群
centos 7.4.x consul 1.2.2 list: 172.16.16.103 172.16.16.112 172.16.16.115 下载: #cd /usr/local/ #wget ...
- mysql创建存储过程动态SQL语句
DROP PROCEDURE IF EXISTS x.`wk`; DELIMITER $$ CREATE PROCEDURE `x`.`wk`() BEGIN ); ); SET t = CONCAT ...
- spark listener
最近在做一个需求,当spark程序在读数据或写数据时,将所读的条数或或所写的条数实时的展现出来,这里用到了SparkListener,sparklisten 可以获取spark 各个运行阶段的状态. ...